mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-24 13:46:53 +01:00
[cspan] handle error massages and extract qualities
This commit is contained in:
parent
30787f7259
commit
355c7ad361
@ -9,16 +9,21 @@
|
|||||||
find_xpath_attr,
|
find_xpath_attr,
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
determine_ext,
|
determine_ext,
|
||||||
|
ExtractorError,
|
||||||
)
|
)
|
||||||
from .senateisvp import SenateISVPIE
|
from .senateisvp import SenateISVPIE
|
||||||
|
|
||||||
|
|
||||||
|
def get_text_attr(d, attr):
|
||||||
|
return d.get(attr, {}).get('#text')
|
||||||
|
|
||||||
|
|
||||||
class CSpanIE(InfoExtractor):
|
class CSpanIE(InfoExtractor):
|
||||||
_VALID_URL = r'http://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)'
|
_VALID_URL = r'http://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)'
|
||||||
IE_DESC = 'C-SPAN'
|
IE_DESC = 'C-SPAN'
|
||||||
_TESTS = [{
|
_TESTS = [{
|
||||||
'url': 'http://www.c-span.org/video/?313572-1/HolderonV',
|
'url': 'http://www.c-span.org/video/?313572-1/HolderonV',
|
||||||
'md5': '067803f994e049b455a58b16e5aab442',
|
'md5': '94b29a4f131ff03d23471dd6f60b6a1d',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '315139',
|
'id': '315139',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
@ -28,7 +33,7 @@ class CSpanIE(InfoExtractor):
|
|||||||
'skip': 'Regularly fails on travis, for unknown reasons',
|
'skip': 'Regularly fails on travis, for unknown reasons',
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models',
|
'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models',
|
||||||
'md5': '4eafd1e91a75d2b1e6a3cbd0995816a2',
|
'md5': '8e5fbfabe6ad0f89f3012a7943c1287b',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'c4486943',
|
'id': 'c4486943',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
@ -37,7 +42,7 @@ class CSpanIE(InfoExtractor):
|
|||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall',
|
'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall',
|
||||||
'md5': '446562a736c6bf97118e389433ed88d4',
|
'md5': '2ae5051559169baadba13fc35345ae74',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': '342759',
|
'id': '342759',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
@ -71,8 +76,10 @@ def _real_extract(self, url):
|
|||||||
return self.url_result(surl, 'SenateISVP', video_id, title)
|
return self.url_result(surl, 'SenateISVP', video_id, title)
|
||||||
|
|
||||||
data = self._download_json(
|
data = self._download_json(
|
||||||
'http://c-spanvideo.org/videoLibrary/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id),
|
'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id),
|
||||||
video_id)
|
video_id)['video']
|
||||||
|
if data['@status'] != 'Success':
|
||||||
|
raise ExtractorError('%s said: %s' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True)
|
||||||
|
|
||||||
doc = self._download_xml(
|
doc = self._download_xml(
|
||||||
'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id),
|
'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id),
|
||||||
@ -83,28 +90,36 @@ def _real_extract(self, url):
|
|||||||
title = find_xpath_attr(doc, './/string', 'name', 'title').text
|
title = find_xpath_attr(doc, './/string', 'name', 'title').text
|
||||||
thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
|
thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
|
||||||
|
|
||||||
files = data['video']['files']
|
files = data['files']
|
||||||
try:
|
capfile = get_text_attr(data, 'capfile')
|
||||||
capfile = data['video']['capfile']['#text']
|
|
||||||
except KeyError:
|
|
||||||
capfile = None
|
|
||||||
|
|
||||||
entries = [{
|
entries = []
|
||||||
|
for partnum, f in enumerate(files):
|
||||||
|
formats = []
|
||||||
|
for quality in f['qualities']:
|
||||||
|
formats.append({
|
||||||
|
'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')),
|
||||||
|
'url': unescapeHTML(get_text_attr(quality, 'file')),
|
||||||
|
'height': int_or_none(get_text_attr(quality, 'height')),
|
||||||
|
'tbr': int_or_none(get_text_attr(quality, 'bitrate')),
|
||||||
|
})
|
||||||
|
self._sort_formats(formats)
|
||||||
|
entries.append({
|
||||||
'id': '%s_%d' % (video_id, partnum + 1),
|
'id': '%s_%d' % (video_id, partnum + 1),
|
||||||
'title': (
|
'title': (
|
||||||
title if len(files) == 1 else
|
title if len(files) == 1 else
|
||||||
'%s part %d' % (title, partnum + 1)),
|
'%s part %d' % (title, partnum + 1)),
|
||||||
'url': unescapeHTML(f['path']['#text']),
|
'formats': formats,
|
||||||
'description': description,
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'duration': int_or_none(f.get('length', {}).get('#text')),
|
'duration': int_or_none(get_text_attr(f, 'length')),
|
||||||
'subtitles': {
|
'subtitles': {
|
||||||
'en': [{
|
'en': [{
|
||||||
'url': capfile,
|
'url': capfile,
|
||||||
'ext': determine_ext(capfile, 'dfxp')
|
'ext': determine_ext(capfile, 'dfxp')
|
||||||
}],
|
}],
|
||||||
} if capfile else None,
|
} if capfile else None,
|
||||||
} for partnum, f in enumerate(files)]
|
})
|
||||||
|
|
||||||
if len(entries) == 1:
|
if len(entries) == 1:
|
||||||
entry = dict(entries[0])
|
entry = dict(entries[0])
|
||||||
|
Loading…
Reference in New Issue
Block a user