added youtube as music src

This commit is contained in:
Lars Noack 2022-10-20 16:20:48 +02:00
parent 609041c50f
commit 116f7cf414
3 changed files with 17 additions and 3 deletions

View File

@ -1,7 +1,9 @@
import requests import requests
import os.path import os.path
import pandas as pd import pandas as pd
import mutagen
from mutagen.easyid3 import EasyID3 from mutagen.easyid3 import EasyID3
import mutagen.mp3
import json import json
import logging import logging
@ -90,6 +92,7 @@ class Download:
for idx, row in self.dataframe.iterrows(): for idx, row in self.dataframe.iterrows():
row['artist'] = json.loads(row['artist'].replace("'", '"')) row['artist'] = json.loads(row['artist'].replace("'", '"'))
if self.path_stuff(row['path'], row['file']): if self.path_stuff(row['path'], row['file']):
self.write_metadata(row, row['file'])
continue continue
src = row['src'] src = row['src']
@ -119,18 +122,24 @@ class Download:
mp3_file.write(r.content) mp3_file.write(r.content)
logging.info("finished") logging.info("finished")
def write_metadata(self, row, file): def write_metadata(self, row, filePath):
audiofile = EasyID3(file) try:
audiofile = EasyID3(filePath)
except mutagen.id3.ID3NoHeaderError:
audiofile = mutagen.mp3.EasyMP3(filePath)
audiofile.add_tags()
valid_keys = list(EasyID3.valid_keys.keys()) valid_keys = list(EasyID3.valid_keys.keys())
for key in list(row.keys()): for key in list(row.keys()):
if key in valid_keys and row[key] is not None and not pd.isna(row[key]): 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: if type(row[key]) == int or type(row[key]) == float:
row[key] = str(row[key]) row[key] = str(row[key])
audiofile[key] = row[key] audiofile[key] = row[key]
audiofile.save() print("saving")
audiofile.save(filePath, v1=2)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -40,6 +40,11 @@ def download(row):
file_ = row['file'] file_ = row['file']
options = { options = {
'format': 'bestaudio/best', 'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
'keepvideo': False, 'keepvideo': False,
'outtmpl': file_ 'outtmpl': file_
} }