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

Code before:
                    'width': source.get('widthPixels')
                })

        self._sort_formats(formats)

        timestamp = traverse_obj(
            metadata, ('snippet', 'activeStartDate'))

        age_limit = int_or_none(
            traverse_obj(metadata, ('snippet', 'minimumAge'))) or 0

        subtitles = OrderedDict()

        for lang, data in (traverse_obj(metadata, 'captions') or {}).items():
            subtitles[lang] = [{
                'url': data.get('url'),
                'ext': 'vtt'
            }]

        thumbnails = []

        for thumbnail_size, data in (traverse_obj(metadata, ('snippet', 'thumbnails')) or {}).items():
            thumbnails.append({
                'url': data.get('url'),
                'http_headers': data.get('link')
            })

        output = {
            'id': video_id,
            'title': traverse_obj(metadata, ('snippet', 'title')),
            'thumbnails': thumbnails,
            'timestamp': unified_timestamp(timestamp),
            'formats': formats,
            'age_limit': age_limit,
            'subtitles': subtitles
        }
        return output


Review comment (suggestion):
```suggestion
        subtitles = {
            lang: [{
                'url': data.get('url'),
                'ext': 'vtt'
            }] for lang, data in traverse_obj(metadata, 'captions', default={}).items()
        }

        thumbnails = [{
            'url': data.get('url'),
            'http_headers': data.get('link')
        } for thumbnail_size, data in traverse_obj(metadata, ('snippet', 'thumbnails'), default={}).items()]
```

Code after:
                    'width': source.get('widthPixels'),
                })
        self._sort_formats(formats)

        subtitles = {
            lang: [{
                'url': data.get('url'),
                'ext': 'vtt',
            }] for lang, data in traverse_obj(metadata, 'captions', default={}).items()
        }

        thumbnails = [{
            'url': thumb.get('url'),
            'width': thumb.get('width') or None,
            'height': thumb.get('height') or None,
        } for thumb in traverse_obj(metadata, ('snippet', 'thumbnails', ...))]
        self._remove_duplicate_formats(thumbnails)

        return {
            'id': video_id,
            'title': traverse_obj(metadata, ('snippet', 'title')),
            'timestamp': unified_timestamp(traverse_obj(metadata, ('snippet', 'activeStartDate'))),
            'age_limit': int_or_none(traverse_obj(metadata, ('snippet', 'minimumAge'))) or 0,
            'formats': formats,
            'subtitles': subtitles,
            'thumbnails': thumbnails,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/microsoftembed.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import (
    traverse_obj,
    unified_timestamp,
    int_or_none,
)


class MicrosoftEmbedIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?microsoft\.com/en-us/videoplayer/embed/(?P<id>[a-z0-9A-Z]+)'

    _TESTS = [{
        'url': 'https://www.microsoft.com/en-us/videoplayer/embed/RWL07e',
        'md5': '69a3bff81349094e91b303ff51393de2  Microsoft for Public Health and Social Services [RWL07e].mp4',
        'info_dict': {
            'id': 'RWL07e',
            'title': '...',
            'ext': 'mp4',
            'thumbnail': r're:^https?://.*\.jpg$'
        }
    }]
    _API_URL = 'https://prod-video-cms-rt-microsoft-com.akamaized.net/vhs/api/videos/'

    def _real_extract(self, url):
        video_id = self._match_id(url)
        metadata = self._download_json(self._API_URL + video_id, video_id)
        formats = []

        for source_type, source in metadata['streams'].items():
            stream_url = source['url']

            if source_type == 'smoothStreaming':
                formats.extend(self._extract_ism_formats(stream_url, video_id, 'mss'))
            elif source_type == 'apple_HTTP_Live_Streaming':
                formats.extend(self._extract_m3u8_formats(stream_url, video_id))

Review comment (suggestion):
The language tag is not required and should probably be optional, while also accepting other languages.
```suggestion
    _VALID_URL = r'https?://(?:www\.)?microsoft\.com/(?:[^/]+/)?videoplayer/embed/(?P<id>[a-z0-9A-Z]+)'
```

Code after:
from .common import InfoExtractor
from ..utils import (
    int_or_none,
    traverse_obj,
    unified_timestamp,
)


class MicrosoftEmbedIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?microsoft\.com/(?:[^/]+/)?videoplayer/embed/(?P<id>[a-z0-9A-Z]+)'

    _TESTS = [{
        'url': 'https://www.microsoft.com/en-us/videoplayer/embed/RWL07e',
        'md5': 'eb0ae9007f9b305f9acd0a03e74cb1a9',
        'info_dict': {
            'id': 'RWL07e',
            'title': 'Microsoft for Public Health and Social Services',
            'ext': 'mp4',
            'thumbnail': 'http://img-prod-cms-rt-microsoft-com.akamaized.net/cms/api/am/imageFileData/RWL7Ju?ver=cae5',
            'age_limit': 0,
            'timestamp': 1631658316,
            'upload_date': '20210914'
        }
    }]
    _API_URL = 'https://prod-video-cms-rt-microsoft-com.akamaized.net/vhs/api/videos/'

    def _real_extract(self, url):
        video_id = self._match_id(url)
        metadata = self._download_json(self._API_URL + video_id, video_id)

        formats = []
        for source_type, source in metadata['streams'].items():
            if source_type == 'smooth_Streaming':
                formats.extend(self._extract_ism_formats(source['url'], video_id, 'mss'))
            elif source_type == 'apple_HTTP_Live_Streaming':
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/_extractors.py (Python)

Code before:
from .infoq import InfoQIE
from .instagram import (
    InstagramIE,
    InstagramIOSIE,
    InstagramUserIE,
    InstagramTagIE,
    InstagramStoryIE,
)
from .internazionale import InternazionaleIE
from .internetvideoarchive import InternetVideoArchiveIE
from .iprima import (
    IPrimaIE,
    IPrimaCNNIE
)
from .iqiyi import (
    IqiyiIE,
    IqIE,
    IqAlbumIE
)
from .islamchannel import (
    IslamChannelIE,
    IslamChannelSeriesIE,
)
from .israelnationalnews import (
    IsraelNationalNewsIE
)
from .itprotv import (
    ITProTVIE,
    ITProTVCourseIE
)
from .itv import (
    ITVIE,
    ITVBTCCIE,
)
from .ivi import (
    IviIE,
    IviCompilationIE
)
from .ivideon import IvideonIE
from .iwara import (
    IwaraIE,
    IwaraPlaylistIE,
    IwaraUserIE,
)
from .ixigua import IxiguaIE
from .izlesene import IzleseneIE
from .jable import (
    JableIE,
    JablePlaylistIE,
)
from .jamendo import (

Review comment (suggestion):
```suggestion
from .israelnationalnews import IsraelNationalNewsIE
```
is the convention

Code after:
from .infoq import InfoQIE
from .instagram import (
    InstagramIE,
    InstagramIOSIE,
    InstagramUserIE,
    InstagramTagIE,
    InstagramStoryIE,
)
from .internazionale import InternazionaleIE
from .internetvideoarchive import InternetVideoArchiveIE
from .iprima import (
    IPrimaIE,
    IPrimaCNNIE
)
from .iqiyi import (
    IqiyiIE,
    IqIE,
    IqAlbumIE
)
from .islamchannel import (
    IslamChannelIE,
    IslamChannelSeriesIE,
)
from .israelnationalnews import IsraelNationalNewsIE
from .itprotv import (
    ITProTVIE,
    ITProTVCourseIE
)
from .itv import (
    ITVIE,
    ITVBTCCIE,
)
from .ivi import (
    IviIE,
    IviCompilationIE
)
from .ivideon import IvideonIE
from .iwara import (
    IwaraIE,
    IwaraPlaylistIE,
    IwaraUserIE,
)
from .ixigua import IxiguaIE
from .izlesene import IzleseneIE
from .jable import (
    JableIE,
    JablePlaylistIE,
)
from .jamendo import (
    JamendoIE,
    JamendoAlbumIE,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/israelnationalnews.py (Python)

Code before:
            'view_count': int,
            'duration': 240,
            'thumbnail': 'https://i.ytimg.com/vi_webp/jA84wQhVvg8/maxresdefault.webp',
            'live_status': 'not_live',
            'playable_in_embed': True,
            'age_limit': 0,
            'tags': 'count:29',
            'channel_id': 'UCJdKr0Bgd_5saZYqLCa9mng',
            'channel_url': 'https://www.youtube.com/channel/UCJdKr0Bgd_5saZYqLCa9mng',
            'upload_date': '20220606',
            'uploader': 'The Rubin Report',
        }
    }]

    def _real_extract(self, url):
        news_article_id = self._match_id(url)
        article_json = self._download_json(f'https://www.israelnationalnews.com/Generic/NewAPI/Item?type=0&Item={news_article_id}', news_article_id)

        entries = []
        for item in traverse_obj(article_json, ('Content2', ..., 'content', ..., 'attrs', 'src')) or []:
            entries.append(self.url_result(item, ie_key='Youtube'))

        if not entries:
            raise ExtractorError('This article does not have any videos', expected=True)

        return self.playlist_result(entries, news_article_id)


Review comment (refactor):
```suggestion
        news_article_id = self._match_id(url)
        article_json = self._download_json(
            f'https://www.israelnationalnews.com/Generic/NewAPI/Item?type=0&Item={news_article_id}', news_article_id)

        urls = traverse_obj(article_json, ('Content2', ..., 'content', ..., 'attrs', 'src'))
        if not urls:
            raise ExtractorError('This article does not have any videos', expected=True)

        return self.playlist_from_matches(urls, news_article_id, ie='Youtube')
```

Code after:
                'like_count': int,
                'uploader_url': 'http://www.youtube.com/user/RubinReport',
                'uploader_id': 'RubinReport',
                'availability': 'public',
                'view_count': int,
                'duration': 240,
                'thumbnail': 'https://i.ytimg.com/vi_webp/jA84wQhVvg8/maxresdefault.webp',
                'live_status': 'not_live',
                'playable_in_embed': True,
                'age_limit': 0,
                'tags': 'count:29',
                'channel_id': 'UCJdKr0Bgd_5saZYqLCa9mng',
                'channel_url': 'https://www.youtube.com/channel/UCJdKr0Bgd_5saZYqLCa9mng',
                'upload_date': '20220606',
                'uploader': 'The Rubin Report',
            }
        }]
    }]

    def _real_extract(self, url):
        news_article_id = self._match_id(url)
        article_json = self._download_json(
            f'https://www.israelnationalnews.com/Generic/NewAPI/Item?type=0&Item={news_article_id}', news_article_id)

        urls = traverse_obj(article_json, ('Content2', ..., 'content', ..., 'attrs', 'src'))
        if not urls:
            raise ExtractorError('This article does not have any videos', expected=True)

        return self.playlist_from_matches(urls, news_article_id, ie='Youtube')
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/israelnationalnews.py (Python)

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


class IsraelNationalNewsIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?israelnationalnews\.com/news/(?P<id>[0-9]+)'
    _TESTS = [{
        'url': 'https://www.israelnationalnews.com/news/354520',
        'info_dict': {
            'id': '354520'
        },
        'playlist': [{
            'info_dict': {
                'id': 'jA84wQhVvg8',
                'title': 'Even CNN Host Is Shocked by How Bad Biden\'s Approval Ratings Have Gotten | DM CLIPS | Rubin Report',
                'ext': 'mp4',
                'description': 'md5:b7325a3d00c7596337dc3ae37e32d35c',
                'channel': 'The Rubin Report',
                'channel_follower_count': int,
                'comment_count': int,
                'categories': ['News & Politics'],
                'like_count': int,
                'uploader_url': 'http://www.youtube.com/user/RubinReport',
                'uploader_id': 'RubinReport',
                'availability': 'public',
                'view_count': int,
                'duration': 240,
                'thumbnail': 'https://i.ytimg.com/vi_webp/jA84wQhVvg8/maxresdefault.webp',
                'live_status': 'not_live',
                'playable_in_embed': True,
                'age_limit': 0,

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?israelnationalnews\.com/news/(?P<id>\d+)'
```

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


class IsraelNationalNewsIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?israelnationalnews\.com/news/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://www.israelnationalnews.com/news/354520',
        'info_dict': {
            'id': '354520'
        },
        'playlist': [{
            'info_dict': {
                'id': 'jA84wQhVvg8',
                'title': 'Even CNN Host Is Shocked by How Bad Biden\'s Approval Ratings Have Gotten | DM CLIPS | Rubin Report',
                'ext': 'mp4',
                'description': 'md5:b7325a3d00c7596337dc3ae37e32d35c',
                'channel': 'The Rubin Report',
                'channel_follower_count': int,
                'comment_count': int,
                'categories': ['News & Politics'],
                'like_count': int,
                'uploader_url': 'http://www.youtube.com/user/RubinReport',
                'uploader_id': 'RubinReport',
                'availability': 'public',
                'view_count': int,
                'duration': 240,
                'thumbnail': 'https://i.ytimg.com/vi_webp/jA84wQhVvg8/maxresdefault.webp',
                'live_status': 'not_live',
                'playable_in_embed': True,
                'age_limit': 0,
Repository: yt-dlp/yt-dlp
File: yt_dlp/downloader/__init__.py (Python)

Code before:
from ..utils import NO_DEFAULT, determine_protocol


def get_suitable_downloader(info_dict, params={}, default=NO_DEFAULT, protocol=None, to_stdout=False):
    info_dict['protocol'] = determine_protocol(info_dict)
    info_copy = info_dict.copy()
    info_copy['to_stdout'] = to_stdout

    protocols = (protocol or info_copy['protocol']).split('+')
    downloaders = [_get_suitable_downloader(info_copy, proto, params, default) for proto in protocols]

    if set(downloaders) == {FFmpegFD} and FFmpegFD.can_merge_formats(info_copy, params):
        return FFmpegFD
    elif (set(downloaders) == {DashSegmentsFD}
          and not (to_stdout and len(protocols) > 1)
          and set(protocols) == {'http_dash_segments_generator'}
          and info_dict.get('is_live')):
        return DashSegmentsFD
    elif len(downloaders) == 1:
        return downloaders[0]
    return None


# Some of these require get_suitable_downloader
from .common import FileDownloader
from .dash import DashSegmentsFD
from .external import FFmpegFD, get_external_downloader
from .f4m import F4mFD
from .fc2 import FC2LiveFD
from .hls import HlsFD
from .http import HttpFD
from .ism import IsmFD
from .mhtml import MhtmlFD
from .niconico import NiconicoDmcFD
from .rtmp import RtmpFD
from .rtsp import RtspFD
from .websocket import WebSocketFragmentFD
from .youtube_live_chat import YoutubeLiveChatFD

PROTOCOL_MAP = {
    'rtmp': RtmpFD,
    'rtmpe': RtmpFD,

Review comment (suggestion):
```suggestion
          and set(protocols) == {'http_dash_segments_generator'}):
```

Code after:
from ..utils import NO_DEFAULT, determine_protocol


def get_suitable_downloader(info_dict, params={}, default=NO_DEFAULT, protocol=None, to_stdout=False):
    info_dict['protocol'] = determine_protocol(info_dict)
    info_copy = info_dict.copy()
    info_copy['to_stdout'] = to_stdout

    protocols = (protocol or info_copy['protocol']).split('+')
    downloaders = [_get_suitable_downloader(info_copy, proto, params, default) for proto in protocols]

    if set(downloaders) == {FFmpegFD} and FFmpegFD.can_merge_formats(info_copy, params):
        return FFmpegFD
    elif (set(downloaders) == {DashSegmentsFD}
          and not (to_stdout and len(protocols) > 1)
          and set(protocols) == {'http_dash_segments_generator'}):
        return DashSegmentsFD
    elif len(downloaders) == 1:
        return downloaders[0]
    return None


# Some of these require get_suitable_downloader
from .common import FileDownloader
from .dash import DashSegmentsFD
from .external import FFmpegFD, get_external_downloader
from .f4m import F4mFD
from .fc2 import FC2LiveFD
from .hls import HlsFD
from .http import HttpFD
from .ism import IsmFD
from .mhtml import MhtmlFD
from .niconico import NiconicoDmcFD
from .rtmp import RtmpFD
from .rtsp import RtspFD
from .websocket import WebSocketFragmentFD
from .youtube_live_chat import YoutubeLiveChatFD

PROTOCOL_MAP = {
    'rtmp': RtmpFD,
    'rtmpe': RtmpFD,
    'rtmp_ffmpeg': FFmpegFD,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/bundesliga.py (Python)

Code before:
from .common import InfoExtractor
from .jwplatform import JWPlatformIE


class BundesligaIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?bundesliga\.com/[a-z]{2}/bundesliga/videos\?vid=(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://www.bundesliga.com/en/bundesliga/videos?vid=bhhHkKyN',
        'md5': '8fc3b25cd12440e3a8cdc51f1493849c',
        'info_dict': {
            'id': 'bhhHkKyN',
            'ext': 'mp4',
            'title': 'Watch: Alphonso Davies and Jeremie Frimpong head-to-head',
            'thumbnail': 'https://cdn.jwplayer.com/v2/media/bhhHkKyN/poster.jpg?width=720',
            'upload_date': '20220928',
            'duration': 146,
            'timestamp': 1664366511,
            'description': 'md5:803d4411bd134140c774021dd4b7598b'
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        return self.url_result(
            f'jwplatform:{video_id}', ie=JWPlatformIE.ie_key(),
            video_id=video_id)


Review comment (suggestion):
minor nitpick, but since I assume this is a JWPlatform id, might as well keep it as the same as JWPlatform id regex:

```suggestion
    _VALID_URL = r'https?://(?:www\.)?bundesliga\.com/[a-z]{2}/bundesliga/videos\?vid=(?P<id>[a-zA-Z0-9]{8})'
```

Code after:
from .common import InfoExtractor
from .jwplatform import JWPlatformIE


class BundesligaIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?bundesliga\.com/[a-z]{2}/bundesliga/videos(?:/[^?]+)?\?vid=(?P<id>[a-zA-Z0-9]{8})'
    _TESTS = [
        {
            'url': 'https://www.bundesliga.com/en/bundesliga/videos?vid=bhhHkKyN',
            'md5': '8fc3b25cd12440e3a8cdc51f1493849c',
            'info_dict': {
                'id': 'bhhHkKyN',
                'ext': 'mp4',
                'title': 'Watch: Alphonso Davies and Jeremie Frimpong head-to-head',
                'thumbnail': 'https://cdn.jwplayer.com/v2/media/bhhHkKyN/poster.jpg?width=720',
                'upload_date': '20220928',
                'duration': 146,
                'timestamp': 1664366511,
                'description': 'md5:803d4411bd134140c774021dd4b7598b'
            }
        },
        {
            'url': 'https://www.bundesliga.com/en/bundesliga/videos/latest-features/T8IKc8TX?vid=ROHjs06G',
            'only_matching': True
        },
        {
            'url': 'https://www.bundesliga.com/en/bundesliga/videos/goals?vid=mOG56vWA',
            'only_matching': True
        }
    ]
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/bundesliga.py (Python)

Code before:
            'info_dict': {
                'id': 'bhhHkKyN',
                'ext': 'mp4',
                'title': 'Watch: Alphonso Davies and Jeremie Frimpong head-to-head',
                'thumbnail': 'https://cdn.jwplayer.com/v2/media/bhhHkKyN/poster.jpg?width=720',
                'upload_date': '20220928',
                'duration': 146,
                'timestamp': 1664366511,
                'description': 'md5:803d4411bd134140c774021dd4b7598b'
            }
        },
        {
            'url': 'https://www.bundesliga.com/en/bundesliga/videos/latest-features/T8IKc8TX?vid=ROHjs06G',
            'only_matching': True
        },
        {
            'url': 'https://www.bundesliga.com/en/bundesliga/videos/goals?vid=mOG56vWA',
            'only_matching': True
        }
    ]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        return self.url_result(
            f'jwplatform:{video_id}', ie=JWPlatformIE.ie_key(),
            video_id=video_id)


Review comment (suggestion):
```suggestion
        return self.url_result(f'jwplatform:{video_id}', JWPlatformIE, video_id)
```

Code after:
from .common import InfoExtractor
from .jwplatform import JWPlatformIE


class BundesligaIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?bundesliga\.com/[a-z]{2}/bundesliga/videos(?:/[^?]+)?\?vid=(?P<id>[a-zA-Z0-9]{8})'
    _TESTS = [
        {
            'url': 'https://www.bundesliga.com/en/bundesliga/videos?vid=bhhHkKyN',
            'md5': '8fc3b25cd12440e3a8cdc51f1493849c',
            'info_dict': {
                'id': 'bhhHkKyN',
                'ext': 'mp4',
                'title': 'Watch: Alphonso Davies and Jeremie Frimpong head-to-head',
                'thumbnail': 'https://cdn.jwplayer.com/v2/media/bhhHkKyN/poster.jpg?width=720',
                'upload_date': '20220928',
                'duration': 146,
                'timestamp': 1664366511,
                'description': 'md5:803d4411bd134140c774021dd4b7598b'
            }
        },
        {
            'url': 'https://www.bundesliga.com/en/bundesliga/videos/latest-features/T8IKc8TX?vid=ROHjs06G',
            'only_matching': True
        },
        {
            'url': 'https://www.bundesliga.com/en/bundesliga/videos/goals?vid=mOG56vWA',
            'only_matching': True
        }
    ]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        return self.url_result(f'jwplatform:{video_id}', JWPlatformIE, video_id)