mirror of
https://github.com/glomatico/votify.git
synced 2026-09-23 09:32:16 +02:00
Include UPC in Spotify song metadata
This commit is contained in:
@@ -110,10 +110,11 @@ class SpotifySongInterface(SpotifyAudioInterface):
|
||||
) -> MediaTags:
|
||||
release_date = album_data["date"]
|
||||
|
||||
(composer, producer), (album_artist, artist, isrc, label) = (
|
||||
(composer, producer), (album_artist, artist, isrc, label), upc = (
|
||||
await asyncio.gather(
|
||||
self._get_composer_producer(track_data["uri"].split(":")[-1]),
|
||||
self._get_isrc_label(track_data["uri"].split(":")[-1]),
|
||||
self._get_upc(album_data["uri"].split(":")[-1]),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -145,6 +146,7 @@ class SpotifySongInterface(SpotifyAudioInterface):
|
||||
rating=rating,
|
||||
track=track_data["trackNumber"],
|
||||
track_total=track_total,
|
||||
upc=upc,
|
||||
url=f"https://open.spotify.com/track/{track_data['uri'].split(':')[-1]}",
|
||||
)
|
||||
|
||||
@@ -259,3 +261,20 @@ class SpotifySongInterface(SpotifyAudioInterface):
|
||||
synced="\n".join(synced_lines) if synced_lines else None,
|
||||
unsynced="\n".join(unsynced_lines) + "\n" if unsynced_lines else None,
|
||||
)
|
||||
|
||||
async def _get_upc(
|
||||
self,
|
||||
album_id: str,
|
||||
) -> str | None:
|
||||
album_gid = await self.api.get_gid_metadata(album_id, "album")
|
||||
|
||||
upc = next(
|
||||
(
|
||||
external_id["id"]
|
||||
for external_id in album_gid.get("external_id", [])
|
||||
if external_id["type"] == "upc"
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
return upc
|
||||
|
||||
@@ -67,6 +67,7 @@ class MediaTags:
|
||||
title: str = None
|
||||
track: int = None
|
||||
track_total: int = None
|
||||
upc: str = None
|
||||
url: str = None
|
||||
|
||||
def as_mp4_tags(self, date_format: str = None) -> dict[str, list[Any]]:
|
||||
@@ -126,6 +127,9 @@ class MediaTags:
|
||||
"\xa9nam": self.title,
|
||||
"trkn": track_mp4,
|
||||
"\xa9url": self.url,
|
||||
"----:com.apple.iTunes:UPC": (
|
||||
MP4FreeForm(self.upc.encode("utf-8")) if self.upc is not None else None
|
||||
),
|
||||
}
|
||||
return {
|
||||
k: ([v] if not isinstance(v, (list, bool)) else v)
|
||||
@@ -163,6 +167,7 @@ class MediaTags:
|
||||
"TRACKNUMBER": [str(self.track)],
|
||||
"TRACKTOTAL": [str(self.track_total)],
|
||||
"URL": [self.url],
|
||||
"UPC": [self.upc],
|
||||
}
|
||||
return {k: v for k, v in flac_tags.items() if v[0] is not None}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user