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