From 4c119447f5c1dc6b1d7f0ddd2b5a6d3f62aef651 Mon Sep 17 00:00:00 2001 From: TheoD02 Date: Tue, 3 Aug 2021 23:08:06 +0200 Subject: [PATCH] add POPM on ID3 and RATING on Flac --- deemix/tagger.py | 13 ++++++++++++- deemix/types/Track.py | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/deemix/tagger.py b/deemix/tagger.py index e3cdbf6..205e28a 100644 --- a/deemix/tagger.py +++ b/deemix/tagger.py @@ -1,7 +1,7 @@ from mutagen.flac import FLAC, Picture from mutagen.id3 import ID3, ID3NoHeaderError, \ TXXX, TIT2, TPE1, TALB, TPE2, TRCK, TPOS, TCON, TYER, TDAT, TLEN, TBPM, \ - TPUB, TSRC, USLT, SYLT, APIC, IPLS, TCOM, TCOP, TCMP, Encoding, PictureType + TPUB, TSRC, USLT, SYLT, APIC, IPLS, TCOM, TCOP, TCMP, Encoding, PictureType, POPM # Adds tags to a MP3 file def tagID3(path, track, save): @@ -12,6 +12,14 @@ def tagID3(path, track, save): except ID3NoHeaderError: tag = ID3() + rank = round((int(track.rank) / 10000) * 2.55) + if rank > 255 : + rank = 255 + else: + rank = round(rank, 0) + + tag.add(POPM(rating=rank)) + if save['title']: tag.add(TIT2(text=track.title)) @@ -123,6 +131,9 @@ def tagFLAC(path, track, save): tag.delete() tag.clear_pictures() + rank = round((int(track.rank) / 10000)) + tag['RATING'] = str(rank) + if save['title']: tag["TITLE"] = track.title diff --git a/deemix/types/Track.py b/deemix/types/Track.py index 9f86b42..a034ad8 100644 --- a/deemix/types/Track.py +++ b/deemix/types/Track.py @@ -57,6 +57,7 @@ class Track: self.id = str(trackAPI_gw['SNG_ID']) self.duration = trackAPI_gw['DURATION'] self.trackToken = trackAPI_gw['TRACK_TOKEN'] + self.rank = trackAPI_gw['RANK_SNG'] self.MD5 = trackAPI_gw.get('MD5_ORIGIN') if not self.MD5: if trackAPI and trackAPI.get('md5_origin'):