implemented check for ytdl & ffmpeg
This commit is contained in:
		
							
								
								
									
										29
									
								
								coub-dl.py
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								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',
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user