General script cleanup
This commit is contained in:
parent
f2a45a7ca3
commit
a39f4c9c51
36
dlaudio.py
36
dlaudio.py
@ -3,22 +3,36 @@
|
|||||||
|
|
||||||
Dependencies:
|
Dependencies:
|
||||||
=============
|
=============
|
||||||
|
|
||||||
* youtube-dl
|
* youtube-dl
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import pathlib
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
# =========== Constants ==========
|
# =========== Constants ==========
|
||||||
YOUTUBE_DL_BIN = shutil.which("youtube-dl")
|
YOUTUBE_DL_BIN = "/usr/bin/youtube-dl"
|
||||||
DEFAULT_FILENAME = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
|
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
|
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 = argparse.ArgumentParser()
|
||||||
parser.add_argument("-b", "--batchfile", help="provide the links from a text file")
|
parser.add_argument("-b", "--batchfile", help="provide the links from a text file")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@ -28,13 +42,17 @@ parser.add_argument(
|
|||||||
"-n", "--filename", type=str, help="downloaded filename (without extension)"
|
"-n", "--filename", type=str, help="downloaded filename (without extension)"
|
||||||
)
|
)
|
||||||
parser.add_argument("urls", nargs="*", help="video URLs")
|
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 = [
|
dl_opts = [
|
||||||
YOUTUBE_DL_BIN,
|
YOUTUBE_DL_BIN,
|
||||||
"--no-part",
|
*DEFAULT_YOUTUBE_DL_OPTS,
|
||||||
"--no-continue",
|
|
||||||
"--extract-audio",
|
|
||||||
f"--audio-format={args.format}",
|
f"--audio-format={args.format}",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user