[yahoo] Use centralized sorting, and add tbr field

This commit is contained in:
Philipp Hagemeister 2013-12-25 15:18:40 +01:00
parent b874fe2da8
commit 7217e148fb
4 changed files with 13 additions and 6 deletions

View file

@ -1018,6 +1018,8 @@ class YoutubeDL(object):
res += u'(unsupported) ' res += u'(unsupported) '
if fdict.get('format_note') is not None: if fdict.get('format_note') is not None:
res += fdict['format_note'] + u' ' res += fdict['format_note'] + u' '
if fdict.get('tbr') is not None:
res += u'%4dk ' % fdict['tbr']
if (fdict.get('vcodec') is not None and if (fdict.get('vcodec') is not None and
fdict.get('vcodec') != 'none'): fdict.get('vcodec') != 'none'):
res += u'%-5s@' % fdict['vcodec'] res += u'%-5s@' % fdict['vcodec']

View file

@ -57,6 +57,7 @@ class InfoExtractor(object):
* width Width of the video, if known * width Width of the video, if known
* height Height of the video, if known * height Height of the video, if known
* resolution Textual description of width and height * resolution Textual description of width and height
* tbr Average bitrate of audio and video in KBit/s
* abr Average audio bitrate in KBit/s * abr Average audio bitrate in KBit/s
* acodec Name of the audio codec in use * acodec Name of the audio codec in use
* vbr Average video bitrate in KBit/s * vbr Average video bitrate in KBit/s

View file

@ -6,8 +6,8 @@ from .common import InfoExtractor, SearchInfoExtractor
from ..utils import ( from ..utils import (
compat_urllib_parse, compat_urllib_parse,
compat_urlparse, compat_urlparse,
determine_ext,
clean_html, clean_html,
int_or_none,
) )
@ -68,9 +68,9 @@ class YahooIE(InfoExtractor):
formats = [] formats = []
for s in info['streams']: for s in info['streams']:
format_info = { format_info = {
'width': s.get('width'), 'width': int_or_none(s.get('width')),
'height': s.get('height'), 'height': int_or_none(s.get('height')),
'bitrate': s.get('bitrate'), 'tbr': int_or_none(s.get('bitrate')),
} }
host = s['host'] host = s['host']
@ -84,10 +84,10 @@ class YahooIE(InfoExtractor):
else: else:
format_url = compat_urlparse.urljoin(host, path) format_url = compat_urlparse.urljoin(host, path)
format_info['url'] = format_url format_info['url'] = format_url
format_info['ext'] = determine_ext(format_url)
formats.append(format_info) formats.append(format_info)
formats = sorted(formats, key=lambda f:(f['height'], f['width']))
self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,

View file

@ -1098,3 +1098,7 @@ def url_basename(url):
class HEADRequest(compat_urllib_request.Request): class HEADRequest(compat_urllib_request.Request):
def get_method(self): def get_method(self):
return "HEAD" return "HEAD"
def int_or_none(v):
return v if v is None else int(v)