diff --git a/src/mpd_now_playable/cocoa/persistent_id.py b/src/mpd_now_playable/cocoa/persistent_id.py index be88dc8..7f63ae9 100644 --- a/src/mpd_now_playable/cocoa/persistent_id.py +++ b/src/mpd_now_playable/cocoa/persistent_id.py @@ -8,6 +8,7 @@ from ..song import Song # The maximum size for a BLAKE2b "person" value is sixteen bytes, so we need to be concise. HASH_PERSON_PREFIX: Final = b"mnp.mac." TRACKID_HASH_PERSON: Final = HASH_PERSON_PREFIX + b"mb_tid" +RELEASETRACKID_HASH_PERSON: Final = HASH_PERSON_PREFIX + b"mb_rtid" FILE_HASH_PERSON: Final = HASH_PERSON_PREFIX + b"f" PERSISTENT_ID_BITS: Final = 64 @@ -20,6 +21,14 @@ def digest_trackid(trackid: UUID) -> bytes: ).digest() +def digest_releasetrackid(trackid: UUID) -> bytes: + return blake2b( + trackid.bytes, + digest_size=PERSISTENT_ID_BYTES, + person=RELEASETRACKID_HASH_PERSON, + ).digest() + + def digest_file_uri(file: Path) -> bytes: return blake2b( bytes(file), digest_size=PERSISTENT_ID_BYTES, person=FILE_HASH_PERSON @@ -34,6 +43,8 @@ def digest_file_uri(file: Path) -> bytes: def song_to_persistent_id(song: Song) -> int: if song.musicbrainz_trackid: hashed_id = digest_trackid(song.musicbrainz_trackid) + elif song.musicbrainz_releasetrackid: + hashed_id = digest_releasetrackid(song.musicbrainz_releasetrackid) else: hashed_id = digest_file_uri(song.file) return int.from_bytes(hashed_id) diff --git a/src/mpd_now_playable/mpd/listener.py b/src/mpd_now_playable/mpd/listener.py index b044139..81d2174 100644 --- a/src/mpd_now_playable/mpd/listener.py +++ b/src/mpd_now_playable/mpd/listener.py @@ -21,6 +21,9 @@ def mpd_current_to_song( queue_length=int(status["playlistlength"]), file=Path(current["file"]), musicbrainz_trackid=convert_if_exists(current.get("musicbrainz_trackid"), UUID), + musicbrainz_releasetrackid=convert_if_exists( + current.get("musicbrainz_releasetrackid"), UUID + ), title=current.get("title"), artist=current.get("artist"), album=current.get("album"), diff --git a/src/mpd_now_playable/song.py b/src/mpd_now_playable/song.py index fa904f6..cf72cfa 100644 --- a/src/mpd_now_playable/song.py +++ b/src/mpd_now_playable/song.py @@ -19,6 +19,7 @@ class Song: queue_length: int file: Path musicbrainz_trackid: UUID | None + musicbrainz_releasetrackid: UUID | None title: str | None artist: str | None composer: str | None