refactored check_output().decode().rstrip() to a little helper method

This commit is contained in:
Kjistóf 2017-08-22 01:25:52 +02:00
parent 1e7a5a2cf2
commit 3d51485d77
1 changed files with 9 additions and 5 deletions

View File

@ -47,6 +47,10 @@ def print_opt(*args, **kwargs):
print(*args, **kwargs)
def get_output(*args, **kwargs):
return check_output(*args, **kwargs).decode().rstrip('\n')
def run(url, files_dict, directory):
# download streams and update FILE dict with extensions
download_audio_stream(url, files_dict)
@ -91,8 +95,8 @@ def download_audio_stream(url, file_dict):
@call_verbose(before_message='Downloading video stream... ')
def download_video_stream(url, file_dict):
url = check_output(('youtube-dl',
'--get-url', url)).decode('utf-8').strip()
url = get_output(('youtube-dl',
'--get-url', url))
curl = Popen(('curl', '--silent',
'--write-out',
@ -103,8 +107,8 @@ def download_video_stream(url, file_dict):
grep = Popen(('grep', '--only-matching', '"http.*"'),
stdin=curl.stdout, stdout=PIPE)
url = check_output(('sed', 's/muted_//g'),
stdin=grep.stdout).decode('utf-8').strip().strip('"')
url = get_output(('sed', 's/muted_//g'),
stdin=grep.stdout).strip('"')
call(('youtube-dl', '--ignore-config',
'--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):
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:
files_dict[File.OUTPUT] = user_supplied
files_dict[File.OUTPUT] += extension