made writing noncritical stuff to stdout optional

This commit is contained in:
Kjistóf 2017-01-15 23:53:48 +01:00
parent 72910c3367
commit ce32850410
1 changed files with 14 additions and 9 deletions

View File

@ -18,6 +18,11 @@ class File(Enum):
LOOP = 2
OUTPUT = 3
VERBOSE = True
def print_opt(*args, **kwargs):
if VERBOSE:
print(*args, **kwargs)
def getCmdStdErr(command):
process = Popen(command, stderr=PIPE, stdout=PIPE)
out, err = process.communicate()
@ -32,17 +37,17 @@ def getDuration(ffprobe_output):
return duration
def downloadStreams():
print('Downloading audio stream... ', end='', flush=True)
print_opt('Downloading audio stream... ', end='', flush=True)
call(('/usr/bin/env', 'youtube-dl', '--extract-audio',
'--output', '{}.%(ext)s'.format(FILES[Stream.AUDIO]),
URL),
stdout=DEVNULL, stderr=DEVNULL)
print('Done!')
print('Downloading video stream... ', end='', flush=True)
print_opt('Done!')
print_opt('Downloading video stream... ', end='', flush=True)
call(('/usr/bin/env', 'youtube-dl', '--output', '{}.%(ext)s'.format(FILES[Stream.VIDEO]),
URL),
stdout=DEVNULL, stderr=DEVNULL)
print('Done!')
print_opt('Done!')
def readExtensions():
for file in listdir():
@ -86,7 +91,7 @@ FILES[File.OUTPUT] = check_output(('/usr/bin/env', 'youtube-dl', '--get-title',
if exists(FILES[File.OUTPUT]):
answer = yes_no_question('A file named "{}" already exists! Overwrite?'.format(FILES[File.OUTPUT]), default='no')
if not answer:
print('Exiting!')
print_opt('Exiting!')
exit()
else:
remove(FILES[File.OUTPUT])
@ -116,17 +121,17 @@ with open(FILES[File.LIST], 'w') as f:
print("file '{}'".format(shorterFile), file=f)
# loop & mux
print('Looping shorter stream... ', end='', flush=True)
print_opt('Looping shorter stream... ', end='', flush=True)
call(('/usr/bin/env', 'ffmpeg', '-f', 'concat', '-i', FILES[File.LIST], '-c', 'copy', FILES[File.LOOP]),
stdout=DEVNULL, stderr=DEVNULL)
print('Done!')
print('Muxing streams... ', end='', flush=True)
print_opt('Done!')
print_opt('Muxing streams... ', end='', flush=True)
call(('/usr/bin/env', 'ffmpeg', '-i', FILES[File.LOOP],
'-i', FILES[Stream.AUDIO],
'-map', '0', '-map', '1',
'-c', 'copy', FILES[File.OUTPUT]),
stdout=DEVNULL, stderr=DEVNULL)
print('Done!')
print_opt('Done!')
# cleanup
for key in FILES: