mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-10 07:15:35 +08:00
avconv - output percentage
This commit is contained in:
commit
388ae2fc47
@ -43,7 +43,7 @@ which means you can modify it, redistribute it or use it however you like.
|
|||||||
%(autonumber)s to get an automatically incremented
|
%(autonumber)s to get an automatically incremented
|
||||||
number, %(ext)s for the filename extension,
|
number, %(ext)s for the filename extension,
|
||||||
%(upload_date)s for the upload date (YYYYMMDD),
|
%(upload_date)s for the upload date (YYYYMMDD),
|
||||||
%(extractor)s for the extractor used (youtube, metacafe,
|
%(extractor)s for the provider (youtube, metacafe,
|
||||||
etc), %(id)s for the video id and %% for a literal
|
etc), %(id)s for the video id and %% for a literal
|
||||||
percent. Use - to output to stdout.
|
percent. Use - to output to stdout.
|
||||||
-a, --batch-file FILE file containing URLs to download ('-' for stdin)
|
-a, --batch-file FILE file containing URLs to download ('-' for stdin)
|
||||||
|
@ -55,7 +55,7 @@ redistribute it or use it however you like.
|
|||||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ %(autonumber)s\ to\ get\ an\ automatically\ incremented
|
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ %(autonumber)s\ to\ get\ an\ automatically\ incremented
|
||||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ number,\ %(ext)s\ for\ the\ filename\ extension,
|
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ number,\ %(ext)s\ for\ the\ filename\ extension,
|
||||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ %(upload_date)s\ for\ the\ upload\ date\ (YYYYMMDD),
|
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ %(upload_date)s\ for\ the\ upload\ date\ (YYYYMMDD),
|
||||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ %(extractor)s\ for\ the\ extractor\ used\ (youtube,\ metacafe,
|
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ %(extractor)s\ for\ the\ provider\ (youtube,\ metacafe,
|
||||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ etc),\ %(id)s\ for\ the\ video\ id\ and\ %%\ for\ a\ literal
|
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ etc),\ %(id)s\ for\ the\ video\ id\ and\ %%\ for\ a\ literal
|
||||||
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ percent.\ Use\ -\ to\ output\ to\ stdout.
|
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ percent.\ Use\ -\ to\ output\ to\ stdout.
|
||||||
-a,\ --batch-file\ FILE\ \ \ \ file\ containing\ URLs\ to\ download\ (\[aq]-\[aq]\ for\ stdin)
|
-a,\ --batch-file\ FILE\ \ \ \ file\ containing\ URLs\ to\ download\ (\[aq]-\[aq]\ for\ stdin)
|
||||||
|
@ -683,11 +683,16 @@ class DailymotionIE(InfoExtractor):
|
|||||||
return
|
return
|
||||||
video_uploader = mobj.group(1)
|
video_uploader = mobj.group(1)
|
||||||
|
|
||||||
|
video_upload_date = u'NA'
|
||||||
|
mobj = re.search(r'<div class="[^"]*uploaded_cont[^"]*" title="[^"]*">([0-9]{2})-([0-9]{2})-([0-9]{4})</div>', webpage)
|
||||||
|
if mobj is not None:
|
||||||
|
video_upload_date = mobj.group(3) + mobj.group(2) + mobj.group(1)
|
||||||
|
|
||||||
return [{
|
return [{
|
||||||
'id': video_id.decode('utf-8'),
|
'id': video_id.decode('utf-8'),
|
||||||
'url': video_url.decode('utf-8'),
|
'url': video_url.decode('utf-8'),
|
||||||
'uploader': video_uploader.decode('utf-8'),
|
'uploader': video_uploader.decode('utf-8'),
|
||||||
'upload_date': u'NA',
|
'upload_date': video_upload_date,
|
||||||
'title': video_title,
|
'title': video_title,
|
||||||
'ext': video_extension.decode('utf-8'),
|
'ext': video_extension.decode('utf-8'),
|
||||||
'format': u'NA',
|
'format': u'NA',
|
||||||
|
@ -89,15 +89,25 @@ class FFmpegExtractAudioPP(PostProcessor):
|
|||||||
return None
|
return None
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
return None
|
return None
|
||||||
audio_codec = None
|
codec = None
|
||||||
|
duration = None
|
||||||
for line in output.split('\n'):
|
for line in output.split('\n'):
|
||||||
if line.startswith('codec_name='):
|
if line.startswith('codec_name='):
|
||||||
audio_codec = line.split('=')[1].strip()
|
codec = line.split('=')[1].strip()
|
||||||
elif line.strip() == 'codec_type=audio' and audio_codec is not None:
|
elif line.startswith('duration='):
|
||||||
return audio_codec
|
duration = line.split('=')[1].strip()
|
||||||
return None
|
try:
|
||||||
|
duration = float(duration)
|
||||||
|
except:
|
||||||
|
duration = None
|
||||||
|
elif line.strip() == '[/STREAM]' and codec is not None:
|
||||||
|
break
|
||||||
|
return {
|
||||||
|
'codec': codec,
|
||||||
|
'duration': duration
|
||||||
|
}
|
||||||
|
|
||||||
def run_ffmpeg(self, path, out_path, codec, more_opts):
|
def run_ffmpeg(self, path, out_path, codec, more_opts, duration):
|
||||||
if not self._exes['ffmpeg'] and not self._exes['avconv']:
|
if not self._exes['ffmpeg'] and not self._exes['avconv']:
|
||||||
raise AudioConversionError('ffmpeg or avconv not found. Please install one.')
|
raise AudioConversionError('ffmpeg or avconv not found. Please install one.')
|
||||||
if codec is None:
|
if codec is None:
|
||||||
@ -107,16 +117,55 @@ class FFmpegExtractAudioPP(PostProcessor):
|
|||||||
cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], '-y', '-i', encodeFilename(path), '-vn']
|
cmd = ([self._exes['avconv'] or self._exes['ffmpeg'], '-y', '-i', encodeFilename(path), '-vn']
|
||||||
+ acodec_opts + more_opts +
|
+ acodec_opts + more_opts +
|
||||||
['--', encodeFilename(out_path)])
|
['--', encodeFilename(out_path)])
|
||||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
start = time.time()
|
||||||
stdout,stderr = p.communicate()
|
# open process redirecting stderr to stdout
|
||||||
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
|
||||||
|
import fcntl
|
||||||
|
import errno
|
||||||
|
import select
|
||||||
|
# entire captured output
|
||||||
|
p_output = ''
|
||||||
|
# size= 765kB time=243.67 bitrate= 25.7kbits/s
|
||||||
|
reo = re.compile("""size=\s*(?P<size>\S+) # size
|
||||||
|
\stime=(?P<time>\S+) # time
|
||||||
|
\sbitrate=\s*(?P<bitrate>[\d\.]+) # bitrate
|
||||||
|
""", re.X)
|
||||||
|
# make stdout non-blocking
|
||||||
|
fcntl.fcntl(p.stdout.fileno(), fcntl.F_SETFL, fcntl.fcntl(p.stdout.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK)
|
||||||
|
while p.poll() == None:
|
||||||
|
# check if there is some output waiting
|
||||||
|
readx = select.select([p.stdout.fileno()], [], [])[0]
|
||||||
|
if readx:
|
||||||
|
# got some output, read it
|
||||||
|
chunk = p.stdout.read()
|
||||||
|
if chunk == '':
|
||||||
|
break
|
||||||
|
m = reo.match(chunk)
|
||||||
|
if m:
|
||||||
|
info = m.groupdict()
|
||||||
|
info['time'] = float(info['time'])
|
||||||
|
# compute current position
|
||||||
|
pos = None
|
||||||
|
if duration is not None:
|
||||||
|
if info['time'] < duration:
|
||||||
|
pos = info['time']
|
||||||
|
else:
|
||||||
|
pos = duration
|
||||||
|
if not self._downloader.params.get('noprogress', False):
|
||||||
|
self._downloader.to_screen(u'\r[' + (self._exes['avconv'] and 'avconv' or 'ffmpeg') + '] %s of %s ETA %s' % (self._downloader.calc_percent(pos, duration), duration, self._downloader.calc_eta(start, time.time(), duration, pos)), skip_eol=True)
|
||||||
|
self._downloader.to_cons_title(u'youtube-dl - %s of %s ETA %s' % (self._downloader.calc_percent(pos, duration), duration, self._downloader.calc_eta(start, time.time(), duration, pos)))
|
||||||
|
time.sleep(.1)
|
||||||
|
if not self._downloader.params.get('noprogress', False):
|
||||||
|
self._downloader.to_screen(u'')
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
msg = stderr.strip().split('\n')[-1]
|
msg = p_output.strip().split('\n')[-1]
|
||||||
raise AudioConversionError(msg)
|
raise AudioConversionError(msg)
|
||||||
|
|
||||||
def run(self, information):
|
def run(self, information):
|
||||||
path = information['filepath']
|
path = information['filepath']
|
||||||
|
|
||||||
filecodec = self.get_audio_codec(path)
|
fileinfo = self.get_audio_codec(path)
|
||||||
|
filecodec = fileinfo['codec'] if fileinfo is not None else None
|
||||||
if filecodec is None:
|
if filecodec is None:
|
||||||
self._downloader.to_stderr(u'WARNING: unable to obtain file audio codec with ffprobe')
|
self._downloader.to_stderr(u'WARNING: unable to obtain file audio codec with ffprobe')
|
||||||
return None
|
return None
|
||||||
@ -148,7 +197,7 @@ class FFmpegExtractAudioPP(PostProcessor):
|
|||||||
more_opts += [self._exes['avconv'] and '-b:a' or '-ab', self._preferredquality]
|
more_opts += [self._exes['avconv'] and '-b:a' or '-ab', self._preferredquality]
|
||||||
else:
|
else:
|
||||||
# We convert the audio (lossy)
|
# We convert the audio (lossy)
|
||||||
acodec = {'mp3': 'libmp3lame', 'aac': 'aac', 'm4a': 'aac', 'vorbis': 'libvorbis', 'wav': None}[self._preferredcodec]
|
acodec = {'mp3': 'libmp3lame', 'aac': 'libfaac', 'm4a': 'aac', 'vorbis': 'libvorbis', 'wav': None}[self._preferredcodec]
|
||||||
extension = self._preferredcodec
|
extension = self._preferredcodec
|
||||||
more_opts = []
|
more_opts = []
|
||||||
if self._preferredquality is not None:
|
if self._preferredquality is not None:
|
||||||
@ -170,7 +219,7 @@ class FFmpegExtractAudioPP(PostProcessor):
|
|||||||
new_path = prefix + sep + extension
|
new_path = prefix + sep + extension
|
||||||
self._downloader.to_screen(u'[' + (self._exes['avconv'] and 'avconv' or 'ffmpeg') + '] Destination: ' + new_path)
|
self._downloader.to_screen(u'[' + (self._exes['avconv'] and 'avconv' or 'ffmpeg') + '] Destination: ' + new_path)
|
||||||
try:
|
try:
|
||||||
self.run_ffmpeg(path, new_path, acodec, more_opts)
|
self.run_ffmpeg(path, new_path, acodec, more_opts, fileinfo['duration'] if fileinfo is not None else None)
|
||||||
except:
|
except:
|
||||||
etype,e,tb = sys.exc_info()
|
etype,e,tb = sys.exc_info()
|
||||||
if isinstance(e, AudioConversionError):
|
if isinstance(e, AudioConversionError):
|
||||||
|
@ -269,7 +269,7 @@ def parseOpts():
|
|||||||
action='store_true', dest='autonumber',
|
action='store_true', dest='autonumber',
|
||||||
help='number downloaded files starting from 00000', default=False)
|
help='number downloaded files starting from 00000', default=False)
|
||||||
filesystem.add_option('-o', '--output',
|
filesystem.add_option('-o', '--output',
|
||||||
dest='outtmpl', metavar='TEMPLATE', help='output filename template. Use %(stitle)s to get the title, %(uploader)s for the uploader name, %(autonumber)s to get an automatically incremented number, %(ext)s for the filename extension, %(upload_date)s for the upload date (YYYYMMDD), %(extractor)s for the extractor used (youtube, metacafe, etc), %(id)s for the video id and %% for a literal percent. Use - to output to stdout.')
|
dest='outtmpl', metavar='TEMPLATE', help='output filename template. Use %(stitle)s to get the title, %(uploader)s for the uploader name, %(autonumber)s to get an automatically incremented number, %(ext)s for the filename extension, %(upload_date)s for the upload date (YYYYMMDD), %(extractor)s for the provider (youtube, metacafe, etc), %(id)s for the video id and %% for a literal percent. Use - to output to stdout.')
|
||||||
filesystem.add_option('-a', '--batch-file',
|
filesystem.add_option('-a', '--batch-file',
|
||||||
dest='batchfile', metavar='FILE', help='file containing URLs to download (\'-\' for stdin)')
|
dest='batchfile', metavar='FILE', help='file containing URLs to download (\'-\' for stdin)')
|
||||||
filesystem.add_option('-w', '--no-overwrites',
|
filesystem.add_option('-w', '--no-overwrites',
|
||||||
|
Loading…
Reference in New Issue
Block a user