implemented a wrapper helping with verbosity

This commit is contained in:
Kjistóf 2017-02-04 18:00:20 +01:00
parent 74e2d1b26f
commit 3974c5aa1c

View File

@ -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