Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/senategov.py (Python)

Code before:
        },
        'params': {
            # 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': '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',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        url, smuggled_data = unsmuggle_url(url, {})

        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)
        filename = qs['filename'][0]
        video_id = remove_end(filename, '.mp4')

        webpage = self._download_webpage(url, video_id)

        if smuggled_data.get('force_title'):
            title = smuggled_data['force_title']
        else:
            title = self._html_extract_title(webpage)
        poster = qs.get('poster')
        thumbnail = poster[0] if poster else None

        committee = qs['comm'][0]

        return {
            'id': video_id,
            'title': title,
            'formats': self._extract_formats(committee, filename, video_id),
            'thumbnail': thumbnail,
        }


class SenateGovIE(SenateBaseIE):
    _IE_NAME = 'senate.gov'

Review comment (bug):
Suggestion #`2` to remove `qs.get('type')`. `type` is not used anywhere in the function and fails isvp urls such as `https://www.senate.gov/isvp/?auto_play=false&comm=help&filename=help090920&poster=https://www.help.senate.gov/assets/images/video-poster.png&stt=950`.

Code after:
        '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 _real_extract(self, url):
        qs = urllib.parse.parse_qs(self._match_valid_url(url).group('qs'))
        if not qs.get('filename') or not qs.get('comm'):
            raise ExtractorError('Invalid URL', expected=True)
        filename = qs['filename'][0]
        video_id = remove_end(filename, '.mp4')

        webpage = self._download_webpage(url, video_id)
        committee = qs['comm'][0]

        stream_num, stream_domain, stream_id, msl3 = self._COMMITTEES[committee]

        urls_alternatives = [f'https://www-senate-gov-media-srs.akamaized.net/hls/live/{stream_id}/{committee}/{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']
        formats = []
        subtitles = {}
        for video_url in urls_alternatives:
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(video_url, video_id, ext='mp4', fatal=False)
            if formats:
                break

        return {
            'id': video_id,
            'title': self._html_extract_title(webpage),
            'formats': formats,
            'subtitles': subtitles,
            'thumbnail': traverse_obj(qs, ('poster', 0, {url_or_none})),
            '_old_archive_ids': [make_archive_id(SenateGovIE, video_id)],
        }