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

Code before:
from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    parse_iso8601,
    traverse_obj,
)


class BeaconTvIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?beacon\.tv/content/(?P<id>.+)'

    _TESTS = [{
        'url': 'https://beacon.tv/content/welcome-to-beacon',
        'md5': 'b3f5932d437f288e662f10f3bfc5bd04',
        'info_dict': {
            'id': 'welcome-to-beacon',
            'ext': 'mp4',
            'upload_date': '20240509',
            'description': 'md5:ea2bd32e71acf3f9fca6937412cc3563',
            'thumbnail': 'https://imagedelivery.net/_18WuG-hYMyVquF6KgU_xQ/critrole-beacon-staging-backend/beacon_trailer_thumbnail_beacon_website-5-600x600.png/format=auto',
            'title': 'Your home for Critical Role!',
            'timestamp': 1715227200,
        }
    }]

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

        json_data_string = self._html_search_regex(r'<script id="__NEXT_DATA__" type="application/json">(.+)</script>', webpage, 'JSON Body')
        json_data = self._parse_json(json_data_string, video_id)

        state = traverse_obj(json_data, ('props', 'pageProps', '__APOLLO_STATE__'))

        content_data = None

Review comment (suggestion):
Don't match the IDs so broadly, otherwise things such as `#` or `?` might also be part of the id.
```suggestion
    _VALID_URL = r'https?://(?:www\.)?beacon\.tv/content/(?P<id>[\w-]+)'
```

Code after:
import json

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    parse_iso8601,
    traverse_obj,
)


class BeaconTvIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?beacon\.tv/content/(?P<id>[\w-]+)'

    _TESTS = [{
        'url': 'https://beacon.tv/content/welcome-to-beacon',
        'md5': 'b3f5932d437f288e662f10f3bfc5bd04',
        'info_dict': {
            'id': 'welcome-to-beacon',
            'ext': 'mp4',
            'upload_date': '20240509',
            'description': 'md5:ea2bd32e71acf3f9fca6937412cc3563',
            'thumbnail': 'https://cdn.jwplayer.com/v2/media/I4CkkEvN/poster.jpg?width=720',
            'title': 'Your home for Critical Role!',
            'timestamp': 1715227200,
            'duration': 105.494,
        },
    }, {
        'url': 'https://beacon.tv/content/re-slayers-take-trailer',
        'md5': 'd879b091485dbed2245094c8152afd89',
        'info_dict': {
            'id': 're-slayers-take-trailer',
            'ext': 'mp4',
            'title': 'The Re-Slayer’s Take | Official Trailer',
            'timestamp': 1715189040,
            'upload_date': '20240508',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/digiview.py (Python)

Code before:
import urllib.parse

from yt_dlp.utils import int_or_none

from .youtube import YoutubeIE
from ..networking import Request


class DigiviewIE(YoutubeIE):
    IE_DESC = 'Digiview'
    IE_NAME = 'digiview'
    _VALID_URL = r'https?://(?:www\.)?ladigitale\.dev/digiview/#/v/(?P<id>[0-9a-f]+)'
    _TESTS = [
        {
            # normal video
            'url': 'https://ladigitale.dev/digiview/#/v/663e17b35e979',
            'md5': 'acdf2c99c1e4d67664c9fbc5695986a9',
            'info_dict': {
                'id': 'BaW_jenozKc',
                'ext': 'mp4',
                'title': 'youtube-dl test video "\'/\\ä↭𝕐',
                'channel': 'Philipp Hagemeister',
                'channel_id': 'UCLqxVugv74EIW3VWh2NOa3Q',
                'channel_url': r're:https?://(?:www\.)?youtube\.com/channel/UCLqxVugv74EIW3VWh2NOa3Q',
                'upload_date': '20121002',
                'description': 'md5:8fb536f4877b8a7455c2ec23794dbc22',
                'categories': ['Science & Technology'],
                'tags': ['youtube-dl'],
                'duration': 10,
                'view_count': int,
                'like_count': int,
                'availability': 'public',
                'playable_in_embed': True,
                'thumbnail': 'https://i.ytimg.com/vi/BaW_jenozKc/maxresdefault.jpg',
                'live_status': 'not_live',
                'age_limit': 0,

Review comment (suggestion):
imo. not needed if they are just repeats
```suggestion
```

Code after:
from .common import InfoExtractor
from .youtube import YoutubeIE
from ..utils import clean_html, int_or_none, traverse_obj, url_or_none, urlencode_postdata


class DigiviewIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?ladigitale\.dev/digiview/#/v/(?P<id>[0-9a-f]+)'
    _TESTS = [{
        # normal video
        'url': 'https://ladigitale.dev/digiview/#/v/67a8e50aee2ec',
        'info_dict': {
            'id': '67a8e50aee2ec',
            'ext': 'mp4',
            'title': 'Big Buck Bunny 60fps 4K - Official Blender Foundation Short Film',
            'thumbnail': 'https://i.ytimg.com/vi/aqz-KE-bpKQ/hqdefault.jpg',
            'upload_date': '20141110',
            'playable_in_embed': True,
            'duration': 635,
            'view_count': int,
            'comment_count': int,
            'channel': 'Blender',
            'license': 'Creative Commons Attribution license (reuse allowed)',
            'like_count': int,
            'tags': 'count:8',
            'live_status': 'not_live',
            'channel_id': 'UCSMOQeBJ2RAnuFungnQOxLg',
            'channel_follower_count': int,
            'channel_url': 'https://www.youtube.com/channel/UCSMOQeBJ2RAnuFungnQOxLg',
            'uploader_id': '@BlenderOfficial',
            'description': 'md5:8f3ed18a53a1bb36cbb3b70a15782fd0',
            'categories': ['Film & Animation'],
            'channel_is_verified': True,
            'heatmap': 'count:100',
            'section_end': 635,
            'uploader': 'Blender',
            'timestamp': 1415628355,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/digiview.py (Python)

Code before:
from .youtube import YoutubeIE
from ..utils import clean_html, int_or_none, traverse_obj, url_or_none, urlencode_postdata


class DigiviewIE(YoutubeIE):
    _VALID_URL = r'https?://(?:www\.)?ladigitale\.dev/digiview/#/v/(?P<id>[0-9a-f]+)'
    _TESTS = [
        {
            # normal video
            'url': 'https://ladigitale.dev/digiview/#/v/67a8e50aee2ec',
            'info_dict': {
                'title': 'Big Buck Bunny 60fps 4K - Official Blender Foundation Short Film',
            },
        },
        {
            # cut video
            'url': 'https://ladigitale.dev/digiview/#/v/67a8e51d0dd58',
            'info_dict': {
                'title': 'Big Buck Bunny 60fps 4K - Official Blender Foundation Short Film',
            },
        },
        {
            # changed title
            'url': 'https://ladigitale.dev/digiview/#/v/67a8ea5644d7a',
            'info_dict': {
                'title': 'Big Buck Bunny (with title changed)',
            },
        },
    ]


Review comment (refactor):
Don't subclass from a concrete extractor
```suggestion
class DigiviewIE(InfoExtractor):
```
Needs `from .common import InfoExtractor` as well

Code after:
from .common import InfoExtractor
from .youtube import YoutubeIE
from ..utils import clean_html, int_or_none, traverse_obj, url_or_none, urlencode_postdata


class DigiviewIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?ladigitale\.dev/digiview/#/v/(?P<id>[0-9a-f]+)'
    _TESTS = [{
        # normal video
        'url': 'https://ladigitale.dev/digiview/#/v/67a8e50aee2ec',
        'info_dict': {
            'id': '67a8e50aee2ec',
            'ext': 'mp4',
            'title': 'Big Buck Bunny 60fps 4K - Official Blender Foundation Short Film',
            'thumbnail': 'https://i.ytimg.com/vi/aqz-KE-bpKQ/hqdefault.jpg',
            'upload_date': '20141110',
            'playable_in_embed': True,
            'duration': 635,
            'view_count': int,
            'comment_count': int,
            'channel': 'Blender',
            'license': 'Creative Commons Attribution license (reuse allowed)',
            'like_count': int,
            'tags': 'count:8',
            'live_status': 'not_live',
            'channel_id': 'UCSMOQeBJ2RAnuFungnQOxLg',
            'channel_follower_count': int,
            'channel_url': 'https://www.youtube.com/channel/UCSMOQeBJ2RAnuFungnQOxLg',
            'uploader_id': '@BlenderOfficial',
            'description': 'md5:8f3ed18a53a1bb36cbb3b70a15782fd0',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/digiview.py (Python)

Code before:
            'channel_is_verified': True,
            'heatmap': 'count:100',
            'section_end': 15,
            'uploader': 'Blender',
            'timestamp': 1415628355,
            'uploader_url': 'https://www.youtube.com/@BlenderOfficial',
            'age_limit': 0,
            'section_start': 10,
            'availability': 'public',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_data = self._download_json(
            'https://ladigitale.dev/digiview/inc/recuperer_video.php', video_id,
            data=urlencode_postdata({'id': video_id}))

        clip_id = video_data['videoId']
        return self.url_result(
            f'https://www.youtube.com/watch?v={clip_id}',
            YoutubeIE, video_id, url_transparent=True,
            **traverse_obj(video_data, {
                'section_start': ('debut', {int_or_none}),
                'section_end': ('fin', {int_or_none}),
                'description': ('description', {clean_html}),
                'title': ('titre', {str}),
                'thumbnail': ('vignette', {url_or_none}),
                'view_count': ('vues', {int_or_none}),
            }),
        )


Review comment (refactor):
I saw a few empty string descriptions in the tests; would be better to `filter` to get the resolving extractor's description instead IMO
```suggestion
                'description': ('description', {clean_html}, filter),
```

Code after:
            'channel_is_verified': True,
            'heatmap': 'count:100',
            'section_end': 15,
            'uploader': 'Blender',
            'timestamp': 1415628355,
            'uploader_url': 'https://www.youtube.com/@BlenderOfficial',
            'age_limit': 0,
            'section_start': 10,
            'availability': 'public',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        video_data = self._download_json(
            'https://ladigitale.dev/digiview/inc/recuperer_video.php', video_id,
            data=urlencode_postdata({'id': video_id}))

        clip_id = video_data['videoId']
        return self.url_result(
            f'https://www.youtube.com/watch?v={clip_id}',
            YoutubeIE, video_id, url_transparent=True,
            **traverse_obj(video_data, {
                'section_start': ('debut', {int_or_none}),
                'section_end': ('fin', {int_or_none}),
                'description': ('description', {clean_html}, filter),
                'title': ('titre', {str}),
                'thumbnail': ('vignette', {url_or_none}),
                'view_count': ('vues', {int_or_none}),
            }),
        )
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/googledrive.py (Python)

Code before:
import re

from .common import InfoExtractor
from ..compat import compat_parse_qs
from .youtube import YoutubeIE
from ..utils import (
    ExtractorError,
    determine_ext,
    extract_attributes,
    get_element_by_class,
    get_element_html_by_id,
    int_or_none,
    lowercase_escape,
    try_get,
    update_url_query,
)


class GoogleDriveIE(InfoExtractor):
    _VALID_URL = r'''(?x)
                        https?://
                            (?:
                                (?:docs|drive|drive\.usercontent)\.google\.com/
                                (?:
                                    (?:uc|open|download)\?.*?id=|
                                    file/d/
                                )|
                                video\.google\.com/get_player\?.*?docid=
                            )

Review comment (refactor):
```suggestion
from .common import InfoExtractor
from .youtube import YoutubeIE
from ..compat import compat_parse_qs
```

Code after:
import re

from .common import InfoExtractor
from .youtube import YoutubeIE
from ..compat import compat_parse_qs
from ..utils import (
    ExtractorError,
    bug_reports_message,
    determine_ext,
    extract_attributes,
    get_element_by_class,
    get_element_html_by_id,
    int_or_none,
    lowercase_escape,
    try_get,
    update_url_query,
)


class GoogleDriveIE(InfoExtractor):
    _VALID_URL = r'''(?x)
                        https?://
                            (?:
                                (?:docs|drive|drive\.usercontent)\.google\.com/
                                (?:
                                    (?:uc|open|download)\?.*?id=|
                                    file/d/
                                )|
                                video\.google\.com/get_player\?.*?docid=
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/hearthisat.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import (
    determine_ext,
    KNOWN_EXTENSIONS,
    str_to_int,
)


class HearThisAtIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/]+)/(?P<title>[A-Za-z0-9\-]+)/?'
    _PLAYLIST_URL = 'https://hearthis.at/playlist.php'
    _TESTS = [{
        'url': 'https://hearthis.at/moofi/dr-kreep',
        'md5': 'ab6ec33c8fed6556029337c7885eb4e0',
        'info_dict': {
            'id': '150939',
            'ext': 'wav',
            'title': 'Moofi - Dr. Kreep',
            'thumbnail': r're:^https?://.*\.jpg$',
            'timestamp': 1421564134,
            'description': 'md5:1adb0667b01499f9d27e97ddfd53852a',
            'upload_date': '20150118',
            'view_count': int,
            'duration': 71,
            'genre': 'Experimental',
        }
    }, {
        # 'download' link redirects to the original webpage
        'url': 'https://hearthis.at/twitchsf/dj-jim-hopkins-totally-bitchin-80s-dance-mix/',
        'md5': '5980ceb7c461605d30f1f039df160c6e',
        'info_dict': {
            'id': '811296',
            'ext': 'mp3',
            'title': 'TwitchSF - DJ Jim Hopkins -  Totally Bitchin\' 80\'s Dance Mix!',
            'description': 'md5:ef26815ca8f483272a87b137ff175be2',

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/?#]+)/(?P<title>[\w-]+)'
```

Code after:
from .common import InfoExtractor
from ..utils import (
    determine_ext,
    KNOWN_EXTENSIONS,
    str_to_int,
)


class HearThisAtIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/?#]+)/(?P<title>[\w.-]+)'
    _PLAYLIST_URL = 'https://hearthis.at/playlist.php'
    _TESTS = [{
        'url': 'https://hearthis.at/moofi/dr-kreep',
        'md5': 'ab6ec33c8fed6556029337c7885eb4e0',
        'info_dict': {
            'id': '150939',
            'display_id': 'moofi - dr-kreep',
            'ext': 'wav',
            'title': 'Moofi - Dr. Kreep',
            'thumbnail': r're:^https?://.*\.jpg$',
            'timestamp': 1421564134,
            'description': 'md5:1adb0667b01499f9d27e97ddfd53852a',
            'upload_date': '20150118',
            'view_count': int,
            'duration': 70,
            'genres': ['Experimental'],
        },
    }, {
        # 'download' link redirects to the original webpage
        'url': 'https://hearthis.at/twitchsf/dj-jim-hopkins-totally-bitchin-80s-dance-mix/',
        'md5': '5980ceb7c461605d30f1f039df160c6e',
        'info_dict': {
            'id': '811296',
            'display_id': 'twitchsf - dj-jim-hopkins-totally-bitchin-80s-dance-mix',
            'ext': 'mp3',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/vidflex.py (Python)

Code before:
        return {
            'id': video_id,
            'formats': [*self._yield_formats(media_config, video_id)],
            **self._search_json_ld(
                webpage.replace('/*<![CDATA[*/', '').replace('/*]]>*/', ''), video_id),
        }

    def _yield_formats(self, media_config, video_id):
        for media_source in traverse_obj(media_config, ('media', 'source', lambda _, v: url_or_none(v['src']))):
            media_url = media_source['src']
            media_type = mimetype2ext(media_source.get('type'))

            if media_type == 'm3u8':
                yield from self._extract_m3u8_formats(media_url, video_id, fatal=False, m3u8_id='hls')
            elif media_type == 'mp4':
                fmt = {
                    'format_id': 'http',
                    'url': media_url,
                    'ext': 'mp4',
                }
                if bitrate := self._search_regex(r'_(\d+)k\.mp4', media_url, 'bitrate', default=None):
                    fmt.update({
                        'format_id': f'http-{bitrate}',
                        'tbr': int(bitrate),
                    })
                yield fmt
            else:
                yield {
                    'url': media_url,
                    'ext': media_type,
                }


Review comment (suggestion):
```suggestion
            elif media_type == 'mp4':
                bitrate = self._search_regex(r'_(\d+)k\.mp4', media_url, 'bitrate', default=None)
                yield {
                    'format_id': join_nonempty('http', bitrate),
                    'url': media_url,
                    'ext': 'mp4',
                    'tbr': int_or_none(bitrate),
                }
```

Code after:
            ('config', {base64.b64decode}, {bytes.decode}, {json.loads}, {dict}))

        return {
            'id': video_id,
            'formats': list(self._yield_formats(media_config, video_id)),
            **self._search_json_ld(
                webpage.replace('/*<![CDATA[*/', '').replace('/*]]>*/', ''), video_id),
        }

    def _yield_formats(self, media_config, video_id):
        for media_source in traverse_obj(media_config, ('media', 'source', lambda _, v: url_or_none(v['src']))):
            media_url = media_source['src']
            media_type = mimetype2ext(media_source.get('type'))

            if media_type == 'm3u8':
                yield from self._extract_m3u8_formats(media_url, video_id, fatal=False, m3u8_id='hls')
            elif media_type == 'mp4':
                bitrate = self._search_regex(r'_(\d+)k\.mp4', media_url, 'bitrate', default=None)
                yield {
                    'format_id': join_nonempty('http', bitrate),
                    'url': media_url,
                    'ext': 'mp4',
                    'tbr': int_or_none(bitrate),
                }
            else:
                yield {
                    'url': media_url,
                    'ext': media_type,
                }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/lci.py (Python)

Code before:
                'id': '13875948',
                'ext': 'mp4',
                'title': 'md5:660df5481fd418bc3bbb0d070e6fdb5a',
                'thumbnail': 'https://photos.tf1.fr/1280/720/presidentielle-2022-marine-le-pen-et-emmanuel-macron-invites-de-lci-ce-vendredi-9c0e73-e1a036-0@1x.jpg',
                'upload_date': '20220422',
                'duration': 33,
            },
            'params': {
                'skip_download': True,
            },
        }, {
            'url': 'https://www.lci.fr/politique/election-presidentielle-2022-second-tour-j-2-marine-le-pen-et-emmanuel-macron-en-interview-de-lci-vendredi-soir-2217486.html',
            'only_matching': True,
        }]

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

        next_data = self._search_nextjs_data(webpage, video_id)

        videos = traverse_obj(next_data, ('props', 'pageProps', 'page', 'tms', 'videos'))
        videos_id = videos.keys()

        wat_id = [video_id for video_id in videos_id if video_id.isnumeric()][0]
        return self.url_result('wat:{}'.format(wat_id), 'Wat', wat_id)


Review comment (refactor):
How about:
```suggestion
        wat_id = traverse_obj(next_data, (
            'props', 'pageProps', 'page', 'tms', 'videos', {dict.keys}, ..., {int_or_none}, any))

        if not wat_id:
            raise ExtractorError('Could not find wat_id')

        return self.url_result(f'wat:{wat_id}', WatIE, wat_id)
```
Also do any pages exist with multiple videos, in which case we should return this as a playlist?

Code after:
            'id': '13875948',
            'ext': 'mp4',
            'title': 'md5:660df5481fd418bc3bbb0d070e6fdb5a',
            'thumbnail': 'https://photos.tf1.fr/1280/720/presidentielle-2022-marine-le-pen-et-emmanuel-macron-invites-de-lci-ce-vendredi-9c0e73-e1a036-0@1x.jpg',
            'upload_date': '20220422',
            'duration': 33,
        },
        'params': {
            'skip_download': True,
        },
    }, {
        'url': 'https://www.lci.fr/politique/election-presidentielle-2022-second-tour-j-2-marine-le-pen-et-emmanuel-macron-en-interview-de-lci-vendredi-soir-2217486.html',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        next_data = self._search_nextjs_data(webpage, video_id)
        wat_id = traverse_obj(next_data, (
            'props', 'pageProps', 'page', 'tms', 'videos', {dict.keys}, ..., {int_or_none}, any))
        if wat_id is None:
            raise ExtractorError('Could not find wat_id')

        return self.url_result(f'wat:{wat_id}', WatIE, str(wat_id))