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

Code before:
        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):
            json_query = {
                'nTitleNo': video_id,
                'nApiLevel': 10,
            }
            video_json = self._download_json(
                "https://api.m.afreecatv.com/station/video/a/view",
                video_id, data=urlencode_postdata(json_query), headers={
                    'Referer': url,
                })
            if video_json['result'] != 1:
                continue
            video_json = video_json['data']
            station_id = video_json['station_no']
            bbs_id = video_json['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 ''),
                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. '
                    'Only content suitable for all ages will be downloaded. '
                    'Provide account credentials if you wish to download restricted content.')

Review comment (suggestion):
```suggestion
            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,
                }))
            if video_json['result'] != 1:
                continue
            station_id = video_json['data']['station_no']
            bbs_id = video_json['data']['bbs_no']
```

Code after:
        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. '
                    'Only content suitable for all ages will be downloaded. '
                    'Provide account credentials if you wish to download restricted content.')
                partial_view = True
                continue
            elif flag == 'ADULT':
                if not adult_view:
                    adult_view = True
                    continue
                error = 'Only users older than 19 are able to watch this video. Provide account credentials to download this content.'
            else:
                error = flag
            raise ExtractorError(
                '%s said: %s' % (self.IE_NAME, error), expected=True)
        else:
            raise ExtractorError('Unable to download video info')

        video_element = video_xml.findall('./track/video')[-1]