made writing noncritical stuff to stdout optional
This commit is contained in:
parent
72910c3367
commit
ce32850410
23
coub-dl.py
23
coub-dl.py
@ -18,6 +18,11 @@ class File(Enum):
|
|||||||
LOOP = 2
|
LOOP = 2
|
||||||
OUTPUT = 3
|
OUTPUT = 3
|
||||||
|
|
||||||
|
VERBOSE = True
|
||||||
|
def print_opt(*args, **kwargs):
|
||||||
|
if VERBOSE:
|
||||||
|
print(*args, **kwargs)
|
||||||
|
|
||||||
def getCmdStdErr(command):
|
def getCmdStdErr(command):
|
||||||
process = Popen(command, stderr=PIPE, stdout=PIPE)
|
process = Popen(command, stderr=PIPE, stdout=PIPE)
|
||||||
out, err = process.communicate()
|
out, err = process.communicate()
|
||||||
@ -32,17 +37,17 @@ def getDuration(ffprobe_output):
|
|||||||
return duration
|
return duration
|
||||||
|
|
||||||
def downloadStreams():
|
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',
|
call(('/usr/bin/env', 'youtube-dl', '--extract-audio',
|
||||||
'--output', '{}.%(ext)s'.format(FILES[Stream.AUDIO]),
|
'--output', '{}.%(ext)s'.format(FILES[Stream.AUDIO]),
|
||||||
URL),
|
URL),
|
||||||
stdout=DEVNULL, stderr=DEVNULL)
|
stdout=DEVNULL, stderr=DEVNULL)
|
||||||
print('Done!')
|
print_opt('Done!')
|
||||||
print('Downloading video stream... ', end='', flush=True)
|
print_opt('Downloading video stream... ', end='', flush=True)
|
||||||
call(('/usr/bin/env', 'youtube-dl', '--output', '{}.%(ext)s'.format(FILES[Stream.VIDEO]),
|
call(('/usr/bin/env', 'youtube-dl', '--output', '{}.%(ext)s'.format(FILES[Stream.VIDEO]),
|
||||||
URL),
|
URL),
|
||||||
stdout=DEVNULL, stderr=DEVNULL)
|
stdout=DEVNULL, stderr=DEVNULL)
|
||||||
print('Done!')
|
print_opt('Done!')
|
||||||
|
|
||||||
def readExtensions():
|
def readExtensions():
|
||||||
for file in listdir():
|
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]):
|
if exists(FILES[File.OUTPUT]):
|
||||||
answer = yes_no_question('A file named "{}" already exists! Overwrite?'.format(FILES[File.OUTPUT]), default='no')
|
answer = yes_no_question('A file named "{}" already exists! Overwrite?'.format(FILES[File.OUTPUT]), default='no')
|
||||||
if not answer:
|
if not answer:
|
||||||
print('Exiting!')
|
print_opt('Exiting!')
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
remove(FILES[File.OUTPUT])
|
remove(FILES[File.OUTPUT])
|
||||||
@ -116,17 +121,17 @@ with open(FILES[File.LIST], 'w') as f:
|
|||||||
print("file '{}'".format(shorterFile), file=f)
|
print("file '{}'".format(shorterFile), file=f)
|
||||||
|
|
||||||
# loop & mux
|
# 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]),
|
call(('/usr/bin/env', 'ffmpeg', '-f', 'concat', '-i', FILES[File.LIST], '-c', 'copy', FILES[File.LOOP]),
|
||||||
stdout=DEVNULL, stderr=DEVNULL)
|
stdout=DEVNULL, stderr=DEVNULL)
|
||||||
print('Done!')
|
print_opt('Done!')
|
||||||
print('Muxing streams... ', end='', flush=True)
|
print_opt('Muxing streams... ', end='', flush=True)
|
||||||
call(('/usr/bin/env', 'ffmpeg', '-i', FILES[File.LOOP],
|
call(('/usr/bin/env', 'ffmpeg', '-i', FILES[File.LOOP],
|
||||||
'-i', FILES[Stream.AUDIO],
|
'-i', FILES[Stream.AUDIO],
|
||||||
'-map', '0', '-map', '1',
|
'-map', '0', '-map', '1',
|
||||||
'-c', 'copy', FILES[File.OUTPUT]),
|
'-c', 'copy', FILES[File.OUTPUT]),
|
||||||
stdout=DEVNULL, stderr=DEVNULL)
|
stdout=DEVNULL, stderr=DEVNULL)
|
||||||
print('Done!')
|
print_opt('Done!')
|
||||||
|
|
||||||
# cleanup
|
# cleanup
|
||||||
for key in FILES:
|
for key in FILES:
|
||||||
|
Loading…
Reference in New Issue
Block a user