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',
27 'title': 'Attorney General Eric Holder on Voting Rights Act Decision',
28 'description': 'Attorney General Eric Holder speaks to reporters following the Supreme Court decision in [Shelby County v. Holder], in which the court ruled that the preclearance provisions of the Voting Rights Act could not be enforced.',
30 'skip': 'Regularly fails on travis, for unknown reasons',
32 'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models',
33 'md5': '8e5fbfabe6ad0f89f3012a7943c1287b',
37 'title': 'CSPAN - International Health Care Models',
38 'description': 'md5:7a985a2d595dba00af3d9c9f0783c967',
41 'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall',
42 'md5': '2ae5051559169baadba13fc35345ae74',
46 'title': 'General Motors Ignition Switch Recall',
48 'description': 'md5:118081aedd24bf1d3b68b3803344e7f3'
51 # Video from senate.gov
52 'url': 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers',
54 'id': 'judiciary031715',
56 'title': 'Immigration Reforms Needed to Protect Skilled American Workers',
59 'skip_download': True, # m3u8 downloads
62 # Ustream embedded video
63 'url': 'https://www.c-span.org/video/?114917-1/armed-services',
67 'title': 'USHR07 Armed Services Committee',
68 'description': 'hsas00-2118-20150204-1000et-07\n\n\nUSHR07 Armed Services Committee',
69 'timestamp': 1423060374,
70 'upload_date': '20150204',
71 'uploader': 'HouseCommittee',
72 'uploader_id': '12987475',
76 def _real_extract(self, url):
77 video_id = self._match_id(url)
79 webpage = self._download_webpage(url, video_id)
81 ustream_url = UstreamIE._extract_url(webpage)
83 return self.url_result(ustream_url, UstreamIE.ie_key())
85 # We first look for clipid, because clipprog always appears before
86 patterns = [r'id=\'clip(%s)\'\s*value=\'([0-9]+)\'' % t for t in ('id', 'prog')]
87 results = list(filter(None, (re.search(p, webpage) for p in patterns)))
90 video_type, video_id = matches.groups()
91 video_type = 'clip' if video_type == 'id' else 'program'
93 m = re.search(r'data-(?P<type>clip|prog)id=["\'](?P<id>\d+)', webpage)
95 video_id = m.group('id')
96 video_type = 'program' if m.group('type') == 'prog' else 'clip'
98 senate_isvp_url = SenateISVPIE._search_iframe_url(webpage)
100 title = self._og_search_title(webpage)
101 surl = smuggle_url(senate_isvp_url, {'force_title': title})
102 return self.url_result(surl, 'SenateISVP', video_id, title)
103 if video_type is None or video_id is None:
104 raise ExtractorError('unable to find video id and type')
106 def get_text_attr(d, attr):
107 return d.get(attr, {}).get('#text')
109 data = self._download_json(
110 'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id),
112 if data['@status'] != 'Success':
113 raise ExtractorError('%s said: %s' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True)
115 doc = self._download_xml(
116 'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id),
119 description = self._html_search_meta('description', webpage)
121 title = find_xpath_attr(doc, './/string', 'name', 'title').text
122 thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text
124 files = data['files']
125 capfile = get_text_attr(data, 'capfile')
128 for partnum, f in enumerate(files):
130 for quality in f['qualities']:
132 'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')),
133 'url': unescapeHTML(get_text_attr(quality, 'file')),
134 'height': int_or_none(get_text_attr(quality, 'height')),
135 'tbr': int_or_none(get_text_attr(quality, 'bitrate')),
138 path = unescapeHTML(get_text_attr(f, 'path'))
141 formats = self._extract_m3u8_formats(
142 path, video_id, 'mp4', entry_protocol='m3u8_native',
143 m3u8_id='hls') if determine_ext(path) == 'm3u8' else [{'url': path, }]
144 self._sort_formats(formats)
146 'id': '%s_%d' % (video_id, partnum + 1),
148 title if len(files) == 1 else
149 '%s part %d' % (title, partnum + 1)),
151 'description': description,
152 'thumbnail': thumbnail,
153 'duration': int_or_none(get_text_attr(f, 'length')),
157 'ext': determine_ext(capfile, 'dfxp')
159 } if capfile else None,
162 if len(entries) == 1:
163 entry = dict(entries[0])
164 entry['id'] = 'c' + video_id if video_type == 'clip' else video_id
171 'id': 'c' + video_id if video_type == 'clip' else video_id,