From: Marcel van der Veldt Date: Thu, 20 Jun 2024 15:32:43 +0000 (+0200) Subject: Fix musicbrainz recording id tag in mp3 files X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=6896b20a95829ebe0374362409e45c9be9a984ea;p=music-assistant-server.git Fix musicbrainz recording id tag in mp3 files --- diff --git a/music_assistant/server/helpers/tags.py b/music_assistant/server/helpers/tags.py index 149e45a8..be8d66f4 100644 --- a/music_assistant/server/helpers/tags.py +++ b/music_assistant/server/helpers/tags.py @@ -11,6 +11,8 @@ from dataclasses import dataclass from json import JSONDecodeError from typing import TYPE_CHECKING, Any +import eyed3 + from music_assistant.common.helpers.util import try_parse_int from music_assistant.common.models.enums import AlbumType from music_assistant.common.models.errors import InvalidDataError @@ -219,8 +221,6 @@ class AudioTags: return tag if tag := self.tags.get("musicbrainzrecordingid"): return tag - if tag := self.tags.get("musicbrainzreleasetrackid"): - return tag return self.tags.get("musicbrainztrackid") @property @@ -430,6 +430,17 @@ async def parse_tags( tags.duration = int((file_size * 8) / tags.bit_rate) if not tags.duration and tags.raw.get("format", {}).get("duration"): tags.duration = float(tags.raw["format"]["duration"]) + + if file_path.endswith(".mp3") and "musicbrainzrecordingid" not in tags.tags: + # eyed3 is able to extract the musicbrainzrecordingid from the unique file id + # this is actually a bug in ffmpeg/ffprobe which does not expose this tag + # so we use this as alternative approach for mp3 files + audiofile = await asyncio.to_thread(eyed3.load, file_path) + for uf_id in audiofile.tag.unique_file_ids: + if uf_id.owner_id == b"http://musicbrainz.org" and uf_id.uniq_id: + tags.tags["musicbrainzrecordingid"] = uf_id.uniq_id.decode() + break + return tags except (KeyError, ValueError, JSONDecodeError, InvalidDataError) as err: msg = f"Unable to retrieve info for {file_path}: {err!s}" diff --git a/pyproject.toml b/pyproject.toml index 6beed63c..2bef6cb9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ server = [ "certifi==2024.6.2", "colorlog==6.8.2", "aiosqlite==0.20.0", + "eyeD3==0.9.7", "python-slugify==8.0.4", "mashumaro==3.13.1", "memory-tempfile==2.2.3", diff --git a/requirements_all.txt b/requirements_all.txt index eea9419a..f8987964 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -16,6 +16,7 @@ colorlog==6.8.2 cryptography==42.0.8 deezer-python-async==0.3.0 defusedxml==0.7.1 +eyeD3==0.9.7 faust-cchardet>=2.1.18 git+https://github.com/MarvinSchenkel/pytube.git hass-client==1.1.1