From 5030c2f78c38770999e573eb8a0867cc9c1dc367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Thu, 9 Feb 2017 12:16:38 +0100 Subject: [PATCH] implemented check for ytdl & ffmpeg --- coub-dl.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/coub-dl.py b/coub-dl.py index 631f19e..0553145 100644 --- a/coub-dl.py +++ b/coub-dl.py @@ -1,4 +1,4 @@ -from subprocess import call, Popen, PIPE, check_output, DEVNULL +from subprocess import call, Popen, PIPE, check_output, DEVNULL, CalledProcessError from os import listdir, remove from os.path import splitext, exists, join from re import match @@ -138,6 +138,31 @@ def mux_streams(file_dict): stdout=DEVNULL, stderr=DEVNULL) +@call_verbose(before_message='Checking your system for youtube-dl and ffmpeg... ', after_message='Found both!') +def check_for_ytdl_and_ffmpeg(): + error_str = '\nNo {} found in PATH! coub-dl requires youtube-dl & ffmpeg.' + ytdl_found = False + ffmpeg_found = False + 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: + print_opt(error_str.format('youtube-dl nor ffmpeg')) + elif not ytdl_found: + print_opt(error_str.format('youtube-dl')) + elif not ffmpeg_found: + print_opt(error_str.format('ffmpeg')) + exit() + + def determine_output_filename(url, user_supplied, extension, files_dict): if user_supplied is None: files_dict[File.OUTPUT] = check_output(('youtube-dl', '--get-title', url)).decode('utf-8').strip() @@ -197,6 +222,8 @@ if __name__ == '__main__': args = parse_cmd_arguments() VERBOSE = False if args.nonverbose else True + check_for_ytdl_and_ffmpeg() + # create dict that contains files used FILES = {Stream.AUDIO: 'audio', Stream.VIDEO: 'video', File.LIST: 'list.txt', File.LOOP: 'loop', File.FRACTION: 'fraction',