Minor bug fixes and incorrect option passing fixes

This commit is contained in:
Eric Torres 2019-02-20 02:47:48 -08:00
parent bbfff16b44
commit 45aac4e39b

View File

@ -21,8 +21,6 @@ E_NOURLS = 2
# ========== Main Script ========== # ========== Main Script ==========
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-b', '--batchfile', parser.add_argument('-b', '--batchfile',
type=str,
nargs=1,
help='provide the links from a text file') help='provide the links from a text file')
parser.add_argument('-f', '--format', parser.add_argument('-f', '--format',
type=str, type=str,
@ -40,22 +38,22 @@ dl_opts = [YOUTUBE_DL_BIN,
'--no-part', '--no-part',
'--no-continue', '--no-continue',
'--extract-audio', '--extract-audio',
'--audio-format={args.format}'] f"--audio-format={args.format}"]
# filename handling # filename handling
# if -b is used, DEFAULT_FILENAME must take precedence # if -b is used, DEFAULT_FILENAME must take precedence
if args.filename: if args.filename is not None and args.batchfile is None:
dl_opts.append('--output={args.filename}') dl_opts.append(f"--output={args.filename}")
else: else:
dl_opts.append('--output={DEFAULT_FILENAME}') dl_opts.append(f"--output={DEFAULT_FILENAME}")
# URL handling # URL handling
if args.batchfile: if args.batchfile is not None:
dl_opts.append(f"--batch-file={args.batchfile}") dl_opts.append(f"--batch-file={args.batchfile}")
elif not args.urls: elif args.urls is not None:
dl_opts.extend(args.urls)
else:
print("URLs are required") print("URLs are required")
exit(E_NOURLS) exit(E_NOURLS)
else:
dl_opts.extend(args.urls)
subprocess.run(dl_opts) subprocess.run(dl_opts)