Fix yt-dlp call
This commit is contained in:
@@ -13,20 +13,22 @@ class DownloadedFileNotFoundException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def execute(cmd):
|
||||
def execute(cmd, isVideo):
|
||||
print('Executing "{}"'.format(cmd))
|
||||
p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
|
||||
p.wait()
|
||||
stdout, stderr = p.communicate()
|
||||
print(stdout.decode())
|
||||
if p.returncode != 0:
|
||||
print(stderr.decode())
|
||||
raise YoutubeDLFailedException("ERROR: youtube-dl exited with non-zero: \n{}\nYou may have to update it!".format(stderr.decode()))
|
||||
return get_absolute_filename(stdout.decode(), stderr.decode())
|
||||
return get_absolute_filename(stdout.decode(), stderr.decode(), isVideo)
|
||||
|
||||
|
||||
def get_absolute_filename(stdout, stderr):
|
||||
regex_foo = re.search(r'Destination:\s(.*mp3)', stdout)
|
||||
def get_absolute_filename(stdout, stderr, isVideo):
|
||||
if isVideo:
|
||||
regex_foo = re.search(r'Destination:\s(.*mp4)', stdout)
|
||||
else:
|
||||
regex_foo = re.search(r'Destination:\s(.*mp3)', stdout)
|
||||
if not regex_foo:
|
||||
raise DownloadedFileNotFoundException("ERROR: Can not extract output file via regex. \nstderr: {}\nstdout: {}".format(stderr, stdout))
|
||||
return regex_foo.group(1)
|
||||
@@ -45,21 +47,23 @@ def youtubedl_download(url, destination_dir, proxy=None, video=False):
|
||||
if video:
|
||||
youtube_dl_cmd = config["youtubedl"]["command"] + \
|
||||
proxy_command + \
|
||||
" -f \"best\" " + \
|
||||
" -f b " + \
|
||||
"--no-cache-dir " + \
|
||||
"--merge-output-format mp4 " + \
|
||||
f"-o \"{destination_dir}/%(title)s.%(ext)s\" " + \
|
||||
f"-o \"{destination_dir}/%(title)s [video].%(ext)s\" " + \
|
||||
quote(url)
|
||||
else:
|
||||
youtube_dl_cmd = config["youtubedl"]["command"] + \
|
||||
proxy_command + \
|
||||
" -x --audio-format mp3 " + \
|
||||
"--audio-quality 0 " + \
|
||||
f"-o \"{destination_dir}/%(title)s.%(ext)s\" " + \
|
||||
f"-o \"{destination_dir}/%(title)s [audio].%(ext)s\" " + \
|
||||
"--embed-metadata " + \
|
||||
"--no-embed-chapters " + \
|
||||
"--no-cache-dir " + \
|
||||
quote(url)
|
||||
|
||||
filename_absolute = execute(youtube_dl_cmd)
|
||||
filename_absolute = execute(youtube_dl_cmd, video)
|
||||
return filename_absolute
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user