Unify ID3 post-processor, move add_tags() code into run()

This commit is contained in:
DarkCat09 2024-04-28 13:30:21 +04:00
parent 0f9798efbf
commit 4d83b238e4
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3

View file

@ -5,18 +5,6 @@ from yt_dlp.postprocessor import PostProcessor
ENC_UTF8 = 3
def add_tags(file: mp3.MP3, info: dict[str, str | int]) -> None:
file['TIT2'] = id3.TIT2(encoding=ENC_UTF8, text=info['track'])
file['TPE1'] = id3.TPE1(encoding=ENC_UTF8, text=info['artist'])
if 'album' in info:
file['TALB'] = id3.TALB(encoding=ENC_UTF8, text=info['album'])
if 'release_year' in info:
file['TDRC'] = id3.TDRC(encoding=ENC_UTF8, text=str(info['release_year']))
if 'track_number' in info:
file['TRCK'] = id3.TRCK(encoding=ENC_UTF8, text=str(info['track_number']))
class InfoYouTubePP(PostProcessor):
'''Generates YT Music fields in info if necessary.
Must be run before downloading and post-processing with
@ -48,15 +36,23 @@ class InfoYouTubePP(PostProcessor):
return [], information
class ID3YouTubePP(PostProcessor):
'''Inserts ID3 tags after InfoYouTubePP and FFmpegExtractAudioPP,
class ID3TagsPP(PostProcessor):
'''Inserts ID3 tags after all PPs (for YT: InfoYouTubePP and FFmpegExtractAudioPP),
triggers searching and parsing lyrics from Genius'''
def run(self, information):
add_tags(
mp3.MP3(information['filepath']),
information,
)
file = mp3.MP3(information['filepath'])
file['TIT2'] = id3.TIT2(encoding=ENC_UTF8, text=information['track'])
file['TPE1'] = id3.TPE1(encoding=ENC_UTF8, text=information['artist'])
if 'album' in information:
file['TALB'] = id3.TALB(encoding=ENC_UTF8, text=information['album'])
if 'release_year' in information:
file['TDRC'] = id3.TDRC(encoding=ENC_UTF8, text=str(information['release_year']))
if 'track_number' in information:
file['TRCK'] = id3.TRCK(encoding=ENC_UTF8, text=str(information['track_number']))
# TODO: lyrics file["USLT"]
return [], information