From abc7d96b04d2e5956812088019ca40f42b8c7a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sun, 5 Feb 2017 17:39:46 +0100 Subject: [PATCH] continued refactor-streak --- coub-dl.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/coub-dl.py b/coub-dl.py index 5321423..a563450 100644 --- a/coub-dl.py +++ b/coub-dl.py @@ -107,6 +107,11 @@ def cleanup(file_dict, outputs): pass +def get_length(file): + data = get_duration(get_command_stderr(('ffprobe', file))).split(':') + return timedelta(hours=float(data[0]), minutes=float(data[1]), seconds=float(data[2])) + + def yes_no_question(question, default): valid = {"yes": True, "y": True, "ye": True, "no": False, "n": False} @@ -176,11 +181,8 @@ download_video_stream(URL, FILES) read_extensions(FILES) # get stream lengths via ffprobe -audioData= get_duration(get_command_stderr(('ffprobe', FILES[Stream.AUDIO]))).split(':') -videoData = get_duration(get_command_stderr(('ffprobe', FILES[Stream.VIDEO]))).split(':') - -audioLen = timedelta(hours=float(audioData[0]), minutes=float(audioData[1]), seconds=float(audioData[2])) -videoLen = timedelta(hours=float(videoData[0]), minutes=float(videoData[1]), seconds=float(videoData[2])) +audioLen = get_length(FILES[Stream.AUDIO]) +videoLen = get_length(FILES[Stream.VIDEO]) # decide which stream needs some looping longer = audioLen if audioLen > videoLen else videoLen