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

Code before:
        'skip': 'Requires Authentication',
    }]

    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: # already logged in, so no more actions to take.
            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. In the future, when someone has a use-case, they can update
        #    this code to support that. Maybe the user would need to declare the index number of the profile
        #    in a config file, and this part reads that config and selects the profile in the Nth position.
        #    In that case, `_search_regex` likely wouldn't work, as it selects the first match.
        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, so no more actions to take.
        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'
            })) 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, settings, url, video_id, title, key, parsed_urls):
        subtitles = {}

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


Review comment (suggestion):
```suggestion
        profile_id_hash = self._search_regex(r'<button [^>]+data-hash="(\w+)"', login_webpage, 'profile_id_hash')
```

Code after:

    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:
            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}