mirror of
https://codeberg.org/polarisfm/youtube-dl.git
synced 2024-12-29 11:05:13 +00:00
[cspan] change into a function
This commit is contained in:
parent
4bf5614195
commit
2a776f9788
1 changed files with 10 additions and 10 deletions
|
@ -56,9 +56,6 @@ class CSpanIE(InfoExtractor):
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
|
||||||
def get_text_attr(self, d, attr):
|
|
||||||
return d.get(attr, {}).get('#text')
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
webpage = self._download_webpage(url, video_id)
|
webpage = self._download_webpage(url, video_id)
|
||||||
|
@ -74,11 +71,14 @@ class CSpanIE(InfoExtractor):
|
||||||
surl = smuggle_url(senate_isvp_url, {'force_title': title})
|
surl = smuggle_url(senate_isvp_url, {'force_title': title})
|
||||||
return self.url_result(surl, 'SenateISVP', video_id, title)
|
return self.url_result(surl, 'SenateISVP', video_id, title)
|
||||||
|
|
||||||
|
def get_text_attr(d, attr):
|
||||||
|
return d.get(attr, {}).get('#text')
|
||||||
|
|
||||||
data = self._download_json(
|
data = self._download_json(
|
||||||
'http://www.c-span.org/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']
|
video_id)['video']
|
||||||
if data['@status'] != 'Success':
|
if data['@status'] != 'Success':
|
||||||
raise ExtractorError('%s said: %s' % (self.IE_NAME, self.get_text_attr(data, 'error')), expected=True)
|
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),
|
||||||
|
@ -90,17 +90,17 @@ class CSpanIE(InfoExtractor):
|
||||||
thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
|
thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
|
||||||
|
|
||||||
files = data['files']
|
files = data['files']
|
||||||
capfile = self.get_text_attr(data, 'capfile')
|
capfile = get_text_attr(data, 'capfile')
|
||||||
|
|
||||||
entries = []
|
entries = []
|
||||||
for partnum, f in enumerate(files):
|
for partnum, f in enumerate(files):
|
||||||
formats = []
|
formats = []
|
||||||
for quality in f['qualities']:
|
for quality in f['qualities']:
|
||||||
formats.append({
|
formats.append({
|
||||||
'format_id': '%s-%sp' % (self.get_text_attr(quality, 'bitrate'), self.get_text_attr(quality, 'height')),
|
'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')),
|
||||||
'url': unescapeHTML(self.get_text_attr(quality, 'file')),
|
'url': unescapeHTML(get_text_attr(quality, 'file')),
|
||||||
'height': int_or_none(self.get_text_attr(quality, 'height')),
|
'height': int_or_none(get_text_attr(quality, 'height')),
|
||||||
'tbr': int_or_none(self.get_text_attr(quality, 'bitrate')),
|
'tbr': int_or_none(get_text_attr(quality, 'bitrate')),
|
||||||
})
|
})
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
entries.append({
|
entries.append({
|
||||||
|
@ -111,7 +111,7 @@ class CSpanIE(InfoExtractor):
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'description': description,
|
'description': description,
|
||||||
'thumbnail': thumbnail,
|
'thumbnail': thumbnail,
|
||||||
'duration': int_or_none(self.get_text_attr(f, 'length')),
|
'duration': int_or_none(get_text_attr(f, 'length')),
|
||||||
'subtitles': {
|
'subtitles': {
|
||||||
'en': [{
|
'en': [{
|
||||||
'url': capfile,
|
'url': capfile,
|
||||||
|
|
Loading…
Reference in a new issue