removed directory assumptions, trying to use chdir

This commit is contained in:
Phixxy 2024-09-04 22:56:58 -07:00
parent 2141abae5e
commit ee267275d6
2 changed files with 9 additions and 9 deletions

View file

@ -18,7 +18,9 @@ class YoutubeDL(BotBaseCog):
url = ctx.message.content.split(" ")[1] url = ctx.message.content.split(" ")[1]
url = '"' + url + '"' url = '"' + url + '"'
video_or_audio = ctx.message.content.split(" ")[2] 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() process.wait()
self.logger.exception(process.stdout) self.logger.exception(process.stdout)
self.logger.exception(process.stderr) self.logger.exception(process.stderr)

View file

@ -6,7 +6,7 @@ import subprocess
def download(url, video_or_audio): def download(url, video_or_audio):
if video_or_audio == "video": 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() process.wait()
return True return True
elif video_or_audio == "audio": elif video_or_audio == "audio":
@ -21,19 +21,19 @@ def zip_all_files():
#zip all files #zip all files
current_epoch = time.time() current_epoch = time.time()
output_file = f"{current_epoch}.zip" 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 return output_file
def upload_to_litterbox(input_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. ''' 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''' 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() output_url = os.popen(command).read()
#delete all files in current directory except this script #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"] 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: if file.split(".")[-1] in file_types:
#os.remove(f"data/ytdl/{file}") #os.remove(f"{file}")
pass pass
return output_url return output_url
@ -45,10 +45,8 @@ def main():
#output_url = upload_to_litterbox(zip_file) #output_url = upload_to_litterbox(zip_file)
output_url = "test_url" output_url = "test_url"
print(output_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(output_url)
output_file.write("\n")
output_file.write(os.getcwd())
output_file.close() output_file.close()
else: else:
print("Invalid argument") print("Invalid argument")