From e81adde17d08d916ef8c5f98acb543a9ff626888 Mon Sep 17 00:00:00 2001 From: RemixDev Date: Thu, 10 Sep 2020 13:44:38 +0200 Subject: [PATCH] Added support for embedded sync lyrics on MP3 with the SYLT tag --- deemix/__init__.py | 2 +- deemix/app/settings.py | 1 + deemix/app/track.py | 8 +++++++- deemix/utils/taggers.py | 4 +++- setup.py | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/deemix/__init__.py b/deemix/__init__.py index 669fd79..4a87828 100644 --- a/deemix/__init__.py +++ b/deemix/__init__.py @@ -1,3 +1,3 @@ #!/usr/bin/env python3 -__version__ = "1.2.21" +__version__ = "1.2.22" diff --git a/deemix/app/settings.py b/deemix/app/settings.py index 0bfa148..37b7cb2 100644 --- a/deemix/app/settings.py +++ b/deemix/app/settings.py @@ -84,6 +84,7 @@ class Settings: "replayGain": False, "label": True, "lyrics": False, + "syncedLyrics": False, "copyright": False, "composer": False, "involvedPeople": False, diff --git a/deemix/app/track.py b/deemix/app/track.py index dff9929..42de325 100644 --- a/deemix/app/track.py +++ b/deemix/app/track.py @@ -154,7 +154,8 @@ class Track: self.lyrics = { 'id': trackAPI_gw.get('LYRICS_ID'), 'unsync': None, - 'sync': None + 'sync': None, + 'syncID3': None } if not "LYRICS" in trackAPI_gw and int(self.lyrics['id']) != 0: logger.info(f"[{trackAPI_gw['ART_NAME']} - {self.title}] Getting lyrics") @@ -163,14 +164,19 @@ class Track: self.lyrics['unsync'] = trackAPI_gw["LYRICS"].get("LYRICS_TEXT") if "LYRICS_SYNC_JSON" in trackAPI_gw["LYRICS"]: self.lyrics['sync'] = "" + self.lyrics['syncID3'] = [] lastTimestamp = "" + lastMilliseconds = 0 for i in range(len(trackAPI_gw["LYRICS"]["LYRICS_SYNC_JSON"])): if "lrc_timestamp" in trackAPI_gw["LYRICS"]["LYRICS_SYNC_JSON"][i]: self.lyrics['sync'] += trackAPI_gw["LYRICS"]["LYRICS_SYNC_JSON"][i]["lrc_timestamp"] lastTimestamp = trackAPI_gw["LYRICS"]["LYRICS_SYNC_JSON"][i]["lrc_timestamp"] else: self.lyrics['sync'] += lastTimestamp + if "milliseconds" in trackAPI_gw["LYRICS"]["LYRICS_SYNC_JSON"][i]: + lastMilliseconds = int(trackAPI_gw["LYRICS"]["LYRICS_SYNC_JSON"][i]["milliseconds"]) self.lyrics['sync'] += trackAPI_gw["LYRICS"]["LYRICS_SYNC_JSON"][i]["line"] + "\r\n" + self.lyrics['syncID3'].append((trackAPI_gw["LYRICS"]["LYRICS_SYNC_JSON"][i]["line"], lastMilliseconds)) self.mainArtist = { 'id': trackAPI_gw['ART_ID'], diff --git a/deemix/utils/taggers.py b/deemix/utils/taggers.py index 620c6a1..649b030 100644 --- a/deemix/utils/taggers.py +++ b/deemix/utils/taggers.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 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, APIC, IPLS, TCOM, TCOP, TCMP + TPUB, TSRC, USLT, SYLT, APIC, IPLS, TCOM, TCOP, TCMP # Adds tags to a MP3 file def tagID3(stream, track, save): @@ -62,6 +62,8 @@ def tagID3(stream, track, save): tag.add(TXXX(desc="REPLAYGAIN_TRACK_GAIN", text=track.replayGain)) if track.lyrics['unsync'] and save['lyrics']: tag.add(USLT(text=track.lyrics['unsync'])) + if track.lyrics['syncID3'] and save['syncedLyrics']: + tag.add(SYLT(3, format=2, type=1, text=track.lyrics['syncID3'])) involved_people = [] for role in track.contributors: diff --git a/setup.py b/setup.py index 6250585..02112e7 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ README = (HERE / "README.md").read_text() setup( name="deemix", - version="1.2.21", + version="1.2.22", description="A barebone deezer downloader library", long_description=README, long_description_content_type="text/markdown",