further improved handling of filenames
This commit is contained in:
parent
0c3b92fc9d
commit
3889b760c3
17
coub-dl.py
17
coub-dl.py
@ -2,9 +2,14 @@ from subprocess import call, Popen, PIPE
|
|||||||
from os import listdir
|
from os import listdir
|
||||||
from re import match
|
from re import match
|
||||||
from sys import argv
|
from sys import argv
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Stream(Enum):
|
||||||
|
AUDIO = 1
|
||||||
|
VIDEO = 2
|
||||||
|
|
||||||
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()
|
||||||
@ -19,16 +24,16 @@ def getDuration(ffprobe_output):
|
|||||||
return duration
|
return duration
|
||||||
|
|
||||||
|
|
||||||
argv.append('https://coub.com/view/aeeuu')
|
argv.append('https://coub.com/view/aeeuu') # TODO: remove debug line
|
||||||
|
|
||||||
FILES = {'AUDIO': 'audio', 'VIDEO': 'video'}
|
FILES = {Stream.AUDIO: 'audio', Stream.VIDEO: 'video'}
|
||||||
URL = argv[1] if len(argv) > 0 else '' # youtube-dl error message will be shown if ''
|
URL = argv[1] if len(argv) > 0 else '' # youtube-dl error message will be shown if ''
|
||||||
|
|
||||||
|
|
||||||
call(('/usr/bin/env', 'youtube-dl', '--extract-audio',
|
call(('/usr/bin/env', 'youtube-dl', '--extract-audio',
|
||||||
'--output', '{}.%(ext)s'.format(FILES['AUDIO']),
|
'--output', '{}.%(ext)s'.format(FILES[Stream.AUDIO]),
|
||||||
URL))
|
URL))
|
||||||
call(('/usr/bin/env', 'youtube-dl', '--output', '{}.%(ext)s'.format(FILES['VIDEO']),
|
call(('/usr/bin/env', 'youtube-dl', '--output', '{}.%(ext)s'.format(FILES[Stream.VIDEO]),
|
||||||
URL))
|
URL))
|
||||||
|
|
||||||
for file in listdir():
|
for file in listdir():
|
||||||
@ -36,8 +41,8 @@ for file in listdir():
|
|||||||
if match('^{}.*'.format(FILES[filename]), file):
|
if match('^{}.*'.format(FILES[filename]), file):
|
||||||
FILES[filename] = file
|
FILES[filename] = file
|
||||||
|
|
||||||
audioLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES['AUDIO'])))
|
audioLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES[Stream.AUDIO])))
|
||||||
videoLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES['VIDEO'])))
|
videoLen = getDuration(getCmdStdErr(('/usr/bin/env', 'ffprobe', FILES[Stream.VIDEO])))
|
||||||
|
|
||||||
print(audioLen)
|
print(audioLen)
|
||||||
print(videoLen)
|
print(videoLen)
|
||||||
|
Loading…
Reference in New Issue
Block a user