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

Code before:

    def _perform_login(self, username, password):
        webpage = self._download_webpage(self._LOGIN_URL, None)
        form = self._search_regex(
            r'(?s)<form[^>]+action="/account/login"[^>]*>(.+?)</form>',
            webpage, 'login form', default=None)
        if not form:  # logged in
            return
        data = self._hidden_inputs(form)
        data.update({
            'Email': username,
            'Password': password,
        })
        loginWebpage = self._download_webpage(
            self._LOGIN_URL, None, 'Logging in', data=urlencode_postdata(data))
        # If the user has multiple profiles, select one.
        profileIds = re.findall(r'\<button .+data-profile-id="([a-zA-Z0-9]+)".*\>', loginWebpage)
        if profileIds is None:
            return # If only one profile, Hidive auto-selects it.
        profileIdHashes = re.findall(r'\<button .+data-hash="([a-zA-Z0-9]+)".*\>', loginWebpage)
        # Just pick the first profile, until someone else updates this code to
        #   support declaring a profile in a config file.
        profileId = profileIds[0]
        profileIdHash = profileIdHashes[0]
        chooseProfileResultWebpage = self._download_json(
            'https://www.hidive.com/ajax/chooseprofile', '',
            data=urlencode_postdata({
                'profileId': profileId,
                'hash': profileIdHash,
                'returnUrl': '/dashboard'
            })) or {}

    def _call_api(self, video_id, title, key, data={}, **kwargs):
        data = {
            **data,
            'Title': title,
            'Key': key,
            'PlayerId': 'f4f895ce1ca713ba263b91caeb1daa2d08904783',
        }
        return self._download_json(
            'https://www.hidive.com/play/settings', video_id,
            data=urlencode_postdata(data), **kwargs) or {}

    def _get_subtitles(self, url, video_id, title, key, parsed_urls):
        subtitles = {}
        webpage = self._download_webpage(url, video_id, fatal=False) or ''

        settings = self._call_api(video_id, title, key)
        for rendition_id, rendition in settings['renditions'].items():
            audio, version, extra = rendition_id.split('_')


Review comment (suggestion):
```suggestion
            'https://www.hidive.com/ajax/chooseprofile', None,
```

Code after:
        webpage = self._download_webpage(self._LOGIN_URL, None)
        form = self._search_regex(
            r'(?s)<form[^>]+action="/account/login"[^>]*>(.+?)</form>',
            webpage, 'login form', default=None)
        if not form:
            return
        data = self._hidden_inputs(form)
        data.update({
            'Email': username,
            'Password': password,
        })
        login_webpage = self._download_webpage(
            self._LOGIN_URL, None, 'Logging in', data=urlencode_postdata(data))
        # If the user has multiple profiles on their account, select one. For now pick the first profile.
        profile_id = self._search_regex(r'<button [^>]+?data-profile-id="(\w+)"', login_webpage, 'profile_id')
        if profile_id is None:
            return  # If only one profile, Hidive auto-selects it
        profile_id_hash = self._search_regex(r'\<button [^>]+?data-hash="(\w+)"', login_webpage, 'profile_id_hash')
        self._request_webpage(
            'https://www.hidive.com/ajax/chooseprofile', None,
            data=urlencode_postdata({
                'profileId': profile_id,
                'hash': profile_id_hash,
                'returnUrl': '/dashboard'
            }))

    def _call_api(self, video_id, title, key, data={}, **kwargs):
        data = {
            **data,
            'Title': title,
            'Key': key,
            'PlayerId': 'f4f895ce1ca713ba263b91caeb1daa2d08904783',
        }
        return self._download_json(
            'https://www.hidive.com/play/settings', video_id,
            data=urlencode_postdata(data), **kwargs) or {}

    def _real_extract(self, url):
        video_id, title, key = self._match_valid_url(url).group('id', 'title', 'key')
        settings = self._call_api(video_id, title, key)

        restriction = settings.get('restrictionReason')
        if restriction == 'RegionRestricted':
            self.raise_geo_restricted()
        if restriction and restriction != 'None':
            raise ExtractorError(
                '%s said: %s' % (self.IE_NAME, restriction), expected=True)

        formats, parsed_urls = [], {None}
        for rendition_id, rendition in settings['renditions'].items():
            audio, version, extra = rendition_id.split('_')