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

Code before:
        'url': 'https://gaismasmandalas.getcourse.io/ATLAUTSEVBUT',
        'only_matching': True,
    }]
    _DOMAINS = [
        'academymel.online',
        'marafon.mani-beauty.com',
    ]
    _BASE_URL_RE = rf'https?://(?:(?!player02\.)[^.]+\.getcourse\.(?:ru|io)|{"|".join(map(re.escape, _DOMAINS))})'
    _VALID_URL = [
        rf'{_BASE_URL_RE}/(?!pl/|teach/)(?P<id>[^?#]+)',
        rf'{_BASE_URL_RE}/(:?pl/)?teach/control/lesson/view\?(?:[^#]+&)?id=(?P<id>\d+)',
    ]

    def _login(self, hostname, username, password):
        if self._get_cookies(f'https://{hostname}').get('PHPSESSID5'):
            return
        login_url = f'https://{hostname}{self._LOGIN_URL_PATH}'

        webpage = self._download_webpage(login_url, None)
        xdget_id = self._html_search_regex(
            r'<form[^>]*class="[^"]*state-login[^"]*"[^>]*data-xdget-id="([^"]+)"',
            webpage, 'xdgetId')

        simple_sign = self._html_search_regex(
            r'window.requestSimpleSign\s*=\s*"([\da-f]+)"',
            webpage, 'simple sign')

        self._request_webpage(
            login_url, None, 'Logging in', 'Failed to log in',
            data=urlencode_postdata({
                'action': 'processXdget',
                'xdgetId': xdget_id,
                'params[action]': 'login',
                'params[url]': login_url,
                'params[object_type]': 'cms_page',
                'params[object_id]': -1,
                'params[email]': username,
                'params[password]': password,
                'requestTime': int(time.time()),
                'requestSimpleSign': simple_sign,
            }))

    def _real_extract(self, url):
        hostname = urllib.parse.urlparse(url).hostname
        username, password = self._get_login_info(netrc_machine=hostname)
        if username:
            self._login(hostname, username, password)

        display_id = self._match_id(url)
        # NB: 404 is returned due to yt-dlp not properly following redirects #9020
        webpage, urlh = self._download_webpage_handle(url, display_id, expected_status=404)

Review comment (suggestion):
```suggestion
            r'window.requestSimpleSign\s*=\s*"([\da-f]+)"', webpage, 'simple sign')
```
or even better, this could be inlined below

Code after:
                'id': '447479687',
                'ext': 'mp4',
                'title': 'Мотивация к тренировкам',
                'thumbnail': 'https://preview-htz.vhcdn.com/preview/70ed5b9f489dd03b4aff55bfdff71a26/preview.jpg?version=1685115787&host=vh-71',
                'duration': 30
            },
        }],
        'skip': 'paid lesson'
    }, {
        'url': 'https://gaismasmandalas.getcourse.io/ATLAUTSEVBUT',
        'only_matching': True,
    }]

    _LOGIN_URL_PATH = '/cms/system/login'

    def _login(self, hostname, username, password):
        if self._get_cookies(f'https://{hostname}').get('PHPSESSID5'):
            return
        login_url = f'https://{hostname}{self._LOGIN_URL_PATH}'
        webpage = self._download_webpage(login_url, None)

        self._request_webpage(
            login_url, None, 'Logging in', 'Failed to log in',
            data=urlencode_postdata({
                'action': 'processXdget',
                'xdgetId': self._html_search_regex(
                    r'<form[^>]+\bclass="[^"]*\bstate-login[^"]*"[^>]+\bdata-xdget-id="([^"]+)"',
                    webpage, 'xdgetId'),
                'params[action]': 'login',
                'params[url]': login_url,
                'params[object_type]': 'cms_page',
                'params[object_id]': -1,
                'params[email]': username,
                'params[password]': password,
                'requestTime': int(time.time()),
                'requestSimpleSign': self._html_search_regex(
                    r'window.requestSimpleSign\s*=\s*"([\da-f]+)"', webpage, 'simple sign'),
            }))

    def _real_extract(self, url):
        hostname = urllib.parse.urlparse(url).hostname
        username, password = self._get_login_info(netrc_machine=hostname)
        if username:
            self._login(hostname, username, password)

        display_id = self._match_id(url)
        # NB: 404 is returned due to yt-dlp not properly following redirects #9020
        webpage, urlh = self._download_webpage_handle(url, display_id, expected_status=404)
        if self._LOGIN_URL_PATH in urlh.url or urlh.status == 404:
            raise ExtractorError(
                f'This video is only available for registered users. {self._login_hint("any", netrc=hostname)}',