]>
Commit | Line | Data |
---|---|---|
909b0d66 G |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..compat import ( | |
5 | compat_parse_qs, | |
6 | compat_urlparse, | |
7 | ) | |
8 | from ..utils import ( | |
9 | ExtractorError, | |
10 | parse_qs, | |
11 | unsmuggle_url, | |
12 | ) | |
13 | ||
14 | _COMMITTEES = { | |
15 | 'ag': ('76440', 'http://ag-f.akamaihd.net'), | |
16 | 'aging': ('76442', 'http://aging-f.akamaihd.net'), | |
17 | 'approps': ('76441', 'http://approps-f.akamaihd.net'), | |
18 | 'arch': ('', 'http://ussenate-f.akamaihd.net'), | |
19 | 'armed': ('76445', 'http://armed-f.akamaihd.net'), | |
20 | 'banking': ('76446', 'http://banking-f.akamaihd.net'), | |
21 | 'budget': ('76447', 'http://budget-f.akamaihd.net'), | |
22 | 'cecc': ('76486', 'http://srs-f.akamaihd.net'), | |
23 | 'commerce': ('80177', 'http://commerce1-f.akamaihd.net'), | |
24 | 'csce': ('75229', 'http://srs-f.akamaihd.net'), | |
25 | 'dpc': ('76590', 'http://dpc-f.akamaihd.net'), | |
26 | 'energy': ('76448', 'http://energy-f.akamaihd.net'), | |
27 | 'epw': ('76478', 'http://epw-f.akamaihd.net'), | |
28 | 'ethics': ('76449', 'http://ethics-f.akamaihd.net'), | |
29 | 'finance': ('76450', 'http://finance-f.akamaihd.net'), | |
30 | 'foreign': ('76451', 'http://foreign-f.akamaihd.net'), | |
31 | 'govtaff': ('76453', 'http://govtaff-f.akamaihd.net'), | |
32 | 'help': ('76452', 'http://help-f.akamaihd.net'), | |
33 | 'indian': ('76455', 'http://indian-f.akamaihd.net'), | |
34 | 'intel': ('76456', 'http://intel-f.akamaihd.net'), | |
35 | 'intlnarc': ('76457', 'http://intlnarc-f.akamaihd.net'), | |
36 | 'jccic': ('85180', 'http://jccic-f.akamaihd.net'), | |
37 | 'jec': ('76458', 'http://jec-f.akamaihd.net'), | |
38 | 'judiciary': ('76459', 'http://judiciary-f.akamaihd.net'), | |
39 | 'rpc': ('76591', 'http://rpc-f.akamaihd.net'), | |
40 | 'rules': ('76460', 'http://rules-f.akamaihd.net'), | |
41 | 'saa': ('76489', 'http://srs-f.akamaihd.net'), | |
42 | 'smbiz': ('76461', 'http://smbiz-f.akamaihd.net'), | |
43 | 'srs': ('75229', 'http://srs-f.akamaihd.net'), | |
44 | 'uscc': ('76487', 'http://srs-f.akamaihd.net'), | |
45 | 'vetaff': ('76462', 'http://vetaff-f.akamaihd.net'), | |
46 | } | |
47 | ||
48 | ||
49 | class SenateISVPIE(InfoExtractor): | |
50 | _IE_NAME = 'senate.gov:isvp' | |
51 | _VALID_URL = r'https?://(?:www\.)?senate\.gov/isvp/?\?(?P<qs>.+)' | |
52 | ||
53 | _TESTS = [{ | |
54 | 'url': 'http://www.senate.gov/isvp/?comm=judiciary&type=live&stt=&filename=judiciary031715&auto_play=false&wmode=transparent&poster=http%3A%2F%2Fwww.judiciary.senate.gov%2Fthemes%2Fjudiciary%2Fimages%2Fvideo-poster-flash-fit.png', | |
55 | 'info_dict': { | |
56 | 'id': 'judiciary031715', | |
57 | 'ext': 'mp4', | |
58 | 'title': 'Integrated Senate Video Player', | |
59 | 'thumbnail': r're:^https?://.*\.(?:jpg|png)$', | |
60 | }, | |
61 | 'params': { | |
62 | # m3u8 download | |
63 | 'skip_download': True, | |
64 | }, | |
65 | }, { | |
66 | 'url': 'http://www.senate.gov/isvp/?type=live&comm=commerce&filename=commerce011514.mp4&auto_play=false', | |
67 | 'info_dict': { | |
68 | 'id': 'commerce011514', | |
69 | 'ext': 'mp4', | |
70 | 'title': 'Integrated Senate Video Player' | |
71 | }, | |
72 | 'params': { | |
73 | # m3u8 download | |
74 | 'skip_download': True, | |
75 | }, | |
76 | }, { | |
77 | 'url': 'http://www.senate.gov/isvp/?type=arch&comm=intel&filename=intel090613&hc_location=ufi', | |
78 | # checksum differs each time | |
79 | 'info_dict': { | |
80 | 'id': 'intel090613', | |
81 | 'ext': 'mp4', | |
82 | 'title': 'Integrated Senate Video Player' | |
83 | } | |
84 | }, { | |
85 | # From http://www.c-span.org/video/?96791-1 | |
86 | 'url': 'http://www.senate.gov/isvp?type=live&comm=banking&filename=banking012715', | |
87 | 'only_matching': True, | |
88 | }] | |
89 | ||
90 | @staticmethod | |
91 | def _search_iframe_url(webpage): | |
92 | mobj = re.search( | |
93 | r"<iframe[^>]+src=['\"](?P<url>https?://www\.senate\.gov/isvp/?\?[^'\"]+)['\"]", | |
94 | webpage) | |
95 | if mobj: | |
96 | return mobj.group('url') | |
97 | ||
98 | def _real_extract(self, url): | |
99 | url, smuggled_data = unsmuggle_url(url, {}) | |
100 | ||
101 | qs = compat_parse_qs(self._match_valid_url(url).group('qs')) | |
102 | if not qs.get('filename') or not qs.get('type') or not qs.get('comm'): | |
103 | raise ExtractorError('Invalid URL', expected=True) | |
104 | ||
105 | video_id = re.sub(r'.mp4$', '', qs['filename'][0]) | |
106 | ||
107 | webpage = self._download_webpage(url, video_id) | |
108 | ||
109 | if smuggled_data.get('force_title'): | |
110 | title = smuggled_data['force_title'] | |
111 | else: | |
04f3fd2c | 112 | title = self._html_extract_title(webpage) |
909b0d66 G |
113 | poster = qs.get('poster') |
114 | thumbnail = poster[0] if poster else None | |
115 | ||
116 | video_type = qs['type'][0] | |
117 | committee = video_type if video_type == 'arch' else qs['comm'][0] | |
118 | ||
119 | stream_num, domain = _COMMITTEES[committee] | |
120 | ||
121 | formats = [] | |
122 | if video_type == 'arch': | |
123 | filename = video_id if '.' in video_id else video_id + '.mp4' | |
124 | m3u8_url = compat_urlparse.urljoin(domain, 'i/' + filename + '/master.m3u8') | |
125 | formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', m3u8_id='m3u8') | |
126 | else: | |
127 | hdcore_sign = 'hdcore=3.1.0' | |
128 | url_params = (domain, video_id, stream_num) | |
129 | f4m_url = f'%s/z/%s_1@%s/manifest.f4m?{hdcore_sign}' % url_params | |
130 | m3u8_url = '%s/i/%s_1@%s/master.m3u8' % url_params | |
131 | for entry in self._extract_f4m_formats(f4m_url, video_id, f4m_id='f4m'): | |
132 | # URLs without the extra param induce an 404 error | |
133 | entry.update({'extra_param_to_segment_url': hdcore_sign}) | |
134 | formats.append(entry) | |
135 | for entry in self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', m3u8_id='m3u8'): | |
136 | mobj = re.search(r'(?P<tag>(?:-p|-b)).m3u8', entry['url']) | |
137 | if mobj: | |
138 | entry['format_id'] += mobj.group('tag') | |
139 | formats.append(entry) | |
140 | ||
141 | self._sort_formats(formats) | |
142 | ||
143 | return { | |
144 | 'id': video_id, | |
145 | 'title': title, | |
146 | 'formats': formats, | |
147 | 'thumbnail': thumbnail, | |
148 | } | |
149 | ||
150 | ||
151 | class SenateGovIE(InfoExtractor): | |
152 | _IE_NAME = 'senate.gov' | |
153 | _VALID_URL = r'https?:\/\/(?:www\.)?(help|appropriations|judiciary|banking|armed-services|finance)\.senate\.gov' | |
154 | _TESTS = [{ | |
155 | 'url': 'https://www.help.senate.gov/hearings/vaccines-saving-lives-ensuring-confidence-and-protecting-public-health', | |
156 | 'info_dict': { | |
157 | 'id': 'help090920', | |
158 | 'display_id': 'vaccines-saving-lives-ensuring-confidence-and-protecting-public-health', | |
159 | 'title': 'Vaccines: Saving Lives, Ensuring Confidence, and Protecting Public Health', | |
160 | 'description': 'The U.S. Senate Committee on Health, Education, Labor & Pensions', | |
161 | 'ext': 'mp4', | |
162 | }, | |
163 | 'params': {'skip_download': 'm3u8'}, | |
164 | }, { | |
165 | 'url': 'https://www.appropriations.senate.gov/hearings/watch?hearingid=B8A25434-5056-A066-6020-1F68CB75F0CD', | |
166 | 'info_dict': { | |
167 | 'id': 'appropsA051518', | |
168 | 'display_id': 'watch?hearingid=B8A25434-5056-A066-6020-1F68CB75F0CD', | |
169 | 'title': 'Review of the FY2019 Budget Request for the U.S. Army', | |
170 | 'ext': 'mp4', | |
171 | }, | |
172 | 'params': {'skip_download': 'm3u8'}, | |
173 | }, { | |
174 | 'url': 'https://www.banking.senate.gov/hearings/21st-century-communities-public-transportation-infrastructure-investment-and-fast-act-reauthorization', | |
175 | 'info_dict': { | |
176 | 'id': 'banking041521', | |
177 | 'display_id': '21st-century-communities-public-transportation-infrastructure-investment-and-fast-act-reauthorization', | |
178 | 'title': '21st Century Communities: Public Transportation Infrastructure Investment and FAST Act Reauthorization', | |
179 | 'description': 'The Official website of The United States Committee on Banking, Housing, and Urban Affairs', | |
180 | 'ext': 'mp4', | |
181 | }, | |
182 | 'params': {'skip_download': 'm3u8'}, | |
183 | }] | |
184 | ||
185 | def _real_extract(self, url): | |
186 | display_id = self._generic_id(url) | |
187 | webpage = self._download_webpage(url, display_id) | |
188 | parse_info = parse_qs(self._search_regex( | |
189 | r'<iframe class="[^>"]*streaminghearing[^>"]*"\s[^>]*\bsrc="([^">]*)', webpage, 'hearing URL')) | |
190 | ||
191 | stream_num, stream_domain = _COMMITTEES[parse_info['comm'][-1]] | |
192 | filename = parse_info['filename'][-1] | |
193 | ||
194 | formats = self._extract_m3u8_formats( | |
195 | f'{stream_domain}/i/{filename}_1@{stream_num}/master.m3u8', | |
196 | display_id, ext='mp4') | |
197 | self._sort_formats(formats) | |
198 | ||
199 | title = self._html_search_regex( | |
200 | (*self._og_regexes('title'), r'(?s)<title>([^<]*?)</title>'), webpage, 'video title') | |
201 | ||
202 | return { | |
203 | 'id': re.sub(r'.mp4$', '', filename), | |
204 | 'display_id': display_id, | |
205 | 'title': re.sub(r'\s+', ' ', title.split('|')[0]).strip(), | |
206 | 'description': self._og_search_description(webpage, default=None), | |
207 | 'thumbnail': self._og_search_thumbnail(webpage, default=None), | |
208 | 'age_limit': self._rta_search(webpage), | |
209 | 'formats': formats | |
210 | } |