From 53a00570e7b71835b76d4c174b7829e464eb09ca Mon Sep 17 00:00:00 2001 From: DarkCat09 Date: Fri, 3 May 2024 18:38:11 +0400 Subject: [PATCH] Multiple artists support --- backend/id3pp.py | 8 +++++--- backend/test_pp.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/id3pp.py b/backend/id3pp.py index 960d90d..ae9f657 100644 --- a/backend/id3pp.py +++ b/backend/id3pp.py @@ -20,6 +20,8 @@ class InfoYouTubePP(PostProcessor): information['track'] = information['title'] if not 'artist' in information: information['artist'] = information['channel'].removesuffix(' - Topic') + if not 'artists' in information: + information['artists'] = [information['artist']] if not 'album' in information: try: @@ -47,10 +49,10 @@ class ID3TagsPP(PostProcessor): file = mp3.MP3(information['filepath']) title = information['track'] - artist = information['artist'] + artists: list[str] = information['artists'] file['TIT2'] = id3.TIT2(encoding=ENC_UTF8, text=title) - file['TPE1'] = id3.TPE1(encoding=ENC_UTF8, text=artist) + file['TPE1'] = id3.TPE1(encoding=ENC_UTF8, text=artists) # multiple values are null-separated if 'album' in information: file['TALB'] = id3.TALB(encoding=ENC_UTF8, text=information['album']) if 'release_year' in information: @@ -61,7 +63,7 @@ class ID3TagsPP(PostProcessor): file['TCON'] = id3.TCON(encoding=ENC_UTF8, text=information['genre']) try: - lyr_url = genius.search(title, artist) + lyr_url = genius.search(title, artists[0]) file['USLT'] = id3.USLT(encoding=ENC_UTF8, text=genius.parse(lyr_url)) except: pass diff --git a/backend/test_pp.py b/backend/test_pp.py index 0c95a13..6ad0205 100644 --- a/backend/test_pp.py +++ b/backend/test_pp.py @@ -25,6 +25,7 @@ INFO_AFTER = { **INFO_BEFORE, "track": "A Line in the Sand", "artist": "Linkin Park", + "artists": ["Linkin Park"], "album": "The Hunting Party", "track_number": 12, } @@ -39,7 +40,7 @@ class TestPostProcessorsOnFakeData(TestCase): def test_infoytpp(self) -> None: _, info = id3pp.InfoYouTubePP().run(INFO_BEFORE) - self.assertEqual(info, INFO_AFTER) + self.assertDictEqual(info, INFO_AFTER) def test_id3(self) -> None: