Multiple artists support

This commit is contained in:
DarkCat09 2024-05-03 18:38:11 +04:00
parent 77127d3476
commit 53a00570e7
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3
2 changed files with 7 additions and 4 deletions

View file

@ -20,6 +20,8 @@ class InfoYouTubePP(PostProcessor):
information['track'] = information['title'] information['track'] = information['title']
if not 'artist' in information: if not 'artist' in information:
information['artist'] = information['channel'].removesuffix(' - Topic') information['artist'] = information['channel'].removesuffix(' - Topic')
if not 'artists' in information:
information['artists'] = [information['artist']]
if not 'album' in information: if not 'album' in information:
try: try:
@ -47,10 +49,10 @@ class ID3TagsPP(PostProcessor):
file = mp3.MP3(information['filepath']) file = mp3.MP3(information['filepath'])
title = information['track'] title = information['track']
artist = information['artist'] artists: list[str] = information['artists']
file['TIT2'] = id3.TIT2(encoding=ENC_UTF8, text=title) 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: if 'album' in information:
file['TALB'] = id3.TALB(encoding=ENC_UTF8, text=information['album']) file['TALB'] = id3.TALB(encoding=ENC_UTF8, text=information['album'])
if 'release_year' in information: if 'release_year' in information:
@ -61,7 +63,7 @@ class ID3TagsPP(PostProcessor):
file['TCON'] = id3.TCON(encoding=ENC_UTF8, text=information['genre']) file['TCON'] = id3.TCON(encoding=ENC_UTF8, text=information['genre'])
try: 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)) file['USLT'] = id3.USLT(encoding=ENC_UTF8, text=genius.parse(lyr_url))
except: except:
pass pass

View file

@ -25,6 +25,7 @@ INFO_AFTER = {
**INFO_BEFORE, **INFO_BEFORE,
"track": "A Line in the Sand", "track": "A Line in the Sand",
"artist": "Linkin Park", "artist": "Linkin Park",
"artists": ["Linkin Park"],
"album": "The Hunting Party", "album": "The Hunting Party",
"track_number": 12, "track_number": 12,
} }
@ -39,7 +40,7 @@ class TestPostProcessorsOnFakeData(TestCase):
def test_infoytpp(self) -> None: def test_infoytpp(self) -> None:
_, info = id3pp.InfoYouTubePP().run(INFO_BEFORE) _, info = id3pp.InfoYouTubePP().run(INFO_BEFORE)
self.assertEqual(info, INFO_AFTER) self.assertDictEqual(info, INFO_AFTER)
def test_id3(self) -> None: def test_id3(self) -> None: