From ee267275d6faf4959172c63b6b59f90e9394f1be Mon Sep 17 00:00:00 2001 From: Phixxy Date: Wed, 4 Sep 2024 22:56:58 -0700 Subject: [PATCH] removed directory assumptions, trying to use chdir --- cogs/ytdl.py | 4 +++- data/ytdl/youtubedl.py | 14 ++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cogs/ytdl.py b/cogs/ytdl.py index 958a2b8..6894d1e 100644 --- a/cogs/ytdl.py +++ b/cogs/ytdl.py @@ -18,7 +18,9 @@ class YoutubeDL(BotBaseCog): url = ctx.message.content.split(" ")[1] url = '"' + url + '"' video_or_audio = ctx.message.content.split(" ")[2] - process = subprocess.Popen(["python3", "data/ytdl/youtubedl.py", url, video_or_audio]) + os.chdir("data/ytdl") + process = subprocess.Popen(["python3", "youtubedl.py", url, video_or_audio]) + os.chdir("../../") process.wait() self.logger.exception(process.stdout) self.logger.exception(process.stderr) diff --git a/data/ytdl/youtubedl.py b/data/ytdl/youtubedl.py index 131b57e..6caf167 100644 --- a/data/ytdl/youtubedl.py +++ b/data/ytdl/youtubedl.py @@ -6,7 +6,7 @@ import subprocess def download(url, video_or_audio): if video_or_audio == "video": - process = subprocess.Popen(["yt-dlp", "-o", "data/ytdl/%(playlist|)s/%(playlist_index)s - %(title)s.%(ext)s", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen(["yt-dlp", "--yes-playlist", f"{url}"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) process.wait() return True elif video_or_audio == "audio": @@ -21,19 +21,19 @@ def zip_all_files(): #zip all files current_epoch = time.time() output_file = f"{current_epoch}.zip" - os.system(f"zip -r data/ytdl/{output_file} data/ytdl/*") + os.system(f"zip -r {output_file} *") return output_file def upload_to_litterbox(input_file): ''' If you want to make curl requests to the API, here is an example. Allowed values for "time" are 1h, 12h, 24h, and 72h. curl -F "reqtype=fileupload" -F "time=1h" -F "fileToUpload=@cutie.png" https://litterbox.catbox.moe/resources/internals/api.php''' - command = f"curl -F 'reqtype=fileupload' -F 'time=1h' -F 'fileToUpload=@data/ytdl/{input_file}' https://litterbox.catbox.moe/resources/internals/api.php" + command = f"curl -F 'reqtype=fileupload' -F 'time=1h' -F 'fileToUpload=@{input_file}' https://litterbox.catbox.moe/resources/internals/api.php" output_url = os.popen(command).read() #delete all files in current directory except this script file_types = ["zip", "mp4", "mp3", "webm", "wav", "m4a", "flac", "ogg", "opus", "wma", "aac", "m4p", "m4b", "m4r", "m4v", "mp2", "mp3", "mp4", "mpa", "mpeg", "mpg", "mpv", "mxf", "ogg", "oga", "ogv", "ogx", "spx", "wav", "webm", "wma", "wv", "wvx", "weba", "webm", "webp", "wmv"] - for file in os.listdir("data/ytdl/"): + for file in os.listdir(): if file.split(".")[-1] in file_types: - #os.remove(f"data/ytdl/{file}") + #os.remove(f"{file}") pass return output_url @@ -45,10 +45,8 @@ def main(): #output_url = upload_to_litterbox(zip_file) output_url = "test_url" print(output_url) - with open(f"data/ytdl/{time.time()}.txt", "w") as output_file: + with open(f"{time.time()}.txt", "w") as output_file: output_file.write(output_url) - output_file.write("\n") - output_file.write(os.getcwd()) output_file.close() else: print("Invalid argument")