refactored check_output().decode().rstrip() to a little helper method
This commit is contained in:
parent
1e7a5a2cf2
commit
3d51485d77
14
coub-dl.py
14
coub-dl.py
@ -47,6 +47,10 @@ def print_opt(*args, **kwargs):
|
|||||||
print(*args, **kwargs)
|
print(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def get_output(*args, **kwargs):
|
||||||
|
return check_output(*args, **kwargs).decode().rstrip('\n')
|
||||||
|
|
||||||
|
|
||||||
def run(url, files_dict, directory):
|
def run(url, files_dict, directory):
|
||||||
# download streams and update FILE dict with extensions
|
# download streams and update FILE dict with extensions
|
||||||
download_audio_stream(url, files_dict)
|
download_audio_stream(url, files_dict)
|
||||||
@ -91,8 +95,8 @@ def download_audio_stream(url, file_dict):
|
|||||||
|
|
||||||
@call_verbose(before_message='Downloading video stream... ')
|
@call_verbose(before_message='Downloading video stream... ')
|
||||||
def download_video_stream(url, file_dict):
|
def download_video_stream(url, file_dict):
|
||||||
url = check_output(('youtube-dl',
|
url = get_output(('youtube-dl',
|
||||||
'--get-url', url)).decode('utf-8').strip()
|
'--get-url', url))
|
||||||
|
|
||||||
curl = Popen(('curl', '--silent',
|
curl = Popen(('curl', '--silent',
|
||||||
'--write-out',
|
'--write-out',
|
||||||
@ -103,8 +107,8 @@ def download_video_stream(url, file_dict):
|
|||||||
grep = Popen(('grep', '--only-matching', '"http.*"'),
|
grep = Popen(('grep', '--only-matching', '"http.*"'),
|
||||||
stdin=curl.stdout, stdout=PIPE)
|
stdin=curl.stdout, stdout=PIPE)
|
||||||
|
|
||||||
url = check_output(('sed', 's/muted_//g'),
|
url = get_output(('sed', 's/muted_//g'),
|
||||||
stdin=grep.stdout).decode('utf-8').strip().strip('"')
|
stdin=grep.stdout).strip('"')
|
||||||
|
|
||||||
call(('youtube-dl', '--ignore-config',
|
call(('youtube-dl', '--ignore-config',
|
||||||
'--output', '{}.%(ext)s'.format(file_dict[Stream.VIDEO]),
|
'--output', '{}.%(ext)s'.format(file_dict[Stream.VIDEO]),
|
||||||
@ -176,7 +180,7 @@ def check_for_dependencies():
|
|||||||
|
|
||||||
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] = get_output(('youtube-dl', '--get-title', url))
|
||||||
else:
|
else:
|
||||||
files_dict[File.OUTPUT] = user_supplied
|
files_dict[File.OUTPUT] = user_supplied
|
||||||
files_dict[File.OUTPUT] += extension
|
files_dict[File.OUTPUT] += extension
|
||||||
|
Loading…
Reference in New Issue
Block a user