Fixed incorrect variable name and corrected an issue with reading as a list when the argument was a single URL
This commit is contained in:
parent
32b12536de
commit
8af3f8372e
|
@ -3,11 +3,12 @@
|
|||
import os
|
||||
import re
|
||||
import sys
|
||||
import datetime
|
||||
|
||||
import requests
|
||||
import subprocess
|
||||
from lxml import html
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import argparse
|
||||
|
||||
# Load variables from .env file
|
||||
|
@ -65,7 +66,7 @@ def update_stash():
|
|||
print(f"Update error: {e}")
|
||||
exit(1)
|
||||
|
||||
def download_file(file_url, download_dir, ytdlp_prefix):
|
||||
def download_file(file_url, download_dir, ytdlp_format):
|
||||
extensions = "(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF|mp4|MP4)"
|
||||
rgx_file = r"^.*\.{0}$".format(extensions)
|
||||
rgx_filename = r"[A-Za-z0-9_]*\.{0}".format(extensions)
|
||||
|
@ -113,8 +114,8 @@ def download_file(file_url, download_dir, ytdlp_prefix):
|
|||
return False
|
||||
else:
|
||||
print(STASH_PRINT_PREFIX, file_url)
|
||||
download_path = os.path.join(download_dir, ytdlp_prefix)
|
||||
command = ['yt-dlp', file_url, '-o', download_path]
|
||||
download_path = os.path.join(download_dir, ytdlp_format)
|
||||
command = ['yt-dlp', file_url, '-o', download_path, '--restrict-filenames']
|
||||
try:
|
||||
subprocess.run(command, check=True)
|
||||
return True
|
||||
|
@ -138,7 +139,7 @@ def is_path_or_url(arg): #chatgpt
|
|||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Download files or update stash.")
|
||||
parser.add_argument("url_or_path", metavar="URL_or_path", nargs="+", help="URL or file path to download")
|
||||
parser.add_argument("url_or_path", metavar="URL_or_path", nargs="?", help="URL or file path to download")
|
||||
parser.add_argument("-o", "--overwrite", action="store_true", help="Overwrite existing files if present")
|
||||
parser.add_argument("-u", "--update", action="store_true", help="Update stash")
|
||||
parser.add_argument("-n", "--no-update", action="store_true", help="Do not update stash")
|
||||
|
@ -155,9 +156,7 @@ if __name__ == "__main__":
|
|||
|
||||
url_or_path = args.url_or_path
|
||||
|
||||
valid_args = []
|
||||
if not args.url_or_path is None:
|
||||
valid_args = [arg for arg in args.url_or_path if is_path_or_url(arg) is not None]
|
||||
valid_args = [arg for arg in args.url_or_path if is_path_or_url(arg) is not None] if isinstance(args.url_or_path, list) else [args.url_or_path]
|
||||
|
||||
if valid_args is None or len(valid_args) == 0:
|
||||
print("Valid URL or file path required")
|
||||
|
|
Loading…
Reference in New Issue