implemented check for ytdl & ffmpeg

This commit is contained in:
Kjistóf 2017-02-09 12:16:38 +01:00
parent 010b141183
commit 5030c2f78c

View File

@ -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 import listdir, remove
from os.path import splitext, exists, join from os.path import splitext, exists, join
from re import match from re import match
@ -138,6 +138,31 @@ 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!')
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): def determine_output_filename(url, user_supplied, extension, files_dict):
if user_supplied is None: if user_supplied is None:
files_dict[File.OUTPUT] = check_output(('youtube-dl', '--get-title', url)).decode('utf-8').strip() 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() args = parse_cmd_arguments()
VERBOSE = False if args.nonverbose else True VERBOSE = False if args.nonverbose else True
check_for_ytdl_and_ffmpeg()
# create dict that contains files used # create dict that contains files used
FILES = {Stream.AUDIO: 'audio', Stream.VIDEO: 'video', FILES = {Stream.AUDIO: 'audio', Stream.VIDEO: 'video',
File.LIST: 'list.txt', File.LOOP: 'loop', File.FRACTION: 'fraction', File.LIST: 'list.txt', File.LOOP: 'loop', File.FRACTION: 'fraction',