Skip to content

Commit

Permalink
feat(Track): update get_metadata to provide mediafile compatible dict
Browse files Browse the repository at this point in the history
also updates gen_title and gen_artists to better format

depends on beetbox/mediafile#42
  • Loading branch information
JuniorJPDJ committed May 15, 2021
1 parent 3fc9e10 commit 0193798
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
25 changes: 15 additions & 10 deletions tidal_async/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,31 @@ async def get_metadata(self):
# - [ ] lyrics
# - [x] rewrite title parsing
# - [x] replayGain
# - [ ] multiple artists
# - [ ] Picard like artist and view artist separation
# - [x] multiple artists
# - [x] Tidal track URL
album = self.album
await album.reload_info()

tags = {
# general metatags
"artist": await gen_artist(self),
"title": await gen_title(self),
"artists": [a[0].name async for a in self.artists()],
"title": gen_title(self),
# album related metatags
"albumartist": await gen_artist(album),
"album": await gen_title(album),
"albumartists": [a[0].name async for a in album.artists()],
"album": gen_title(album),
"date": album.release_date,
# track/disc position metatags
"discnumber": self.volume_number,
"disc": self.volume_number,
"disctotal": album.number_of_volumes,
"tracknumber": self.track_number,
"track": self.track_number,
"tracktotal": album.number_of_tracks,
"replaygain_track_gain": self.replay_gain,
"replaygain_track_peak": self.peak,
# replaygain
"rg_track_gain": self.replay_gain,
"rg_track_peak": self.peak,
# track url
"url": await self.get_url(),
}

# Tidal sometimes returns null for track copyright
Expand All @@ -217,11 +222,11 @@ async def get_metadata(self):
elif "copyright" in album and album.copyright:
tags["copyright"] = album.copyright

# identifiers for later use in own music libraries
# identifiers for later use in music libraries
if "isrc" in self and self.isrc:
tags["isrc"] = self.isrc
if "upc" in album and album.upc:
tags["upc"] = album.upc
tags["barcode"] = album.upc

return tags

Expand Down
16 changes: 6 additions & 10 deletions tidal_async/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,19 @@ def wrapped(*args, **kwargs):
return wrapped


async def gen_title(obj):
"""Generates full title from track/album version and artist list"""
artists = [a async for a in obj.artists() if a[1] != "MAIN"]
def gen_title(obj):
"""Generates full title from track/album version"""
title = obj.title.strip()
version = obj.version.strip() if "version" in obj and obj.version else ""

if not artists:
return f"{title} ({version})" if version and version not in title else title

if "feat" not in title:
title += f' (feat. {", ".join([a[0].name for a in artists])})'

return f"{title} ({version})" if version and version not in title else title


async def gen_artist(obj):
return ", ".join([a[0].name async for a in obj.artists() if a[1] == "MAIN"])
artists = [a async for a in obj.artists()]
main = ", ".join(a[0].name for a in artists if a[1].value == "MAIN")
feat = ", ".join(a[0].name for a in artists if a[1].value == "FEATURED")
return main if not feat else f"{main} feat. {feat}"


try:
Expand Down

0 comments on commit 0193798

Please sign in to comment.