improved dependency checking

This commit is contained in:
Kjistóf 2017-08-21 22:51:05 +02:00
parent 68426271f0
commit 0bf31633db
1 changed files with 11 additions and 23 deletions

View File

@ -16,6 +16,7 @@ from functools import wraps
from tempfile import mkdtemp from tempfile import mkdtemp
from shutil import rmtree from shutil import rmtree
from signal import signal, SIGINT from signal import signal, SIGINT
from sys import exit
@ -145,30 +146,17 @@ def mux_streams(file_dict):
stdout=DEVNULL, stderr=DEVNULL) stdout=DEVNULL, stderr=DEVNULL)
@call_verbose(before_message='Checking your system for youtube-dl and ffmpeg... ', after_message='Found both!') @call_verbose(before_message='Checking your system for dependencies... ', after_message='Found all!')
def check_for_ytdl_and_ffmpeg(): def check_for_dependencies():
error_str = '\nNo {} found in PATH! coub-dl requires youtube-dl & ffmpeg.' check_for = (('youtube-dl', '--version'), ('ffmpeg', '-version'), ('curl', '--version'))
ytdl_found = False error_str = '\nMissing dependencies: {}'
ffmpeg_found = False missing = []
try:
check_output(('youtube-dl', '--version'))
ytdl_found = True
except (CalledProcessError, FileNotFoundError):
pass
try:
check_output(('ffmpeg', '-version'))
ffmpeg_found = True
except (CalledProcessError, FileNotFoundError):
pass
if not ytdl_found and not ffmpeg_found: for command in check_for:
print_opt(error_str.format('youtube-dl nor ffmpeg')) try: check_output(command)
elif not ytdl_found: except (CalledProcessError, FileNotFoundError): missing.append(command[0])
print_opt(error_str.format('youtube-dl'))
elif not ffmpeg_found:
print_opt(error_str.format('ffmpeg'))
if not ytdl_found or not ffmpeg_found: exit() if missing: exit(error_str.format(', '.join(missing)))
def determine_output_filename(url, user_supplied, extension, files_dict): def determine_output_filename(url, user_supplied, extension, files_dict):
@ -243,7 +231,7 @@ if __name__ == '__main__':
args = parse_cmd_arguments() args = parse_cmd_arguments()
VERBOSE = False if args.nonverbose else True VERBOSE = False if args.nonverbose else True
check_for_ytdl_and_ffmpeg() check_for_dependencies()
# create dict that contains files used # create dict that contains files used
FILES, OUTPUT_KEYS = build_default_files_dict() FILES, OUTPUT_KEYS = build_default_files_dict()