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

Code before:
            },
        }
    ]

    def _real_extract(self, url):
        webpage = self._download_webpage(url, self._match_id(url))
        video_props = json.loads(re.search(
            r'<script\s?id=\"__NEXT_DATA__\"\s?type=\"application/json\">({.+})</script>',
            webpage).group(1))['props']['pageProps']['video']
        m3u8_url = self._download_json(
            f'https://nbg-api.fite.tv/api/v2/videos/{video_props["id"]}/streams',
            video_props['id'], headers={'x-flipps-user-agent': 'Flipps/75/9.7'})[0]['url']
        formats = self._extract_m3u8_formats(m3u8_url, video_props['id'], 'mp4', m3u8_id='hls')
        self._sort_formats(formats)

        return {
            'id': str(video_props['id']),
            'url': url,
            'title': video_props['title'],
            'alt_title': video_props['slug'],
            'thumbnail': self._og_search_thumbnail(webpage),
            'description': self._og_search_description(webpage),
            'formats': formats,
            'duration': parse_duration(video_props['duration']),
            'release_date': video_props['published_at'],
            'view_count': video_props['view_count']
        }


Review comment (suggestion):
```suggestion
            'view_count': int_or_none(video_props['view_count']),
```

Code after:
            },
        }
    ]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        video_props = self._parse_json(self._search_regex(
            r'<script\s?id=\"__NEXT_DATA__\"\s?type=\"application/json\">({.+})</script>',
            webpage, 'video_props'), video_id)['props']['pageProps']['video']
        m3u8_url = self._download_json(
            f'https://nbg-api.fite.tv/api/v2/videos/{video_id}/streams',
            video_id, headers={'x-flipps-user-agent': 'Flipps/75/9.7'})[0]['url']
        formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', m3u8_id='hls')
        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': video_props['title'],
            'alt_title': video_props.get('slug'),
            'thumbnail': self._og_search_thumbnail(webpage),
            'description': self._og_search_description(webpage),
            'formats': formats,
            'duration': parse_duration(video_props['duration']),
            'timestamp': parse_iso8601(video_props['published_at']),
            'view_count': int_or_none(video_props['view_count']),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/extractors.py (Python)

Code before:
from .tmz import TMZIE
from .tnaflix import (
    TNAFlixNetworkEmbedIE,
    TNAFlixIE,
    EMPFlixIE,
    MovieFapIE,
)
from .toggle import (
    ToggleIE,
    MeWatchIE,
)
from .tokentube import (
    TokentubeIE,
    TokentubeChannelIE
)
from .tonline import TOnlineIE
from .toongoggles import ToonGogglesIE
from .toutv import TouTvIE
from .toypics import ToypicsUserIE, ToypicsIE
from .traileraddict import TrailerAddictIE
from .trilulilu import TriluliluIE
from .trovo import (
    TrovoIE,
    TrovoVodIE,
    TrovoBatchVodIE,
    TrovoBatchClipIE,
)
from .trunews import TruNewsIE
from .trutv import TruTVIE
from .tube8 import Tube8IE
from .tubitv import (
    TubiTvIE,
    TubiTvShowIE,
)
from .tumblr import TumblrIE
from .tunein import (
    TuneInClipIE,
    TuneInStationIE,
    TuneInProgramIE,
    TuneInTopicIE,
    TuneInShortenerIE,
)
from .tunepk import TunePkIE
from .turbo import TurboIE
from .tv2 import (
    TV2IE,
    TV2ArticleIE,
    KatsomoIE,
    MTVUutisetArticleIE,
)
from .tv2dk import (

Review comment (suggestion):
Better names would be 
```
TrovoChannelBaseIE
TrovoChannelVodsIE
TrovoChannelClipsIE
```

Code after:
from .tmz import TMZIE
from .tnaflix import (
    TNAFlixNetworkEmbedIE,
    TNAFlixIE,
    EMPFlixIE,
    MovieFapIE,
)
from .toggle import (
    ToggleIE,
    MeWatchIE,
)
from .tokentube import (
    TokentubeIE,
    TokentubeChannelIE
)
from .tonline import TOnlineIE
from .toongoggles import ToonGogglesIE
from .toutv import TouTvIE
from .toypics import ToypicsUserIE, ToypicsIE
from .traileraddict import TrailerAddictIE
from .trilulilu import TriluliluIE
from .trovo import (
    TrovoIE,
    TrovoVodIE,
    TrovoChannelVodIE,
    TrovoChannelClipIE,
)
from .trunews import TruNewsIE
from .trutv import TruTVIE
from .tube8 import Tube8IE
from .tubitv import (
    TubiTvIE,
    TubiTvShowIE,
)
from .tumblr import TumblrIE
from .tunein import (
    TuneInClipIE,
    TuneInStationIE,
    TuneInProgramIE,
    TuneInTopicIE,
    TuneInShortenerIE,
)
from .tunepk import TunePkIE
from .turbo import TurboIE
from .tv2 import (
    TV2IE,
    TV2ArticleIE,
    KatsomoIE,
    MTVUutisetArticleIE,
)
from .tv2dk import (
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/breitbart.py (Python)

Code before:
)


class BreitBartIE(InfoExtractor):
    _VALID_URL = r"https?:\/\/(?:www\.)breitbart.com/videos/v/(.*?)/"

    @classmethod
    def _get_video_id(cls, url):
        if '_VALID_URL_RE' not in cls.__dict__:
            cls._VALID_URL_RE = re.compile(cls._VALID_URL)

        if cls._VALID_URL_RE.match(url) is not None:
            return cls._VALID_URL_RE.match(url).group(1)
        else:
            return ""

    def _generic_id(self, url):
        return compat_urllib_parse_unquote(os.path.splitext(url.rstrip('/').split('/')[-1])[0])

    def _generic_title(self, url):
        return compat_urllib_parse_unquote(os.path.splitext(url_basename(url))[0])

    def _real_extract(self, url):
        video_id = self._get_video_id(url)
        if not video_id:
            return {}

        head_req = HEADRequest(url)
        head_response = self._request_webpage(
            head_req, video_id,
            note=False, errnote='Could not send HEAD request to %s' % url,
            fatal=False)

        info_dict = {
            'id': video_id,
            'title': self._generic_title(url),
            'timestamp': unified_timestamp(head_response.headers.get('Last-Modified'))
        }

        request = sanitized_Request(url)
        request.add_header('Accept-Encoding', '*')
        full_response = self._request_webpage(request, video_id)
        first_bytes = full_response.read(512)
        webpage = self._webpage_read_content(
            full_response, url, video_id, prefix=first_bytes)

        video_title = self._og_search_title(
            webpage, default=None) or self._html_search_regex(
            r'(?s)<title>(.*?)</title>', webpage, 'video title',
            default='video')


Review comment (suggestion):
```suggestion
        video_id = self._match_id(url)
```

Code after:
            'id': '5cOz1yup',
            'ext': 'mp4',
            'title': 'Watch \u2013 Clyburn: Statues in Congress Have to Go Because they Are Honoring Slavery',
            'description': 'md5:bac35eb0256d1cb17f517f54c79404d5',
            'thumbnail': 'https://cdn.jwplayer.com/thumbs/5cOz1yup-1920.jpg',
            'age_limit': 0,
        }
    }, {
        'url': 'https://www.breitbart.com/videos/v/eaiZjVOn/',
        'only_matching': True,
    }]

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

        formats = self._extract_m3u8_formats(f'https://cdn.jwplayer.com/manifests/{video_id}.m3u8', video_id, ext='mp4')
        self._sort_formats(formats)
        return {
            'id': video_id,
            'title': self._og_search_title(
                webpage, default=None) or self._html_search_regex(
                r'(?s)<title>(.*?)</title>', webpage, 'video title'),
            'description': self._og_search_description(webpage),
            'thumbnail': self._og_search_thumbnail(webpage),
            'age_limit': self._rta_search(webpage),
            'formats': formats
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/breitbart.py (Python)

Code before:
        full_response = self._request_webpage(request, video_id)
        first_bytes = full_response.read(512)
        webpage = self._webpage_read_content(
            full_response, url, video_id, prefix=first_bytes)

        video_title = self._og_search_title(
            webpage, default=None) or self._html_search_regex(
            r'(?s)<title>(.*?)</title>', webpage, 'video title',
            default='video')

        video_description = self._og_search_description(webpage, default=None)
        video_thumbnail = self._og_search_thumbnail(webpage, default=None)

        age_limit = self._rta_search(webpage)
        info_dict.update({
            'title': video_title,
            'description': video_description,
            'thumbnail': video_thumbnail,
            'age_limit': age_limit,
        })

        video_url = "https://cdn.jwplayer.com/manifests/{}.m3u8".format(video_id)
        info_dict['formats'] = self._extract_m3u8_formats(video_url, video_id, ext='mp4')
        if info_dict.get('formats'):
            self._sort_formats(info_dict['formats'])

        return info_dict


Review comment (refactor):
```suggestion
        formats = self._extract_m3u8_formats(f'https://cdn.jwplayer.com/manifests/{video_id}.m3u8', video_id, ext='mp4')
        self._sort_formats(formats)
```

Code after:
from __future__ import unicode_literals

from .common import InfoExtractor


class BreitBartIE(InfoExtractor):
    _VALID_URL = r'https?:\/\/(?:www\.)breitbart.com/videos/v/(?P<id>[^/]+)'
    _TESTS = [{
        'url': 'https://www.breitbart.com/videos/v/5cOz1yup/?pl=Ij6NDOji',
        'md5': '0aa6d1d6e183ac5ca09207fe49f17ade',
        'info_dict': {
            'id': '5cOz1yup',
            'ext': 'mp4',
            'title': 'Watch \u2013 Clyburn: Statues in Congress Have to Go Because they Are Honoring Slavery',
            'description': 'md5:bac35eb0256d1cb17f517f54c79404d5',
            'thumbnail': 'https://cdn.jwplayer.com/thumbs/5cOz1yup-1920.jpg',
            'age_limit': 0,
        }
    }, {
        'url': 'https://www.breitbart.com/videos/v/eaiZjVOn/',
        'only_matching': True,
    }]

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

        formats = self._extract_m3u8_formats(f'https://cdn.jwplayer.com/manifests/{video_id}.m3u8', video_id, ext='mp4')
        self._sort_formats(formats)
        return {
            'id': video_id,
            'title': self._og_search_title(
                webpage, default=None) or self._html_search_regex(
                r'(?s)<title>(.*?)</title>', webpage, 'video title'),
            'description': self._og_search_description(webpage),
            'thumbnail': self._og_search_thumbnail(webpage),
            'age_limit': self._rta_search(webpage),
            'formats': formats
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/breitbart.py (Python)

Code before:
            'url': 'https://www.breitbart.com/videos/v/eaiZjVOn/'
        },
        {
            'url': 'https://www.breitbart.com/videos/v/5cOz1yup/?pl=Ij6NDOji'
        }
    ]

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

        video_title = self._og_search_title(
            webpage, default=None) or self._html_search_regex(
            r'(?s)<title>(.*?)</title>', webpage, 'video title')
        video_description = self._og_search_description(webpage)
        video_thumbnail = self._og_search_thumbnail(webpage)

        age_limit = self._rta_search(webpage)
        info_dict = {'id': video_id, 'title': video_title, 'description': video_description,
                     'thumbnail': video_thumbnail, 'age_limit': age_limit,
                     'formats': self._extract_m3u8_formats(f'https://cdn.jwplayer.com/manifests/{video_id}.m3u8',
                                                           video_id, ext='mp4')}

        self._sort_formats(info_dict['formats'])

        return info_dict


Review comment (refactor):
```suggestion
        formats = self._extract_m3u8_formats(f'https://cdn.jwplayer.com/manifests/{video_id}.m3u8', video_id, ext='mp4')
        self._sort_formats(formats)
        return {
            'id': video_id,
            'title': self._og_search_title(
                webpage, default=None) or self._html_search_regex(
                r'(?s)<title>(.*?)</title>', webpage, 'video title'),
            'description': self._og_search_description(webpage),
            'thumbnail': self._og_search_thumbnail(webpage),
            'age_limit': self._rta_search(webpage),
            'thumbnail': video_thumbnail,
            'formats': formats
        }
```

Code after:
        'md5': '0aa6d1d6e183ac5ca09207fe49f17ade',
        'info_dict': {
            'id': '5cOz1yup',
            'ext': 'mp4',
            'title': 'Watch \u2013 Clyburn: Statues in Congress Have to Go Because they Are Honoring Slavery',
            'description': 'md5:bac35eb0256d1cb17f517f54c79404d5',
            'thumbnail': 'https://cdn.jwplayer.com/thumbs/5cOz1yup-1920.jpg',
            'age_limit': 0,
        }
    }, {
        'url': 'https://www.breitbart.com/videos/v/eaiZjVOn/',
        'only_matching': True,
    }]

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

        formats = self._extract_m3u8_formats(f'https://cdn.jwplayer.com/manifests/{video_id}.m3u8', video_id, ext='mp4')
        self._sort_formats(formats)
        return {
            'id': video_id,
            'title': self._og_search_title(
                webpage, default=None) or self._html_search_regex(
                r'(?s)<title>(.*?)</title>', webpage, 'video title'),
            'description': self._og_search_description(webpage),
            'thumbnail': self._og_search_thumbnail(webpage),
            'age_limit': self._rta_search(webpage),
            'formats': formats
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/breitbart.py (Python)

Code before:
class BreitBartIE(InfoExtractor):
    _VALID_URL = r"https?:\/\/(?:www\.)breitbart.com/videos/v/(?P<id>[^/]+)"
    _TESTS = [
        {
            'url': 'https://www.breitbart.com/videos/v/eaiZjVOn/'
        },
        {
            'url': 'https://www.breitbart.com/videos/v/5cOz1yup/?pl=Ij6NDOji'
        }
    ]

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

        formats = self._extract_m3u8_formats(f'https://cdn.jwplayer.com/manifests/{video_id}.m3u8', video_id, ext='mp4')
        self._sort_formats(formats)
        return {
            'id': video_id,
            'title': self._og_search_title(
                webpage, default=None) or self._html_search_regex(
                r'(?s)<title>(.*?)</title>', webpage, 'video title'),
            'description': self._og_search_description(webpage),
            'thumbnail': self._og_search_thumbnail(webpage),
            'age_limit': self._rta_search(webpage),
            'thumbnail': video_thumbnail,
            'formats': formats
        }


Review comment (suggestion):
```suggestion
            'thumbnail': self._og_search_thumbnail(webpage),
```

Code after:
class BreitBartIE(InfoExtractor):
    _VALID_URL = r'https?:\/\/(?:www\.)breitbart.com/videos/v/(?P<id>[^/]+)'
    _TESTS = [{
        'url': 'https://www.breitbart.com/videos/v/5cOz1yup/?pl=Ij6NDOji',
        'md5': '0aa6d1d6e183ac5ca09207fe49f17ade',
        'info_dict': {
            'id': '5cOz1yup',
            'ext': 'mp4',
            'title': 'Watch \u2013 Clyburn: Statues in Congress Have to Go Because they Are Honoring Slavery',
            'description': 'md5:bac35eb0256d1cb17f517f54c79404d5',
            'thumbnail': 'https://cdn.jwplayer.com/thumbs/5cOz1yup-1920.jpg',
            'age_limit': 0,
        }
    }, {
        'url': 'https://www.breitbart.com/videos/v/eaiZjVOn/',
        'only_matching': True,
    }]

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

        formats = self._extract_m3u8_formats(f'https://cdn.jwplayer.com/manifests/{video_id}.m3u8', video_id, ext='mp4')
        self._sort_formats(formats)
        return {
            'id': video_id,
            'title': self._og_search_title(
                webpage, default=None) or self._html_search_regex(
                r'(?s)<title>(.*?)</title>', webpage, 'video title'),
            'description': self._og_search_description(webpage),
            'thumbnail': self._og_search_thumbnail(webpage),
            'age_limit': self._rta_search(webpage),
            'formats': formats
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/peertv.py (Python)

Code before:
        title = self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title').replace('\xa0', ' ')
        description = self._html_search_meta(('og:description', 'description'), webpage)

        video_key = self._html_search_regex(r'player\.peer\.tv/js/([\d\w]+)', webpage, 'video key')

        js = self._download_webpage(f'https://player.peer.tv/js/{video_key}/', video_id,
                                    headers={'Referer': 'https://www.peer.tv/'})

        session_id = self._search_regex(r'["\']session_id["\']:\s*["\']([\w\d]+)["\']', js, 'session id')

        player_webpage = self._download_webpage(
            f'https://player.peer.tv/jsc/{video_key}/{session_id}?jsr=aHR0cHM6Ly93d3cucGVlci50di9kZS84NDE=&cs=UTF-8&mq=2&ua=0&webm=p&mp4=p&hls=1',
            video_id, note='Downloading player webpage')

        m3u8_url = self._search_regex(r'["\']playlist_url["\']:\s*["\']([^"\']+)["\']', player_webpage,
                                      'm3u8 url').replace('\\', '')

        formats = self._extract_m3u8_formats(m3u8_url, video_id, m3u8_id='hls')

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': title,
            'formats': formats,
            'description': description,
            'thumbnail': self._html_search_meta(('og:image', 'image'), webpage)
        }


Review comment (suggestion):
```suggestion
            'title': self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title').replace('\xa0', ' '),
            'formats': formats,
            'description': self._html_search_meta(('og:description', 'description'), webpage),
```
is cleaner imo

Code after:
        video_key = self._html_search_regex(r'player\.peer\.tv/js/([a-zA-Z0-9]+)', webpage, 'video key')

        js = self._download_webpage(f'https://player.peer.tv/js/{video_key}/', video_id,
                                    headers={'Referer': 'https://www.peer.tv/'}, note='Downloading session id')

        session_id = self._search_regex(r'["\']session_id["\']:\s*["\']([a-zA-Z0-9]+)["\']', js, 'session id')

        player_webpage = self._download_webpage(
            f'https://player.peer.tv/jsc/{video_key}/{session_id}?jsr=aHR0cHM6Ly93d3cucGVlci50di9kZS84NDE=&cs=UTF-8&mq=2&ua=0&webm=p&mp4=p&hls=1',
            video_id, note='Downloading player webpage')

        m3u8_url = self._search_regex(r'["\']playlist_url["\']:\s*(["\'][^"\']+["\'])', player_webpage, 'm3u8 url')
        m3u8_url = self._parse_json(m3u8_url, video_id, transform_source=js_to_json)

        formats = self._extract_m3u8_formats(m3u8_url, video_id, m3u8_id='hls')

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': self._html_search_regex(r'<h1>(.+?)</h1>', webpage, 'title').replace('\xa0', ' '),
            'formats': formats,
            'description': self._html_search_meta(('og:description', 'description'), webpage),
            'thumbnail': self._html_search_meta(('og:image', 'image'), webpage)
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mixch.py (Python)

Code before:
from __future__ import unicode_literals

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


class MixchIE(InfoExtractor):
    IE_NAME = 'mixch'
    # allow omitting last /live in the URL, though it's likely uncommon
    _VALID_URL = r'https?://(?:www\.)?mixch\.tv/u/(?P<id>\d+)'

    TESTS = [{
        'url': 'https://mixch.tv/u/16137876/live',
        'skip': 'live has ended',
    }, {
        'url': 'https://mixch.tv/u/16236849/live',
        'skip': 'don\'t know if this live persists',
        'info_dict': {
            'id': '16236849',
            'title': '24配信シェア⭕️投票🙏💦',
            'comment_count': 13145,
            'view_count': 28348,
            'timestamp': 1636189377,
            'uploader': '🦥伊咲👶🏻#フレアワ',
            'uploader_id': '16236849',
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        url = 'https://mixch.tv/u/%s/live' % video_id
        webpage = self._download_webpage(url, video_id)

        initial_js_state = self._parse_json(self._search_regex(

Review comment (refactor):
```suggestion
```
doesnt matter as long as it doesnt conflict with any other extractor

Code after:
from __future__ import unicode_literals

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


class MixchIE(InfoExtractor):
    IE_NAME = 'mixch'
    _VALID_URL = r'https?://(?:www\.)?mixch\.tv/u/(?P<id>\d+)'

    TESTS = [{
        'url': 'https://mixch.tv/u/16236849/live',
        'skip': 'don\'t know if this live persists',
        'info_dict': {
            'id': '16236849',
            'title': '24配信シェア⭕️投票🙏💦',
            'comment_count': 13145,
            'view_count': 28348,
            'timestamp': 1636189377,
            'uploader': '🦥伊咲👶🏻#フレアワ',
            'uploader_id': '16236849',
        }
    }, {
        'url': 'https://mixch.tv/u/16137876/live',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(f'https://mixch.tv/u/{video_id}/live', video_id)

        initial_js_state = self._parse_json(self._search_regex(
            r'(?m)^\s*window\.__INITIAL_JS_STATE__\s*=\s*(\{.+?\});\s*$', webpage, 'initial JS state'), video_id)
        if not initial_js_state.get('liveInfo'):