]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/cspan.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
14 from .senateisvp
import SenateISVPIE
15 from .ustream
import UstreamIE
18 class CSpanIE(InfoExtractor
):
19 _VALID_URL
= r
'https?://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)'
22 'url': 'http://www.c-span.org/video/?313572-1/HolderonV',
23 'md5': '94b29a4f131ff03d23471dd6f60b6a1d',
26 'title': 'Attorney General Eric Holder on Voting Rights Act Decision',
28 'playlist_mincount': 2,
29 'skip': 'Regularly fails on travis, for unknown reasons',
31 'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models',
36 'title': 'CSPAN - International Health Care Models',
37 'description': 'md5:7a985a2d595dba00af3d9c9f0783c967',
40 'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall',
43 'title': 'General Motors Ignition Switch Recall',
45 'playlist_mincount': 6,
47 # Video from senate.gov
48 'url': 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers',
50 'id': 'judiciary031715',
52 'title': 'Immigration Reforms Needed to Protect Skilled American Workers',
55 'skip_download': True, # m3u8 downloads
58 # Ustream embedded video
59 'url': 'https://www.c-span.org/video/?114917-1/armed-services',
63 'title': 'USHR07 Armed Services Committee',
64 'description': 'hsas00-2118-20150204-1000et-07\n\n\nUSHR07 Armed Services Committee',
65 'timestamp': 1423060374,
66 'upload_date': '20150204',
67 'uploader': 'HouseCommittee',
68 'uploader_id': '12987475',
72 def _real_extract(self
, url
):
73 video_id
= self
._match
_id
(url
)
75 webpage
= self
._download
_webpage
(url
, video_id
)
77 ustream_url
= UstreamIE
._extract
_url
(webpage
)
79 return self
.url_result(ustream_url
, UstreamIE
.ie_key())
81 # We first look for clipid, because clipprog always appears before
82 patterns
= [r
'id=\'clip(%s)\'\s
*value
=\'([0-9]+)\'' % t for t in ('id', 'prog
')]
83 results = list(filter(None, (re.search(p, webpage) for p in patterns)))
86 video_type, video_id = matches.groups()
87 video_type = 'clip
' if video_type == 'id' else 'program
'
89 m = re.search(r'data
-(?P
<type>clip|prog
)id=["\'](?P<id>\d+)', webpage)
91 video_id = m.group('id')
92 video_type = 'program' if m.group('type') == 'prog' else 'clip'
94 senate_isvp_url = SenateISVPIE._search_iframe_url(webpage)
96 title = self._og_search_title(webpage)
97 surl = smuggle_url(senate_isvp_url, {'force_title': title})
98 return self.url_result(surl, 'SenateISVP', video_id, title)
99 if video_type is None or video_id is None:
100 raise ExtractorError('unable to find video id and type')
102 def get_text_attr(d, attr):
103 return d.get(attr, {}).get('#text')
105 data = self._download_json(
106 'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id),
108 if data['@status'] != 'Success':
109 raise ExtractorError('%s said: %s' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True)
111 doc = self._download_xml(
112 'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id),
115 description = self._html_search_meta('description', webpage)
117 title = find_xpath_attr(doc, './/string', 'name', 'title').text
118 thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
120 files = data['files']
121 capfile = get_text_attr(data, 'capfile')
124 for partnum, f in enumerate(files):
126 for quality in f['qualities']:
128 'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')),
129 'url': unescapeHTML(get_text_attr(quality, 'file')),
130 'height': int_or_none(get_text_attr(quality, 'height')),
131 'tbr': int_or_none(get_text_attr(quality, 'bitrate')),
134 path = unescapeHTML(get_text_attr(f, 'path'))
137 formats = self._extract_m3u8_formats(
138 path, video_id, 'mp4', entry_protocol='m3u8_native',
139 m3u8_id='hls') if determine_ext(path) == 'm3u8' else [{'url': path, }]
140 self._sort_formats(formats)
142 'id': '%s_%d' % (video_id, partnum + 1),
144 title if len(files) == 1 else
145 '%s part %d' % (title, partnum + 1)),
147 'description': description,
148 'thumbnail': thumbnail,
149 'duration': int_or_none(get_text_attr(f, 'length')),
153 'ext': determine_ext(capfile, 'dfxp')
155 } if capfile else None,
158 if len(entries) == 1:
159 entry = dict(entries[0])
160 entry['id'] = 'c' + video_id if video_type == 'clip' else video_id
167 'id': 'c' + video_id if video_type == 'clip' else video_id,