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

Code before:
            0: 'The username does not exist or you have entered the wrong password.',
            -1: 'The username does not exist or you have entered the wrong password.',
            -3: 'You have entered your username/password incorrectly.',
            -7: 'You cannot use your Global AfreecaTV account to access Korean AfreecaTV.',
            -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
            -32008: 'You have failed to log in. Please contact our Help Center.',
        }

        result = int_or_none(response.get('RESULT'))
        if result != 1:
            error = _ERRORS.get(result, 'You have failed to log in.')
            raise ExtractorError(
                'Unable to login: %s said: %s' % (self.IE_NAME, error),
                expected=True)

    def _real_extract(self, url):
        video_id = self._match_id(url)

        webpage = self._download_webpage(url, video_id)

        if re.search(r'alert\(["\']This video has been deleted', webpage):
            raise ExtractorError(
                'Video %s has been deleted' % video_id, expected=True)

        video_id = self._search_regex(
            r'vod.afreecatv.com/player/(\d+)/', webpage, 'title', default=video_id)

        partial_view = False
        adult_view = False
        for _ in range(2):
            video_json = self._download_json(
                "https://api.m.afreecatv.com/station/video/a/view",
                video_id, headers={'Referer': url}, data=urlencode_postdata({
                    'nTitleNo': video_id,
                    'nApiLevel': 10,
                }))
            station_id = video_json['data']['station_no']
            bbs_id = video_json['data']['bbs_no']
            query = {
                'nTitleNo': video_id,
                'nStationNo': station_id,
                'nBbsNo': bbs_id,
            }
            if partial_view:
                query['partialView'] = 'SKIP_ADULT'
            if adult_view:
                query['adultView'] = 'ADULT_VIEW'
            video_xml = self._download_xml(
                'http://afbbs.afreecatv.com:8080/api/video/get_video_info.php',
                video_id, 'Downloading video info XML%s'
                % (' (skipping adult)' if partial_view else ''),

Review comment (suggestion):
Minor regex fix...but is this `video_id = ...` even necessary though? The `video_id` is always matched from the URL, yeah? Are there any tests/examples that need this?
```suggestion
            r'vod\.afreecatv\.com/player/(\d+)/', webpage, 'title', default=video_id)
```

Code after:
            -1: 'The username does not exist or you have entered the wrong password.',
            -3: 'You have entered your username/password incorrectly.',
            -7: 'You cannot use your Global AfreecaTV account to access Korean AfreecaTV.',
            -10: 'Sorry for the inconvenience. \nYour account has been blocked due to an unauthorized access. \nPlease contact our Help Center for assistance.',
            -32008: 'You have failed to log in. Please contact our Help Center.',
        }

        result = int_or_none(response.get('RESULT'))
        if result != 1:
            error = _ERRORS.get(result, 'You have failed to log in.')
            raise ExtractorError(
                'Unable to login: %s said: %s' % (self.IE_NAME, error),
                expected=True)

    def _real_extract(self, url):
        video_id = self._match_id(url)

        partial_view = False
        adult_view = False
        for _ in range(2):
            data = self._download_json(
                'https://api.m.afreecatv.com/station/video/a/view',
                video_id, headers={'Referer': url}, data=urlencode_postdata({
                    'nTitleNo': video_id,
                    'nApiLevel': 10,
                }))['data']
            if traverse_obj(data, ('code', {int})) == -6221:
                raise ExtractorError('The VOD does not exist', expected=True)
            query = {
                'nTitleNo': video_id,
                'nStationNo': data['station_no'],
                'nBbsNo': data['bbs_no'],
            }
            if partial_view:
                query['partialView'] = 'SKIP_ADULT'
            if adult_view:
                query['adultView'] = 'ADULT_VIEW'
            video_xml = self._download_xml(
                'http://afbbs.afreecatv.com:8080/api/video/get_video_info.php',
                video_id, 'Downloading video info XML%s'
                % (' (skipping adult)' if partial_view else ''),
                video_id, headers={
                    'Referer': url,
                }, query=query)

            flag = xpath_text(video_xml, './track/flag', 'flag', default=None)
            if flag and flag == 'SUCCEED':
                break
            if flag == 'PARTIAL_ADULT':
                self.report_warning(
                    'In accordance with local laws and regulations, underage users are restricted from watching adult content. '