From 6b883f9d8c726723873880f5eb578ca17afd9d2d Mon Sep 17 00:00:00 2001 From: sepro Date: Wed, 15 Jan 2025 19:20:03 +0100 Subject: [PATCH] Fix SenateISVPIE --- yt_dlp/extractor/senategov.py | 148 ++++++++++++++++------------------ 1 file changed, 70 insertions(+), 78 deletions(-) diff --git a/yt_dlp/extractor/senategov.py b/yt_dlp/extractor/senategov.py index 5b5d991664..2a4466a97b 100644 --- a/yt_dlp/extractor/senategov.py +++ b/yt_dlp/extractor/senategov.py @@ -5,45 +5,61 @@ from .common import InfoExtractor from ..utils import ( ExtractorError, parse_qs, + remove_end, unsmuggle_url, ) -_COMMITTEES = { - 'ag': ('76440', 'https://ag-f.akamaihd.net', '2036803', 'agriculture'), - 'aging': ('76442', 'https://aging-f.akamaihd.net', '2036801', 'aging'), - 'approps': ('76441', 'https://approps-f.akamaihd.net', '2036802', 'appropriations'), - 'arch': ('', 'https://ussenate-f.akamaihd.net/', '', 'arch'), - 'armed': ('76445', 'https://armed-f.akamaihd.net', '2036800', 'armedservices'), - 'banking': ('76446', 'https://banking-f.akamaihd.net', '2036799', 'banking'), - 'budget': ('76447', 'https://budget-f.akamaihd.net', '2036798', 'budget'), - 'cecc': ('76486', 'https://srs-f.akamaihd.net', '2036782', 'srs_cecc'), - 'commerce': ('80177', 'https://commerce1-f.akamaihd.net', '2036779', 'commerce'), - 'csce': ('75229', 'https://srs-f.akamaihd.net', '2036777', 'srs_srs'), - 'dpc': ('76590', 'https://dpc-f.akamaihd.net', '', 'dpc'), - 'energy': ('76448', 'https://energy-f.akamaihd.net', '2036797', 'energy'), - 'epw': ('76478', 'https://epw-f.akamaihd.net', '2036783', 'environment'), - 'ethics': ('76449', 'https://ethics-f.akamaihd.net', '2036796', 'ethics'), - 'finance': ('76450', 'https://finance-f.akamaihd.net', '2036795', 'finance_finance'), - 'foreign': ('76451', 'https://foreign-f.akamaihd.net', '2036794', 'foreignrelations'), - 'govtaff': ('76453', 'https://govtaff-f.akamaihd.net', '2036792', 'hsgac'), - 'help': ('76452', 'https://help-f.akamaihd.net', '2036793', 'help'), - 'indian': ('76455', 'https://indian-f.akamaihd.net', '2036791', 'indianaffairs'), - 'intel': ('76456', 'https://intel-f.akamaihd.net', '2036790', 'intelligence'), - 'intlnarc': ('76457', 'https://intlnarc-f.akamaihd.net', '', 'internationalnarcoticscaucus'), - 'jccic': ('85180', 'https://jccic-f.akamaihd.net', '2036778', 'jccic'), - 'jec': ('76458', 'https://jec-f.akamaihd.net', '2036789', 'jointeconomic'), - 'judiciary': ('76459', 'https://judiciary-f.akamaihd.net', '2036788', 'judiciary'), - 'rpc': ('76591', 'https://rpc-f.akamaihd.net', '', 'rpc'), - 'rules': ('76460', 'https://rules-f.akamaihd.net', '2036787', 'rules'), - 'saa': ('76489', 'https://srs-f.akamaihd.net', '2036780', 'srs_saa'), - 'smbiz': ('76461', 'https://smbiz-f.akamaihd.net', '2036786', 'smallbusiness'), - 'srs': ('75229', 'https://srs-f.akamaihd.net', '2031966', 'srs_srs'), - 'uscc': ('76487', 'https://srs-f.akamaihd.net', '2036781', 'srs_uscc'), - 'vetaff': ('76462', 'https://vetaff-f.akamaihd.net', '2036785', 'veteransaffairs'), -} + +class SenateBaseIE(InfoExtractor): + _COMMITTEES = { + 'ag': ('76440', 'https://ag-f.akamaihd.net', '2036803', 'agriculture'), + 'aging': ('76442', 'https://aging-f.akamaihd.net', '2036801', 'aging'), + 'approps': ('76441', 'https://approps-f.akamaihd.net', '2036802', 'appropriations'), + 'arch': ('', 'https://ussenate-f.akamaihd.net/', '', 'arch'), + 'armed': ('76445', 'https://armed-f.akamaihd.net', '2036800', 'armedservices'), + 'banking': ('76446', 'https://banking-f.akamaihd.net', '2036799', 'banking'), + 'budget': ('76447', 'https://budget-f.akamaihd.net', '2036798', 'budget'), + 'cecc': ('76486', 'https://srs-f.akamaihd.net', '2036782', 'srs_cecc'), + 'commerce': ('80177', 'https://commerce1-f.akamaihd.net', '2036779', 'commerce'), + 'csce': ('75229', 'https://srs-f.akamaihd.net', '2036777', 'srs_srs'), + 'dpc': ('76590', 'https://dpc-f.akamaihd.net', '', 'dpc'), + 'energy': ('76448', 'https://energy-f.akamaihd.net', '2036797', 'energy'), + 'epw': ('76478', 'https://epw-f.akamaihd.net', '2036783', 'environment'), + 'ethics': ('76449', 'https://ethics-f.akamaihd.net', '2036796', 'ethics'), + 'finance': ('76450', 'https://finance-f.akamaihd.net', '2036795', 'finance_finance'), + 'foreign': ('76451', 'https://foreign-f.akamaihd.net', '2036794', 'foreignrelations'), + 'govtaff': ('76453', 'https://govtaff-f.akamaihd.net', '2036792', 'hsgac'), + 'help': ('76452', 'https://help-f.akamaihd.net', '2036793', 'help'), + 'indian': ('76455', 'https://indian-f.akamaihd.net', '2036791', 'indianaffairs'), + 'intel': ('76456', 'https://intel-f.akamaihd.net', '2036790', 'intelligence'), + 'intlnarc': ('76457', 'https://intlnarc-f.akamaihd.net', '', 'internationalnarcoticscaucus'), + 'jccic': ('85180', 'https://jccic-f.akamaihd.net', '2036778', 'jccic'), + 'jec': ('76458', 'https://jec-f.akamaihd.net', '2036789', 'jointeconomic'), + 'judiciary': ('76459', 'https://judiciary-f.akamaihd.net', '2036788', 'judiciary'), + 'rpc': ('76591', 'https://rpc-f.akamaihd.net', '', 'rpc'), + 'rules': ('76460', 'https://rules-f.akamaihd.net', '2036787', 'rules'), + 'saa': ('76489', 'https://srs-f.akamaihd.net', '2036780', 'srs_saa'), + 'smbiz': ('76461', 'https://smbiz-f.akamaihd.net', '2036786', 'smallbusiness'), + 'srs': ('75229', 'https://srs-f.akamaihd.net', '2031966', 'srs_srs'), + 'uscc': ('76487', 'https://srs-f.akamaihd.net', '2036781', 'srs_uscc'), + 'vetaff': ('76462', 'https://vetaff-f.akamaihd.net', '2036785', 'veteransaffairs'), + } + + def _extract_formats(self, commitee, filename, video_id): + stream_num, stream_domain, stream_id, msl3 = self._COMMITTEES[commitee] + + urls_alternatives = [f'https://www-senate-gov-media-srs.akamaized.net/hls/live/{stream_id}/{commitee}/{filename}/master.m3u8', + f'https://www-senate-gov-msl3archive.akamaized.net/{msl3}/{filename}_1/master.m3u8', + f'{stream_domain}/i/{filename}_1@{stream_num}/master.m3u8', + f'{stream_domain}/i/{filename}.mp4/master.m3u8'] + for video_url in urls_alternatives: + formats = self._extract_m3u8_formats(video_url, video_id, ext='mp4', fatal=False) + if formats: + break + return formats -class SenateISVPIE(InfoExtractor): +class SenateISVPIE(SenateBaseIE): _IE_NAME = 'senate.gov:isvp' _VALID_URL = r'https?://(?:www\.)?senate\.gov/isvp/?\?(?P.+)' _EMBED_REGEX = [r"]+src=['\"](?Phttps?://www\.senate\.gov/isvp/?\?[^'\"]+)['\"]"] @@ -53,13 +69,14 @@ class SenateISVPIE(InfoExtractor): 'info_dict': { 'id': 'judiciary031715', 'ext': 'mp4', - 'title': 'Integrated Senate Video Player', + 'title': 'ISVP', 'thumbnail': r're:^https?://.*\.(?:jpg|png)$', }, 'params': { # m3u8 download 'skip_download': True, }, + 'expected_warnings': ['Failed to download m3u8 information'], }, { 'url': 'http://www.senate.gov/isvp/?type=live&comm=commerce&filename=commerce011514.mp4&auto_play=false', 'info_dict': { @@ -71,14 +88,16 @@ class SenateISVPIE(InfoExtractor): # m3u8 download 'skip_download': True, }, + 'skip': 'This video is not available.', }, { 'url': 'http://www.senate.gov/isvp/?type=arch&comm=intel&filename=intel090613&hc_location=ufi', # checksum differs each time 'info_dict': { 'id': 'intel090613', 'ext': 'mp4', - 'title': 'Integrated Senate Video Player', + 'title': 'ISVP', }, + 'expected_warnings': ['Failed to download m3u8 information'], }, { # From http://www.c-span.org/video/?96791-1 'url': 'http://www.senate.gov/isvp?type=live&comm=banking&filename=banking012715', @@ -91,8 +110,8 @@ class SenateISVPIE(InfoExtractor): qs = urllib.parse.parse_qs(self._match_valid_url(url).group('qs')) if not qs.get('filename') or not qs.get('type') or not qs.get('comm'): raise ExtractorError('Invalid URL', expected=True) - - video_id = re.sub(r'.mp4$', '', qs['filename'][0]) + filename = qs['filename'][0] + video_id = remove_end(filename, '.mp4') webpage = self._download_webpage(url, video_id) @@ -103,40 +122,17 @@ class SenateISVPIE(InfoExtractor): poster = qs.get('poster') thumbnail = poster[0] if poster else None - video_type = qs['type'][0] - committee = video_type if video_type == 'arch' else qs['comm'][0] - - stream_num, domain = _COMMITTEES[committee] - - formats = [] - if video_type == 'arch': - filename = video_id if '.' in video_id else video_id + '.mp4' - m3u8_url = urllib.parse.urljoin(domain, 'i/' + filename + '/master.m3u8') - formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', m3u8_id='m3u8') - else: - hdcore_sign = 'hdcore=3.1.0' - url_params = (domain, video_id, stream_num) - f4m_url = f'%s/z/%s_1@%s/manifest.f4m?{hdcore_sign}' % url_params - m3u8_url = '{}/i/{}_1@{}/master.m3u8'.format(*url_params) - for entry in self._extract_f4m_formats(f4m_url, video_id, f4m_id='f4m'): - # URLs without the extra param induce an 404 error - entry.update({'extra_param_to_segment_url': hdcore_sign}) - formats.append(entry) - for entry in self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', m3u8_id='m3u8'): - mobj = re.search(r'(?P(?:-p|-b)).m3u8', entry['url']) - if mobj: - entry['format_id'] += mobj.group('tag') - formats.append(entry) + committee = qs['comm'][0] return { 'id': video_id, 'title': title, - 'formats': formats, + 'formats': self._extract_formats(committee, filename, video_id), 'thumbnail': thumbnail, } -class SenateGovIE(InfoExtractor): +class SenateGovIE(SenateBaseIE): _IE_NAME = 'senate.gov' _VALID_URL = r'https?:\/\/(?:www\.)?(help|appropriations|judiciary|banking|armed-services|finance)\.senate\.gov' _TESTS = [{ @@ -147,6 +143,8 @@ class SenateGovIE(InfoExtractor): 'title': 'Vaccines: Saving Lives, Ensuring Confidence, and Protecting Public Health', 'description': 'The U.S. Senate Committee on Health, Education, Labor & Pensions', 'ext': 'mp4', + 'age_limit': 0, + 'thumbnail': 'https://www.help.senate.gov/assets/images/sharelogo.jpg', }, 'params': {'skip_download': 'm3u8'}, }, { @@ -156,8 +154,10 @@ class SenateGovIE(InfoExtractor): 'display_id': 'watch?hearingid=B8A25434-5056-A066-6020-1F68CB75F0CD', 'title': 'Review of the FY2019 Budget Request for the U.S. Army', 'ext': 'mp4', + 'age_limit': 0, }, 'params': {'skip_download': 'm3u8'}, + 'expected_warnings': ['Failed to download m3u8 information'], }, { 'url': 'https://www.banking.senate.gov/hearings/21st-century-communities-public-transportation-infrastructure-investment-and-fast-act-reauthorization', 'info_dict': { @@ -166,6 +166,8 @@ class SenateGovIE(InfoExtractor): 'title': '21st Century Communities: Public Transportation Infrastructure Investment and FAST Act Reauthorization', 'description': 'The Official website of The United States Committee on Banking, Housing, and Urban Affairs', 'ext': 'mp4', + 'thumbnail': 'https://www.banking.senate.gov/themes/banking/images/sharelogo.jpg', + 'age_limit': 0, }, 'params': {'skip_download': 'm3u8'}, }] @@ -178,28 +180,18 @@ class SenateGovIE(InfoExtractor): r'