add directory creation on download

This commit is contained in:
oskvr37
2024-07-26 23:33:12 +02:00
parent a6156bf06e
commit c6257a3f0d
+5 -2
View File
@@ -1,4 +1,5 @@
import requests
from os import makedirs
from xml.etree.ElementTree import fromstring
from base64 import b64decode
@@ -60,13 +61,15 @@ def threadDownload(urls: list[str]) -> bytes:
return data
def downloadTrack(track_id: int, manifest: str, path: str):
def downloadTrack(file_name: int, manifest: str, path: str):
decoded_manifest = decodeManifest(manifest)
track_urls, codecs = parseTrackManifest(decoded_manifest)
track_data = threadDownload(track_urls)
makedirs(path, exist_ok=True)
# TODO: use proper file extension ✨
file_path = f"{path}/{track_id}.flac"
file_path = f"{path}/{file_name}.flac"
with open(file_path, "wb+") as f:
f.write(track_data)