ronantakizawa/codereview-bench huggingface dataset:
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/japandiet.py (Python)

Code before:
import re

from ..utils import (
    ExtractorError,
    clean_html,
    float_or_none,
    int_or_none,
    join_nonempty,
    smuggle_url,
    traverse_obj,
    unsmuggle_url
)
from .common import InfoExtractor


class ShugiinItvBaseIE(InfoExtractor):
    @classmethod
    def _find_rooms(cls, webpage):
        return [{
            '_type': 'url',
            'id': x.group(1),
            'title': clean_html(x.group(2)).strip(),
            'url': smuggle_url(f'https://www.shugiintv.go.jp/jp/index.php?room_id={x.group(1)}', x.groups()),
            'ie_key': ShugiinItvLiveIE.ie_key(),
        } for x in re.finditer(r'<a\s+href=".+?\?room_id=(room\d+)"\s*class="play_live".+?class="s12_14">(.+?)</td>', webpage)]

    @staticmethod
    def _parse_japanese_date(text):
        if not text:
            return None
        ERA_TABLE = {
            '明治': 1868,
            '大正': 1912,
            '昭和': 1926,
            '平成': 1989,
            '令和': 2019,
        }
        ERA_RE = '|'.join(map(re.escape, ERA_TABLE.keys()))
        mobj = re.search(rf'({ERA_RE})?(\d+)年(\d+)月(\d+)日', re.sub(r'[\s\u3000]+', '', text))
        if not mobj:
            return None
        era, year, month, day = mobj.groups()
        year, month, day = map(int, (year, month, day))
        if era:
            # example input: 令和5年3月34日
            # even though each era have their end, don't check here
            year += ERA_TABLE[era]
        return '%04d%02d%02d' % (year, month, day)

    @staticmethod

Review comment (suggestion):
```suggestion
        } for x in re.finditer(r'<a\s+href="[^"]+\?room_id=(room\d+)"\s*class="play_live".+?class="s12_14">(.+?)</td>', webpage)]
```

The regex looks fragile. Though I haven't looked at the page, so not sure if there's a better way

Code after:
import re

from ..utils import (
    ExtractorError,
    clean_html,
    int_or_none,
    join_nonempty,
    parse_qs,
    smuggle_url,
    traverse_obj,
    try_call,
    unsmuggle_url
)
from .common import InfoExtractor


def _parse_japanese_date(text):
    if not text:
        return None
    ERA_TABLE = {
        '明治': 1868,
        '大正': 1912,
        '昭和': 1926,
        '平成': 1989,
        '令和': 2019,
    }
    ERA_RE = '|'.join(map(re.escape, ERA_TABLE.keys()))
    mobj = re.search(rf'({ERA_RE})?(\d+)年(\d+)月(\d+)日', re.sub(r'[\s\u3000]+', '', text))
    if not mobj:
        return None
    era, year, month, day = mobj.groups()
    year, month, day = map(int, (year, month, day))
    if era:
        # example input: 令和5年3月34日
        # even though each era have their end, don't check here
        year += ERA_TABLE[era]
    return '%04d%02d%02d' % (year, month, day)


def _parse_japanese_duration(text):
    mobj = re.search(r'(?:(\d+)日間?)?(?:(\d+)時間?)?(?:(\d+)分)?(?:(\d+)秒)?', re.sub(r'[\s\u3000]+', '', text or ''))
    if not mobj:
        return
    days, hours, mins, secs = [int_or_none(x, default=0) for x in mobj.groups()]
    return secs + mins * 60 + hours * 60 * 60 + days * 24 * 60 * 60


class ShugiinItvBaseIE(InfoExtractor):
    _INDEX_ROOMS = None
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/swearnet.py (Python)

Code before:
            })

        return subs

    def _real_extract(self, url):
        display_id, season_number, episode_number = self._match_valid_url(url).group('id', 'season_num', 'episode_num')
        webpage = self._download_webpage(url, display_id)

        external_id = self._search_regex(r'externalid\s*=\s*"([^"]+)', webpage, 'externalid')
        json_data = self._download_json(
            f'https://play.vidyard.com/player/{external_id}.json', display_id)['payload']['chapters'][0]

        formats, subtitles = self._get_formats_and_subtitle(json_data['sources'], display_id)
        self._merge_subtitles(self._get_direct_subtitle(json_data.get('captions')), target=subtitles)

        return {
            'id': str(json_data['videoId']),
            'title': json_data.get('name') or self._html_search_meta(['og:title', 'twitter:title'], webpage),
            'description': (json_data.get('description')
                            or self._html_search_meta(['og:description', 'twitter:description'])),
            'duration': int_or_none(json_data.get('seconds')),
            'formats': formats,
            'subtitles': subtitles,
            'season_number': int_or_none(season_number),
            'episode_number': int_or_none(episode_number),
            'thumbnails': [{'url': thumbnail_url} for thumbnail_url in traverse_obj(json_data, ('thumbnailUrls', ...))]
        }


Review comment (suggestion):
```suggestion
            'thumbnails': [{'url': thumbnail_url}
                           for thumbnail_url in traverse_obj(json_data, ('thumbnailUrls', ...))]
```

Code after:
        return subs

    def _real_extract(self, url):
        display_id, season_number, episode_number = self._match_valid_url(url).group('id', 'season_num', 'episode_num')
        webpage = self._download_webpage(url, display_id)

        external_id = self._search_regex(r'externalid\s*=\s*"([^"]+)', webpage, 'externalid')
        json_data = self._download_json(
            f'https://play.vidyard.com/player/{external_id}.json', display_id)['payload']['chapters'][0]

        formats, subtitles = self._get_formats_and_subtitle(json_data['sources'], display_id)
        self._merge_subtitles(self._get_direct_subtitle(json_data.get('captions')), target=subtitles)

        return {
            'id': str(json_data['videoId']),
            'title': json_data.get('name') or self._html_search_meta(['og:title', 'twitter:title'], webpage),
            'description': (json_data.get('description')
                            or self._html_search_meta(['og:description', 'twitter:description'])),
            'duration': int_or_none(json_data.get('seconds')),
            'formats': formats,
            'subtitles': subtitles,
            'season_number': int_or_none(season_number),
            'episode_number': int_or_none(episode_number),
            'thumbnails': [{'url': thumbnail_url}
                           for thumbnail_url in traverse_obj(json_data, ('thumbnailUrls', ...))]
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/epoch.py (Python)

Code before:
            'info_dict': {
                'id': 'aa9ceecd-a127-453d-a2de-7153d6fd69b6',
                'ext': 'mp4',
                'title': 'Kash Patel: A ‘6-Year-Saga’ of Government Corruption, From Russiagate to Mar-a-Lago',
            }
        },
        {
            'url': 'https://www.theepochtimes.com/dick-morris-discusses-his-book-the-return-trumps-big-2024-comeback_4819205.html',
            'info_dict': {
                'id': '9489f994-2a20-4812-b233-ac0e5c345632',
                'ext': 'mp4',
                'title': 'Dick Morris Discusses His Book ‘The Return: Trump’s Big 2024 Comeback’',
            }
        },
    ]

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

        html_ws = r'\t\n\f\r\x20'
        html_attr_val = r'(?:"[^"]*"|\'[^\']*\'|[{html_ws}]*[^"\'{html_ws}>][^{html_ws}>]*)'
        youmaker_video_id = next(id for id in self._search_regex(
            fr'[{html_ws}]data-trailer={html_attr_val}[{html_ws}]+data-id=(?:(["\'])(?P<id_quoted>[\w-]+)\1|(?P<id_unquoted>[\w-]+))',
            webpage, 'url', group=('id_quoted', 'id_unquoted'))
            if id is not None)
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            f'http://vs1.youmaker.com/assets/{youmaker_video_id}/playlist.m3u8', video_id, 'mp4', m3u8_id='hls')

        return {
            'id': youmaker_video_id,
            'formats': formats,
            'subtitles': subtitles,
            'title': self._html_extract_title(webpage)
        }


Review comment (refactor):
looks unnecessarily complicated. Why not use `extract_attributes(get_element_html_by_attribute(...)`?

Code after:
            'url': 'https://www.theepochtimes.com/kash-patel-a-6-year-saga-of-government-corruption-from-russiagate-to-mar-a-lago_4690250.html',
            'info_dict': {
                'id': 'aa9ceecd-a127-453d-a2de-7153d6fd69b6',
                'ext': 'mp4',
                'title': 'Kash Patel: A ‘6-Year-Saga’ of Government Corruption, From Russiagate to Mar-a-Lago',
            }
        },
        {
            'url': 'https://www.theepochtimes.com/dick-morris-discusses-his-book-the-return-trumps-big-2024-comeback_4819205.html',
            'info_dict': {
                'id': '9489f994-2a20-4812-b233-ac0e5c345632',
                'ext': 'mp4',
                'title': 'Dick Morris Discusses His Book ‘The Return: Trump’s Big 2024 Comeback’',
            }
        },
    ]

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

        youmaker_video_id = extract_attributes(get_element_html_by_id('videobox', webpage))['data-id']
        formats, subtitles = self._extract_m3u8_formats_and_subtitles(
            f'http://vs1.youmaker.com/assets/{youmaker_video_id}/playlist.m3u8', video_id, 'mp4', m3u8_id='hls')

        return {
            'id': youmaker_video_id,
            'formats': formats,
            'subtitles': subtitles,
            'title': self._html_extract_title(webpage)
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/camsoda.py (Python)

Code before:
import random

from .common import InfoExtractor
from ..utils import ExtractorError, traverse_obj


class CamsodaIE(InfoExtractor):
    _VALID_URL = r'https?://www\.camsoda\.com/(?P<id>[0-9A-Za-z-]+)'
    _TESTS = [{
        'url': 'https://www.camsoda.com/lizzhopf',
        'info_dict': {
            'id': 'lizzhopf',
            'ext': 'mp4',
            'title': 'lizzhopf (lizzhopf) Nude on Cam. Free Live Sex Chat Room - CamSoda',
            'description': str,
            'is_live': True,
            'age_limit': 18,
        },
        'skip': 'Room is offline',
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        user_id = f'guest_{random.randrange(10000, 99999)}'
        webpage = self._download_webpage(url, video_id, headers=self.geo_verification_headers())

        data = self._download_json(
            f'https://camsoda.com/api/v1/video/vtoken/{video_id}?username={user_id}',
            video_id, headers=self.geo_verification_headers())
        if not data:
            raise ExtractorError('Unable to find configuration for stream.')

        if data.get('private_servers'):

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://www\.camsoda\.com/(?P<id>[\w-]+)'
```

Code after:
import random

from .common import InfoExtractor
from ..utils import ExtractorError, traverse_obj


class CamsodaIE(InfoExtractor):
    _VALID_URL = r'https?://www\.camsoda\.com/(?P<id>[\w-]+)'
    _TESTS = [{
        'url': 'https://www.camsoda.com/lizzhopf',
        'info_dict': {
            'id': 'lizzhopf',
            'ext': 'mp4',
            'title': 'lizzhopf (lizzhopf) Nude on Cam. Free Live Sex Chat Room - CamSoda',
            'description': str,
            'is_live': True,
            'age_limit': 18,
        },
        'skip': 'Room is offline',
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id, headers=self.geo_verification_headers())

        data = self._download_json(
            f'https://camsoda.com/api/v1/video/vtoken/{video_id}', video_id,
            query={'username': f'guest_{random.randrange(10000, 99999)}'},
            headers=self.geo_verification_headers())
        if not data:
            raise ExtractorError('Unable to find configuration for stream.')
        elif data.get('private_servers'):
            raise ExtractorError('Model is in private show.', expected=True)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/unsupported.py (Python)

Code before:
        'url': 'https://www.philo.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/3533
        'url': 'https://www.mech-plus.com/',
        'only_matching': True,
    }, {
        'url': 'https://watch.mech-plus.com/',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/2934
        'url': 'https://www.aha.video',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/2743
        'url': 'https://mubi.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/3287
        'url': 'https://www.vootkids.com',
        'only_matching': True,
    }]

    @classproperty
    def _VALID_URL(cls):
        return r'https?://(?:www\.)?(?:%s)' % '|'.join(rf'({s})' for s in cls.UNSUPPORTED_URLS)

    def _real_extract(self, url):
        raise ExtractorError(
            f'The requested site is known to use DRM protection. It will {self._downloader._format_err("NOT", self._downloader.Styles.EMPHASIS)} be supported by yt-dlp. '
            f'Please {self._downloader._format_err("DO NOT", self._downloader.Styles.ERROR)} open an issue, unless you have evidence that it is not DRM protected.',
            expected=True)


Review comment (suggestion):
```suggestion
        return r'https?://(?:www\.)?(?:%s)' % '|'.join(rf'(?:{s})' for s in cls.UNSUPPORTED_URLS)
```

Code after:
        'url': 'https://www.philo.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/3533
        'url': 'https://www.mech-plus.com/',
        'only_matching': True,
    }, {
        'url': 'https://watch.mech-plus.com/',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/2934
        'url': 'https://www.aha.video',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/2743
        'url': 'https://mubi.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/3287
        'url': 'https://www.vootkids.com',
        'only_matching': True,
    }]

    @classproperty
    def _VALID_URL(cls):
        return rf'https?://(?:www\.)?(?:{"|".join(cls.UNSUPPORTED_URLS)})'

    def _real_extract(self, url):
        raise ExtractorError(
            f'The requested site is known to use DRM protection. It will {self._downloader._format_err("NOT", self._downloader.Styles.EMPHASIS)} be supported by yt-dlp. '
            f'Please {self._downloader._format_err("DO NOT", self._downloader.Styles.ERROR)} open an issue, unless you have evidence that it is not DRM protected.',
            expected=True)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/unsupported.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import classproperty, ExtractorError


class KnownDRMIE(InfoExtractor):
    IE_DESC = False
    IE_NAME = 'unsupported:drm'
    UNSUPPORTED_URLS = (
        r'play\.hbomax\.com',
        r'channel(?:4|5)\.com',
        r'peacocktv\.com',
        r'([a-zA-Z0-9_\.]+\.)?disneyplus\.com',
        r'open\.spotify\.com/(?:track|playlist|album|artist)',
        r'tvnz\.co\.nz',
        r'oneplus\.ch',
        r'artstation\.com/learning/courses',
        r'philo\.com',
        r'([a-zA-Z0-9_\.]+\.)?mech-plus\.com',
        r'aha\.video',
        r'mubi\.com',
        r'vootkids\.com'
    )

    _TESTS = [{
        # https://github.com/yt-dlp/yt-dlp/issues/4309
        'url': 'https://www.peacocktv.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/1719,
        'url': 'https://www.channel4.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/1548
        'url': 'https://www.channel5.com',
        'only_matching': True,
    }, {
        'url': r'https://hsesn.apps.disneyplus.com',

Review comment (suggestion):
```suggestion
        r'(?:[\w\.]+\.)?disneyplus\.com',
```

Code after:
from .common import InfoExtractor
from ..utils import classproperty, ExtractorError


class KnownDRMIE(InfoExtractor):
    IE_DESC = False
    IE_NAME = 'unsupported:drm'
    UNSUPPORTED_URLS = (
        r'play\.hbomax\.com',
        r'channel(?:4|5)\.com',
        r'peacocktv\.com',
        r'(?:[\w\.]+\.)?disneyplus\.com',
        r'open\.spotify\.com/(?:track|playlist|album|artist)',
        r'tvnz\.co\.nz',
        r'oneplus\.ch',
        r'artstation\.com/learning/courses',
        r'philo\.com',
        r'(?:[\w\.]+\.)?mech-plus\.com',
        r'aha\.video',
        r'mubi\.com',
        r'vootkids\.com'
    )

    _TESTS = [{
        # https://github.com/yt-dlp/yt-dlp/issues/4309
        'url': 'https://www.peacocktv.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/1719,
        'url': 'https://www.channel4.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/1548
        'url': 'https://www.channel5.com',
        'only_matching': True,
    }, {
        'url': r'https://hsesn.apps.disneyplus.com',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/unsupported.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import classproperty, ExtractorError


class KnownDRMIE(InfoExtractor):
    IE_DESC = False
    IE_NAME = 'unsupported:drm'
    UNSUPPORTED_URLS = (
        r'play\.hbomax\.com',
        r'channel(?:4|5)\.com',
        r'peacocktv\.com',
        r'([a-zA-Z0-9_\.]+\.)?disneyplus\.com',
        r'open\.spotify\.com/(?:track|playlist|album|artist)',
        r'tvnz\.co\.nz',
        r'oneplus\.ch',
        r'artstation\.com/learning/courses',
        r'philo\.com',
        r'([a-zA-Z0-9_\.]+\.)?mech-plus\.com',
        r'aha\.video',
        r'mubi\.com',
        r'vootkids\.com'
    )

    _TESTS = [{
        # https://github.com/yt-dlp/yt-dlp/issues/4309
        'url': 'https://www.peacocktv.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/1719,
        'url': 'https://www.channel4.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/1548
        'url': 'https://www.channel5.com',
        'only_matching': True,
    }, {
        'url': r'https://hsesn.apps.disneyplus.com',
        'only_matching': True,
    }, {
        'url': r'https://www.disneyplus.com',
        'only_matching': True,
    }, {
        'url': 'https://open.spotify.com/artist/',

Review comment (suggestion):
```suggestion
        r'(?:[\w\.]+\.)?mech-plus\.com',
```

Code after:
from .common import InfoExtractor
from ..utils import classproperty, ExtractorError


class KnownDRMIE(InfoExtractor):
    IE_DESC = False
    IE_NAME = 'unsupported:drm'
    UNSUPPORTED_URLS = (
        r'play\.hbomax\.com',
        r'channel(?:4|5)\.com',
        r'peacocktv\.com',
        r'(?:[\w\.]+\.)?disneyplus\.com',
        r'open\.spotify\.com/(?:track|playlist|album|artist)',
        r'tvnz\.co\.nz',
        r'oneplus\.ch',
        r'artstation\.com/learning/courses',
        r'philo\.com',
        r'(?:[\w\.]+\.)?mech-plus\.com',
        r'aha\.video',
        r'mubi\.com',
        r'vootkids\.com'
    )

    _TESTS = [{
        # https://github.com/yt-dlp/yt-dlp/issues/4309
        'url': 'https://www.peacocktv.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/1719,
        'url': 'https://www.channel4.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/1548
        'url': 'https://www.channel5.com',
        'only_matching': True,
    }, {
        'url': r'https://hsesn.apps.disneyplus.com',
        'only_matching': True,
    }, {
        'url': r'https://www.disneyplus.com',
        'only_matching': True,
    }, {
        'url': 'https://open.spotify.com/artist/',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/unsupported.py (Python)

Code before:
        'url': 'https://www.philo.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/3533
        'url': 'https://www.mech-plus.com/',
        'only_matching': True,
    }, {
        'url': 'https://watch.mech-plus.com/',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/2934
        'url': 'https://www.aha.video',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/2743
        'url': 'https://mubi.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/3287
        'url': 'https://www.vootkids.com',
        'only_matching': True,
    }]

    @classproperty
    def _VALID_URL(cls):
        return r'https?://(?:www\.)?(?:%s)' % '|'.join(rf'(?:{s})' for s in cls.UNSUPPORTED_URLS)

    def _real_extract(self, url):
        raise ExtractorError(
            f'The requested site is known to use DRM protection. It will {self._downloader._format_err("NOT", self._downloader.Styles.EMPHASIS)} be supported by yt-dlp. '
            f'Please {self._downloader._format_err("DO NOT", self._downloader.Styles.ERROR)} open an issue, unless you have evidence that it is not DRM protected.',
            expected=True)


Review comment (suggestion):
```suggestion
        return rf'https?://(?:www\.)?(?:{"|".join(cls.UNSUPPORTED_URLS)})'
```
The extra brackets do nothing

Code after:
        'url': 'https://www.philo.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/3533
        'url': 'https://www.mech-plus.com/',
        'only_matching': True,
    }, {
        'url': 'https://watch.mech-plus.com/',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/2934
        'url': 'https://www.aha.video',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/2743
        'url': 'https://mubi.com',
        'only_matching': True,
    }, {
        # https://github.com/yt-dlp/yt-dlp/issues/3287
        'url': 'https://www.vootkids.com',
        'only_matching': True,
    }]

    @classproperty
    def _VALID_URL(cls):
        return rf'https?://(?:www\.)?(?:{"|".join(cls.UNSUPPORTED_URLS)})'

    def _real_extract(self, url):
        raise ExtractorError(
            f'The requested site is known to use DRM protection. It will {self._downloader._format_err("NOT", self._downloader.Styles.EMPHASIS)} be supported by yt-dlp. '
            f'Please {self._downloader._format_err("DO NOT", self._downloader.Styles.ERROR)} open an issue, unless you have evidence that it is not DRM protected.',
            expected=True)