From 117a08ee4f47e4408c1a286c840b18e36e3ffbf2 Mon Sep 17 00:00:00 2001 From: "Xie, Tianshi" Date: Thu, 16 May 2024 16:18:38 -0400 Subject: [PATCH] add support to pulling explicit tag. fix tags on upc. isrc(mp4 not support, use WM tags), and composor missing(possible bug in mp4box, apple documents uses @wrt which belongs to writer in mp4box doc.) --- .gitignore | 2 ++ config.example.toml | 4 ++-- src/api.py | 2 +- src/metadata.py | 9 ++++++++- src/models/song_data.py | 1 + 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c8dc31a..80ff238 100644 --- a/.gitignore +++ b/.gitignore @@ -161,3 +161,5 @@ cython_debug/ #.idea/ config.toml +.python-version +.vscode/* diff --git a/config.example.toml b/config.example.toml index a16e963..d20b0e8 100644 --- a/config.example.toml +++ b/config.example.toml @@ -73,10 +73,10 @@ afterDownloaded = "" # title, artist, album, album_artist, composer, # genre, created, track, tracknum, disk, # record_company, upc, isrc, copyright, -# lyrics, cover +# lyrics, cover, ratings(rtng) embedMetadata = ["title", "artist", "album", "album_artist", "composer", "genre", "created", "track", "tracknum", "disk", "lyrics", "cover", "copyright", - "record_company", "upc", "isrc"] + "record_company", "upc", "isrc","rtng"] [mitm] # The host proxy server listens on diff --git a/src/api.py b/src/api.py index d146318..12bfdc7 100644 --- a/src/api.py +++ b/src/api.py @@ -159,7 +159,7 @@ async def get_cover(url: str, cover_format: str, cover_size: str): async def get_song_info(song_id: str, token: str, storefront: str, lang: str): async with request_lock: req = await client.get(f"https://amp-api.music.apple.com/v1/catalog/{storefront}/songs/{song_id}", - params={"extend": "extendedAssetUrls", "include": "albums", "l": lang}, + params={"extend": "extendedAssetUrls", "include": "albums,explicit", "l": lang}, headers={"Authorization": f"Bearer {token}", "User-Agent": user_agent_itunes, "Origin": "https://music.apple.com"}) song_data_obj = SongData.model_validate(req.json()) diff --git a/src/metadata.py b/src/metadata.py index 0f90b0a..16b3770 100644 --- a/src/metadata.py +++ b/src/metadata.py @@ -41,6 +41,12 @@ class SongMetadata(BaseModel): lrc = ttml_convent_to_lrc(value) tags.append(f"{key}={lrc}") continue + if key.lower() in ('upc', 'isrc'): + tags.append(f"WM/{key.lower()}={value}") + continue + if key == 'composer': + tags.append(f"writer={value}") + continue tags.append(f"{key}={value}") return ":".join(tags) @@ -55,7 +61,8 @@ class SongMetadata(BaseModel): copyright=song_data.relationships.albums.data[0].attributes.copyright, record_company=song_data.relationships.albums.data[0].attributes.recordLabel, upc=song_data.relationships.albums.data[0].attributes.upc, - isrc=song_data.attributes.isrc + isrc=song_data.attributes.isrc, + rtng=1 if song_data.attributes.contentRating and song_data.attributes.contentRating == 'explicit' else 0 ) def set_lyrics(self, lyrics: str): diff --git a/src/models/song_data.py b/src/models/song_data.py index 272b844..f56611c 100644 --- a/src/models/song_data.py +++ b/src/models/song_data.py @@ -58,6 +58,7 @@ class Attributes(BaseModel): previews: List[Preview] artistName: Optional[str] = None extendedAssetUrls: ExtendedAssetUrls + contentRating: Optional[str] = None class Artwork1(BaseModel):