Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from sbruder/opus
Browse files Browse the repository at this point in the history
Add support for opus format
  • Loading branch information
mayhem authored Oct 3, 2023
2 parents 50d5548 + 02d6b69 commit 6caa43d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lb_content_resolver/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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":
Expand Down
27 changes: 27 additions & 0 deletions lb_content_resolver/formats/ogg_opus.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6caa43d

Please sign in to comment.