]>
Commit | Line | Data |
---|---|---|
ca9e7922 PH |
1 | from __future__ import unicode_literals |
2 | ||
aa0c8739 JMF |
3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
672f1bd8 | 7 | determine_ext, |
355c7ad3 | 8 | ExtractorError, |
5996d21a | 9 | extract_attributes, |
7e810109 RA |
10 | find_xpath_attr, |
11 | get_element_by_class, | |
12 | int_or_none, | |
29f7c58a | 13 | js_to_json, |
14 | merge_dicts, | |
7e810109 RA |
15 | smuggle_url, |
16 | unescapeHTML, | |
aa0c8739 | 17 | ) |
2fe1b5bd | 18 | from .senateisvp import SenateISVPIE |
4447fb23 | 19 | from .ustream import UstreamIE |
aa0c8739 | 20 | |
ca9e7922 | 21 | |
aa0c8739 | 22 | class CSpanIE(InfoExtractor): |
5886b38d | 23 | _VALID_URL = r'https?://(?:www\.)?c-span\.org/video/\?(?P<id>[0-9a-f]+)' |
ca9e7922 | 24 | IE_DESC = 'C-SPAN' |
11a15be4 | 25 | _TESTS = [{ |
009a3408 | 26 | 'url': 'http://www.c-span.org/video/?313572-1/HolderonV', |
355c7ad3 | 27 | 'md5': '94b29a4f131ff03d23471dd6f60b6a1d', |
ca9e7922 | 28 | 'info_dict': { |
009a3408 | 29 | 'id': '315139', |
ca9e7922 | 30 | 'title': 'Attorney General Eric Holder on Voting Rights Act Decision', |
6f5ac90c | 31 | }, |
f3c21cb7 | 32 | 'playlist_mincount': 2, |
11577ec0 | 33 | 'skip': 'Regularly fails on travis, for unknown reasons', |
11a15be4 PH |
34 | }, { |
35 | 'url': 'http://www.c-span.org/video/?c4486943/cspan-international-health-care-models', | |
f3c21cb7 | 36 | # md5 is unstable |
11a15be4 | 37 | 'info_dict': { |
30787f72 | 38 | 'id': 'c4486943', |
11a15be4 | 39 | 'ext': 'mp4', |
30787f72 | 40 | 'title': 'CSPAN - International Health Care Models', |
11a15be4 PH |
41 | 'description': 'md5:7a985a2d595dba00af3d9c9f0783c967', |
42 | } | |
22a6f150 PH |
43 | }, { |
44 | 'url': 'http://www.c-span.org/video/?318608-1/gm-ignition-switch-recall', | |
45 | 'info_dict': { | |
46 | 'id': '342759', | |
47 | 'title': 'General Motors Ignition Switch Recall', | |
48 | }, | |
f3c21cb7 | 49 | 'playlist_mincount': 6, |
2fe1b5bd YCH |
50 | }, { |
51 | # Video from senate.gov | |
52 | 'url': 'http://www.c-span.org/video/?104517-1/immigration-reforms-needed-protect-skilled-american-workers', | |
2fe1b5bd YCH |
53 | 'info_dict': { |
54 | 'id': 'judiciary031715', | |
7b0d333a | 55 | 'ext': 'mp4', |
2fe1b5bd | 56 | 'title': 'Immigration Reforms Needed to Protect Skilled American Workers', |
7b0d333a NP |
57 | }, |
58 | 'params': { | |
59 | 'skip_download': True, # m3u8 downloads | |
2fe1b5bd | 60 | } |
4447fb23 YCH |
61 | }, { |
62 | # Ustream embedded video | |
63 | 'url': 'https://www.c-span.org/video/?114917-1/armed-services', | |
64 | 'info_dict': { | |
65 | 'id': '58428542', | |
66 | 'ext': 'flv', | |
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', | |
73 | }, | |
7e810109 RA |
74 | }, { |
75 | # Audio Only | |
76 | 'url': 'https://www.c-span.org/video/?437336-1/judiciary-antitrust-competition-policy-consumer-rights', | |
77 | 'only_matching': True, | |
11a15be4 | 78 | }] |
5996d21a | 79 | BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_%s/index.html?videoId=%s' |
aa0c8739 JMF |
80 | |
81 | def _real_extract(self, url): | |
30787f72 | 82 | video_id = self._match_id(url) |
04e24906 | 83 | video_type = None |
30787f72 | 84 | webpage = self._download_webpage(url, video_id) |
4447fb23 YCH |
85 | |
86 | ustream_url = UstreamIE._extract_url(webpage) | |
87 | if ustream_url: | |
88 | return self.url_result(ustream_url, UstreamIE.ie_key()) | |
89 | ||
5996d21a RA |
90 | if '&vod' not in url: |
91 | bc = self._search_regex( | |
92 | r"(<[^>]+id='brightcove-player-embed'[^>]+>)", | |
93 | webpage, 'brightcove embed', default=None) | |
94 | if bc: | |
95 | bc_attr = extract_attributes(bc) | |
96 | bc_url = self.BRIGHTCOVE_URL_TEMPLATE % ( | |
97 | bc_attr.get('data-bcaccountid', '3162030207001'), | |
98 | bc_attr.get('data-noprebcplayerid', 'SyGGpuJy3g'), | |
99 | bc_attr.get('data-newbcplayerid', 'default'), | |
100 | bc_attr['data-bcid']) | |
101 | return self.url_result(smuggle_url(bc_url, {'source_url': url})) | |
102 | ||
29f7c58a | 103 | def add_referer(formats): |
104 | for f in formats: | |
105 | f.setdefault('http_headers', {})['Referer'] = url | |
106 | ||
107 | # As of 01.12.2020 this path looks to cover all cases making the rest | |
108 | # of the code unnecessary | |
109 | jwsetup = self._parse_json( | |
110 | self._search_regex( | |
111 | r'(?s)jwsetup\s*=\s*({.+?})\s*;', webpage, 'jwsetup', | |
112 | default='{}'), | |
113 | video_id, transform_source=js_to_json, fatal=False) | |
114 | if jwsetup: | |
115 | info = self._parse_jwplayer_data( | |
116 | jwsetup, video_id, require_title=False, m3u8_id='hls', | |
117 | base_url=url) | |
118 | add_referer(info['formats']) | |
119 | ld_info = self._search_json_ld(webpage, video_id, default={}) | |
120 | return merge_dicts(info, ld_info) | |
121 | ||
122 | # Obsolete | |
6c6b8bd5 JMF |
123 | # We first look for clipid, because clipprog always appears before |
124 | patterns = [r'id=\'clip(%s)\'\s*value=\'([0-9]+)\'' % t for t in ('id', 'prog')] | |
125 | results = list(filter(None, (re.search(p, webpage) for p in patterns))) | |
126 | if results: | |
127 | matches = results[0] | |
30787f72 | 128 | video_type, video_id = matches.groups() |
6c6b8bd5 | 129 | video_type = 'clip' if video_type == 'id' else 'program' |
30787f72 | 130 | else: |
f6932135 S |
131 | m = re.search(r'data-(?P<type>clip|prog)id=["\'](?P<id>\d+)', webpage) |
132 | if m: | |
133 | video_id = m.group('id') | |
134 | video_type = 'program' if m.group('type') == 'prog' else 'clip' | |
135 | else: | |
136 | senate_isvp_url = SenateISVPIE._search_iframe_url(webpage) | |
137 | if senate_isvp_url: | |
138 | title = self._og_search_title(webpage) | |
139 | surl = smuggle_url(senate_isvp_url, {'force_title': title}) | |
140 | return self.url_result(surl, 'SenateISVP', video_id, title) | |
7e810109 RA |
141 | video_id = self._search_regex( |
142 | r'jwsetup\.clipprog\s*=\s*(\d+);', | |
143 | webpage, 'jwsetup program id', default=None) | |
144 | if video_id: | |
145 | video_type = 'program' | |
04e24906 | 146 | if video_type is None or video_id is None: |
7e810109 RA |
147 | error_message = get_element_by_class('VLplayer-error-message', webpage) |
148 | if error_message: | |
149 | raise ExtractorError(error_message) | |
04e24906 | 150 | raise ExtractorError('unable to find video id and type') |
ca9e7922 | 151 | |
2a776f97 | 152 | def get_text_attr(d, attr): |
153 | return d.get(attr, {}).get('#text') | |
154 | ||
30787f72 | 155 | data = self._download_json( |
355c7ad3 | 156 | 'http://www.c-span.org/assets/player/ajax-player.php?os=android&html5=%s&id=%s' % (video_type, video_id), |
157 | video_id)['video'] | |
158 | if data['@status'] != 'Success': | |
2a776f97 | 159 | raise ExtractorError('%s said: %s' % (self.IE_NAME, get_text_attr(data, 'error')), expected=True) |
ca9e7922 | 160 | |
aea6e7fc | 161 | doc = self._download_xml( |
30787f72 | 162 | 'http://www.c-span.org/common/services/flashXml.php?%sid=%s' % (video_type, video_id), |
009a3408 JMF |
163 | video_id) |
164 | ||
30787f72 | 165 | description = self._html_search_meta('description', webpage) |
166 | ||
aea6e7fc PH |
167 | title = find_xpath_attr(doc, './/string', 'name', 'title').text |
168 | thumbnail = find_xpath_attr(doc, './/string', 'name', 'poster').text | |
169 | ||
355c7ad3 | 170 | files = data['files'] |
2a776f97 | 171 | capfile = get_text_attr(data, 'capfile') |
aea6e7fc | 172 | |
355c7ad3 | 173 | entries = [] |
174 | for partnum, f in enumerate(files): | |
175 | formats = [] | |
7e810109 | 176 | for quality in f.get('qualities', []): |
355c7ad3 | 177 | formats.append({ |
2a776f97 | 178 | 'format_id': '%s-%sp' % (get_text_attr(quality, 'bitrate'), get_text_attr(quality, 'height')), |
179 | 'url': unescapeHTML(get_text_attr(quality, 'file')), | |
180 | 'height': int_or_none(get_text_attr(quality, 'height')), | |
181 | 'tbr': int_or_none(get_text_attr(quality, 'bitrate')), | |
355c7ad3 | 182 | }) |
af9c2a07 | 183 | if not formats: |
68a0ea15 | 184 | path = unescapeHTML(get_text_attr(f, 'path')) |
af9c2a07 S |
185 | if not path: |
186 | continue | |
187 | formats = self._extract_m3u8_formats( | |
188 | path, video_id, 'mp4', entry_protocol='m3u8_native', | |
189 | m3u8_id='hls') if determine_ext(path) == 'm3u8' else [{'url': path, }] | |
29f7c58a | 190 | add_referer(formats) |
355c7ad3 | 191 | self._sort_formats(formats) |
192 | entries.append({ | |
193 | 'id': '%s_%d' % (video_id, partnum + 1), | |
194 | 'title': ( | |
195 | title if len(files) == 1 else | |
196 | '%s part %d' % (title, partnum + 1)), | |
197 | 'formats': formats, | |
198 | 'description': description, | |
199 | 'thumbnail': thumbnail, | |
2a776f97 | 200 | 'duration': int_or_none(get_text_attr(f, 'length')), |
355c7ad3 | 201 | 'subtitles': { |
202 | 'en': [{ | |
203 | 'url': capfile, | |
204 | 'ext': determine_ext(capfile, 'dfxp') | |
205 | }], | |
206 | } if capfile else None, | |
207 | }) | |
009a3408 | 208 | |
92dcba1e YCH |
209 | if len(entries) == 1: |
210 | entry = dict(entries[0]) | |
30787f72 | 211 | entry['id'] = 'c' + video_id if video_type == 'clip' else video_id |
92dcba1e YCH |
212 | return entry |
213 | else: | |
214 | return { | |
215 | '_type': 'playlist', | |
216 | 'entries': entries, | |
217 | 'title': title, | |
30787f72 | 218 | 'id': 'c' + video_id if video_type == 'clip' else video_id, |
92dcba1e | 219 | } |