From 3974c5aa1cf711ebeffc201ad3b7832ec587cf7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sat, 4 Feb 2017 18:00:20 +0100 Subject: [PATCH] implemented a wrapper helping with verbosity --- coub-dl.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/coub-dl.py b/coub-dl.py index 5d773aa..0fb5418 100644 --- a/coub-dl.py +++ b/coub-dl.py @@ -6,6 +6,7 @@ from enum import Enum from datetime import timedelta from math import floor from argparse import ArgumentParser +from functools import wraps @@ -31,6 +32,16 @@ class File(Enum): FRACTION = 3 OUTPUT = 4 +def call_verbose(before_message=''): + def wrap(f): + @wraps(f) + def wrapper(*args, **kwargs): + print_opt(before_message+' ', end='', flush=True) + f(*args, **kwargs) + print_opt('Done!') + return wrapper + return wrap + def print_opt(*args, **kwargs): if VERBOSE: print(*args, **kwargs) @@ -48,20 +59,20 @@ def getDuration(ffprobe_output): raise ValueError('Cannot process ffprobe output!') return duration -def downloadStreams(): - print_opt('Downloading audio stream... ', end='', flush=True) +@call_verbose(before_message='Downloading audio stream...') +def download_audio_stream(): call(('youtube-dl', '--ignore-config', '--extract-audio', '--output', '{}.%(ext)s'.format(FILES[Stream.AUDIO]), URL), stdout=DEVNULL, stderr=DEVNULL) - print_opt('Done!') - print_opt('Downloading video stream... ', end='', flush=True) + +@call_verbose(before_message='Downloading video stream...') +def download_video_stream(): call(('youtube-dl', '--ignore-config', '--output', '{}.%(ext)s'.format(FILES[Stream.VIDEO]), URL), stdout=DEVNULL, stderr=DEVNULL) - print_opt('Done!') def readExtensions(): for file in listdir(): @@ -116,7 +127,8 @@ if exists(FILES[File.OUTPUT]): remove(FILES[File.OUTPUT]) # download streams and update FILE dict with extensions -downloadStreams() +download_audio_stream() +download_video_stream() readExtensions() # get stream lengths via ffprobe