From c6257a3f0dc6f0e2877832914e74275bc8e189df Mon Sep 17 00:00:00 2001 From: oskvr37 Date: Fri, 26 Jul 2024 23:33:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20directory=20creation=20on=20d?= =?UTF-8?q?ownload?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tiddl/download.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tiddl/download.py b/tiddl/download.py index 8792ef4..6ce0ebb 100644 --- a/tiddl/download.py +++ b/tiddl/download.py @@ -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)