Merge pull request 'add POPM on ID3 and RATING on Flac' (#14) from TheoD02/deemix-py-fork:feature/id3_popm into main

Reviewed-on: https://git.freezer.life/RemixDev/deemix-py/pulls/14
This commit is contained in:
RemixDev 2021-08-04 14:37:06 -04:00
commit 09f087484d
2 changed files with 13 additions and 1 deletions

View File

@ -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

View File

@ -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'):