Support opus audio format

main
Bob Mottram 2022-04-18 14:21:45 +01:00
parent b494eb06b4
commit 8094ca0849
8 changed files with 14 additions and 3 deletions

View File

@ -1105,6 +1105,7 @@ def save_media_in_form_post(media_bytes, debug: bool,
'ogv': 'video/ogv', 'ogv': 'video/ogv',
'mp3': 'audio/mpeg', 'mp3': 'audio/mpeg',
'ogg': 'audio/ogg', 'ogg': 'audio/ogg',
'opus': 'audio/opus',
'flac': 'audio/flac', 'flac': 'audio/flac',
'zip': 'application/zip' 'zip': 'application/zip'
} }

View File

@ -415,6 +415,7 @@ def path_is_audio(path: str) -> bool:
"""Is the given path an audio file? """Is the given path an audio file?
""" """
if path.endswith('.ogg') or \ if path.endswith('.ogg') or \
path.endswith('.opus') or \
path.endswith('.mp3'): path.endswith('.mp3'):
return True return True
return False return False

View File

@ -193,6 +193,7 @@ def meta_data_instance(showAccounts: bool,
'video/mp4', 'video/mp4',
'video/ogv', 'video/ogv',
'audio/ogg', 'audio/ogg',
'audio/opus',
'audio/flac', 'audio/flac',
'audio/mpeg' 'audio/mpeg'
], ],

View File

@ -313,6 +313,7 @@ def post_message_to_outbox(session, translate: {},
"avif": "avif", "avif": "avif",
"audio/mpeg": "mp3", "audio/mpeg": "mp3",
"ogg": "ogg", "ogg": "ogg",
"opus": "opus",
"mp4": "mp4", "mp4": "mp4",
"webm": "webm", "webm": "webm",
"ogv": "ogv" "ogv": "ogv"

View File

@ -372,7 +372,7 @@ def get_video_extensions() -> []:
def get_audio_extensions() -> []: def get_audio_extensions() -> []:
"""Returns a list of the possible audio file extensions """Returns a list of the possible audio file extensions
""" """
return ('mp3', 'ogg', 'flac') return ('mp3', 'ogg', 'flac', 'opus')
def get_image_extensions() -> []: def get_image_extensions() -> []:
@ -2646,6 +2646,7 @@ def media_file_mime_type(filename: str) -> str:
'ico': 'image/x-icon', 'ico': 'image/x-icon',
'mp3': 'audio/mpeg', 'mp3': 'audio/mpeg',
'ogg': 'audio/ogg', 'ogg': 'audio/ogg',
'opus': 'audio/opus',
'flac': 'audio/flac', 'flac': 'audio/flac',
'mp4': 'video/mp4', 'mp4': 'video/mp4',
'ogv': 'video/ogv' 'ogv': 'video/ogv'

View File

@ -225,9 +225,9 @@ def _add_embedded_video_from_sites(translate: {}, content: str,
def _add_embedded_audio(translate: {}, content: str) -> str: def _add_embedded_audio(translate: {}, content: str) -> str:
"""Adds embedded audio for mp3/ogg """Adds embedded audio for mp3/ogg/opus
""" """
if not ('.mp3' in content or '.ogg' in content): if not ('.mp3' in content or '.ogg' in content or '.opus' in content):
return content return content
if '<audio ' in content: if '<audio ' in content:
@ -236,6 +236,8 @@ def _add_embedded_audio(translate: {}, content: str) -> str:
extension = '.mp3' extension = '.mp3'
if '.ogg' in content: if '.ogg' in content:
extension = '.ogg' extension = '.ogg'
elif '.opus' in content:
extension = '.opus'
words = content.strip('\n').split(' ') words = content.strip('\n').split(' ')
for wrd in words: for wrd in words:

View File

@ -209,6 +209,8 @@ def html_podcast_episode(css_cache: {}, translate: {},
if path_is_audio(link_url): if path_is_audio(link_url):
if '.mp3' in link_url: if '.mp3' in link_url:
audio_extension = 'mpeg' audio_extension = 'mpeg'
elif '.opus' in link_url:
audio_extension = 'opus'
else: else:
audio_extension = 'ogg' audio_extension = 'ogg'
else: else:

View File

@ -1217,6 +1217,8 @@ def get_post_attachments_as_html(post_json_object: {}, box_name: str,
extension = '.mp3' extension = '.mp3'
if attach['url'].endswith('.ogg'): if attach['url'].endswith('.ogg'):
extension = '.ogg' extension = '.ogg'
elif attach['url'].endswith('.opus'):
extension = '.opus'
if attach['url'].endswith(extension): if attach['url'].endswith(extension):
if attachment_ctr > 0: if attachment_ctr > 0:
attachment_str += '<br>' attachment_str += '<br>'