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