From 02d6b6913347619d1b1236c80d1dd09521237f03 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 1 Oct 2023 00:54:41 +0200 Subject: [PATCH] Add support for opus format --- lb_content_resolver/database.py | 6 ++++-- lb_content_resolver/formats/ogg_opus.py | 27 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100755 lb_content_resolver/formats/ogg_opus.py diff --git a/lb_content_resolver/database.py b/lb_content_resolver/database.py index f97b0d5..d002c31 100755 --- a/lb_content_resolver/database.py +++ b/lb_content_resolver/database.py @@ -9,9 +9,9 @@ from lb_content_resolver.model.database import db, setup_db from lb_content_resolver.model.recording import Recording -from lb_content_resolver.formats import mp3, m4a, flac, ogg_vorbis, wma +from lb_content_resolver.formats import mp3, m4a, flac, ogg_opus, ogg_vorbis, wma -SUPPORTED_FORMATS = ["flac", "ogg", "mp3", "m4a", "wma"] +SUPPORTED_FORMATS = ["flac", "ogg", "opus", "mp3", "m4a", "wma"] class Database: @@ -169,6 +169,8 @@ def read_metadata_and_add(self, relative_path, format, mtime, update): mdata = flac.read(file_path) elif format == "ogg": mdata = ogg_vorbis.read(file_path) + elif format == "opus": + mdata = ogg_opus.read(file_path) elif format == "m4a": mdata = m4a.read(file_path) elif format == "wma": diff --git a/lb_content_resolver/formats/ogg_opus.py b/lb_content_resolver/formats/ogg_opus.py new file mode 100755 index 0000000..b28e08d --- /dev/null +++ b/lb_content_resolver/formats/ogg_opus.py @@ -0,0 +1,27 @@ +import mutagen +import mutagen.oggopus + +from lb_content_resolver.formats.tag_utils import get_tag_value, extract_track_number + + +def read(file): + + tags = None + try: + tags = mutagen.oggopus.OggOpus(file) + except mutagen.oggous.HeaderNotFoundError: + print("Cannot read metadata from file %s" % file) + return None + + mdata = {} + mdata["artist_name"] = get_tag_value(tags, "artist") + mdata["artist_sortname"] = get_tag_value(tags, "artistsort") + mdata["release_name"] = get_tag_value(tags, "album") + mdata["recording_name"] = get_tag_value(tags, "title") + mdata["track_num"] = extract_track_number(get_tag_value(tags, "tracknumber")) + mdata["artist_mbid"] = get_tag_value(tags, "musicbrainz_artistid", "") + mdata["recording_mbid"] = get_tag_value(tags, "musicbrainz_releasetrackid", "") + mdata["release_mbid"] = get_tag_value(tags, "musicbrainz_albumartistid", "") + mdata["duration"] = int(tags.info.length * 1000) + + return mdata