fixed encoding bug with mp3 files

This commit is contained in:
Lars Noack 2022-10-21 11:02:41 +02:00
parent c6d8c7e18e
commit fa7bfde4a1
3 changed files with 18 additions and 13 deletions

Binary file not shown.

View File

@ -129,7 +129,7 @@ class Download:
src = row['src']
if src == 'musify':
self.download_from_musify(row['path'], row['file'], row['url'])
musify.download(row)
elif src == 'youtube':
youtube_music.download(row)
self.write_metadata(row, row['file'])
@ -142,18 +142,6 @@ class Download:
os.makedirs(path, exist_ok=True)
return False
def download_from_musify(self, path, file, url):
logging.info(f"downloading: '{url}'")
r = self.session.get(url)
if r.status_code != 200:
if r.status_code == 404:
logging.warning(f"{url} was not found")
return -1
raise ConnectionError(f"\"{url}\" returned {r.status_code}: {r.text}")
with open(file, "wb") as mp3_file:
mp3_file.write(r.content)
logging.info("finished")
def write_metadata(self, row, filePath):
AudioSegment.from_file(filePath).export(filePath, format="mp3")

View File

@ -33,3 +33,20 @@ def get_download_link(default_url):
logging.info(f"https://musify.club/track/dl/{musify_id}/{musify_name}.mp3")
return f"https://musify.club/track/dl/{musify_id}/{musify_name}.mp3"
def download_from_musify(path, file, url):
logging.info(f"downloading: '{url}'")
r = session.get(url)
if r.status_code != 200:
if r.status_code == 404:
logging.warning(f"{url} was not found")
return -1
raise ConnectionError(f"\"{url}\" returned {r.status_code}: {r.text}")
with open(file, "wb") as mp3_file:
mp3_file.write(r.content)
logging.info("finished")
def download(row):
url = row['url']
file_ = row['file']
return download_from_musify(file_, url)