diff --git a/src/__pycache__/youtube_music.cpython-310.pyc b/src/__pycache__/youtube_music.cpython-310.pyc index a884025..b706e4e 100644 Binary files a/src/__pycache__/youtube_music.cpython-310.pyc and b/src/__pycache__/youtube_music.cpython-310.pyc differ diff --git a/src/download.py b/src/download.py index 89986be..f7af8df 100644 --- a/src/download.py +++ b/src/download.py @@ -1,7 +1,9 @@ import requests import os.path import pandas as pd +import mutagen from mutagen.easyid3 import EasyID3 +import mutagen.mp3 import json import logging @@ -90,6 +92,7 @@ class Download: for idx, row in self.dataframe.iterrows(): row['artist'] = json.loads(row['artist'].replace("'", '"')) if self.path_stuff(row['path'], row['file']): + self.write_metadata(row, row['file']) continue src = row['src'] @@ -119,18 +122,24 @@ class Download: mp3_file.write(r.content) logging.info("finished") - def write_metadata(self, row, file): - audiofile = EasyID3(file) + def write_metadata(self, row, filePath): + try: + audiofile = EasyID3(filePath) + except mutagen.id3.ID3NoHeaderError: + audiofile = mutagen.mp3.EasyMP3(filePath) + audiofile.add_tags() valid_keys = list(EasyID3.valid_keys.keys()) for key in list(row.keys()): if key in valid_keys and row[key] is not None and not pd.isna(row[key]): + # print(key) if type(row[key]) == int or type(row[key]) == float: row[key] = str(row[key]) audiofile[key] = row[key] - audiofile.save() + print("saving") + audiofile.save(filePath, v1=2) if __name__ == "__main__": diff --git a/src/youtube_music.py b/src/youtube_music.py index 78d2c41..6f8eaf7 100644 --- a/src/youtube_music.py +++ b/src/youtube_music.py @@ -40,6 +40,11 @@ def download(row): file_ = row['file'] options = { 'format': 'bestaudio/best', + 'postprocessors': [{ + 'key': 'FFmpegExtractAudio', + 'preferredcodec': 'mp3', + 'preferredquality': '192', + }], 'keepvideo': False, 'outtmpl': file_ }