From 0c3b92fc9dd7425ae6fcb0af487e48f7fcafe7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sun, 15 Jan 2017 20:14:01 +0100 Subject: [PATCH] refactored handling of filenames --- coub-dl.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/coub-dl.py b/coub-dl.py index b64fb9c..ec38c71 100644 --- a/coub-dl.py +++ b/coub-dl.py @@ -21,24 +21,23 @@ def getDuration(ffprobe_output): argv.append('https://coub.com/view/aeeuu') -AUDIO_FILE = 'audio' -VIDEO_FILE = 'video' +FILES = {'AUDIO': 'audio', 'VIDEO': 'video'} URL = argv[1] if len(argv) > 0 else '' # youtube-dl error message will be shown if '' + call(('/usr/bin/env', 'youtube-dl', '--extract-audio', - '--output', '{}.%(ext)s'.format(AUDIO_FILE), + '--output', '{}.%(ext)s'.format(FILES['AUDIO']), URL)) -call(('/usr/bin/env', 'youtube-dl', '--output', '{}.%(ext)s'.format(VIDEO_FILE), +call(('/usr/bin/env', 'youtube-dl', '--output', '{}.%(ext)s'.format(FILES['VIDEO']), URL)) for file in listdir(): - if match('^{}.*'.format(AUDIO_FILE), file): - AUDIO_FILE = file - if match('^{}.*'.format(VIDEO_FILE), file): - VIDEO_FILE = file + for filename in FILES: + if match('^{}.*'.format(FILES[filename]), file): + FILES[filename] = file -audioLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', AUDIO_FILE))) -videoLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', VIDEO_FILE))) +audioLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES['AUDIO']))) +videoLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES['VIDEO']))) print(audioLen) print(videoLen)