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