6 Commits

4 changed files with 64 additions and 43 deletions

View File

@ -8,7 +8,7 @@ import re
import subprocess
# ========== Constants ==========
COMMENT_PATTERN = "^[#;]"
COMMENT_PATTERN = r"^[#;]"
EXCLUDE_FILE = "/etc/helper-scripts/ddusb-exclude.conf"
E_BLOCKDEVICE_ERROR = 1

View File

@ -3,22 +3,35 @@
Dependencies:
=============
* youtube-dl
"""
import argparse
import pathlib
import shutil
from pathlib import Path
import subprocess
# =========== Constants ==========
YOUTUBE_DL_BIN = shutil.which("youtube-dl")
DEFAULT_FILENAME = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
YOUTUBE_DL_BIN = "/usr/bin/youtube-dl"
DEFAULT_FILENAME = f"{Path.home() / 'Music'}/%(title)s.%(ext)s"
DEFAULT_YOUTUBE_DL_OPTS = (
"--no-part",
"--audio-quality=0",
"--no-continue",
"--extract-audio",
)
# ========== Error Codes ==========
# ----- Error Codes -----
E_NOURLS = 2
# ========== Main Script ==========
# ========== Functions ==========
def parse_cmdline_arguments(**kwargs):
"""Parse command line arguments passed to the script.
All kwargs are passed to ArgumentParser.parse_args().
:rtype: argparse.Namespace object
"""
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--batchfile", help="provide the links from a text file")
parser.add_argument(
@ -28,20 +41,24 @@ parser.add_argument(
"-n", "--filename", type=str, help="downloaded filename (without extension)"
)
parser.add_argument("urls", nargs="*", help="video URLs")
args = parser.parse_args()
return parser.parse_args()
# ========== Main Script ==========
if __name__ == "__main__":
args = parse_cmdline_arguments()
dl_opts = [
YOUTUBE_DL_BIN,
"--no-part",
"--no-continue",
"--extract-audio",
*DEFAULT_YOUTUBE_DL_OPTS,
f"--audio-format={args.format}",
]
# filename handling
# if -b is used, DEFAULT_FILENAME must take precedence
if args.filename is not None and args.batchfile is None:
dl_opts.append(f"--output={args.filename}")
dl_opts.append(f"--output={Path.home() / 'Music' / args.filename}.%(ext)s")
else:
dl_opts.append(f"--output={DEFAULT_FILENAME}")

View File

@ -19,6 +19,7 @@ BOOT_DIR = "/boot"
ETC_DIR = "/etc"
# ----- Exit Codes -----
E_INTERRUPT = 1
E_NOEDITORFOUND = 2
E_NOFILESELECTED = 3
@ -200,7 +201,10 @@ if __name__ == "__main__":
else locate_files(args.patterns)
)
try:
selected_file = run_fzf(files)
except KeyboardInterrupt:
exit(E_INTERRUPT)
if selected_file != "":
cmd = gen_editor_cmd(selected_file)

View File

@ -33,7 +33,7 @@ from termcolor import colored
FD_BIN = "/usr/bin/fd"
FD_OPTS = ["--hidden"]
# Matches 'y' or 'yes' only, ignoring case
USER_RESPONSE_YES = "^[Yy]{1}([Ee]{1}[Ss]{1})?$"
USER_RESPONSE_YES = r"^[Yy]{1}([Ee]{1}[Ss]{1})?$"
E_NO_RESULTS = 1
E_USER_RESPONSE_NO = 2
@ -137,7 +137,7 @@ if __name__ == "__main__":
for ext in args.extensions:
FD_OPTS.extend(["--extension", ext])
files = {}
files = set()
for pattern in args.patterns:
cmd = [FD_BIN, *FD_OPTS, pattern]
files.update(