removed directory assumptions, trying to use chdir
This commit is contained in:
parent
2141abae5e
commit
ee267275d6
2 changed files with 9 additions and 9 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue