[qqmusic] Use _check_formats instead

This commit is contained in:
ping 2015-06-18 23:09:04 +08:00
parent 0392ac98d2
commit 4d58b24c15

View file

@ -9,13 +9,8 @@ from .common import InfoExtractor
from ..utils import ( from ..utils import (
strip_jsonp, strip_jsonp,
unescapeHTML, unescapeHTML,
HEADRequest,
ExtractorError,
)
from ..compat import (
compat_urllib_request,
compat_HTTPError,
) )
from ..compat import compat_urllib_request
class QQMusicIE(InfoExtractor): class QQMusicIE(InfoExtractor):
@ -104,24 +99,15 @@ class QQMusicIE(InfoExtractor):
formats = [] formats = []
for format_id, details in self._FORMATS.items(): for format_id, details in self._FORMATS.items():
video_url = 'http://cc.stream.qqmusic.qq.com/%s%s.%s?vkey=%s&guid=%s&fromtag=0' \ formats.append({
% (details['prefix'], mid, details['ext'], vkey, guid) 'url': 'http://cc.stream.qqmusic.qq.com/%s%s.%s?vkey=%s&guid=%s&fromtag=0'
req = HEADRequest(video_url) % (details['prefix'], mid, details['ext'], vkey, guid),
try: 'format': format_id,
res = self._request_webpage( 'format_id': format_id,
req, mid, note='Testing %s video URL' % format_id, fatal=False) 'preference': details['preference'],
except ExtractorError as e: 'abr': details.get('abr'),
if isinstance(e.cause, compat_HTTPError) and e.cause.code in [400, 404]: })
self.report_warning('Invalid %s video URL' % format_id, mid) self._check_formats(formats, mid)
else:
if res:
formats.append({
'url': video_url,
'format': format_id,
'format_id': format_id,
'preference': details['preference'],
'abr': details.get('abr'),
})
self._sort_formats(formats) self._sort_formats(formats)
return { return {