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

Code before:
            'upload_date': '20190101',
        },
        'params': {
            'skip_download': True,
            'format': 'bestvideo',
        }
    }, {
        # Returned video will always change
        'url': 'https://www.rctiplus.com/live-event',
        'only_matching': True,
    }, {
        # Returned video will also always change
        'url': 'https://www.rctiplus.com/missed-event',
        'only_matching': True,
    }]

    @classmethod
    def suitable(cls, url):
        return False if RCTIPlusIE.suitable(url) else super(RCTIPlusTVIE, cls).suitable(url)

    def _real_extract(self, url):
        match = re.match(self._VALID_URL, url).groupdict()
        tv_id = match.get('tvname') or match.get('eventname')
        webpage = self._download_webpage(url, tv_id)
        video_type, video_id = self._search_regex(
            r'url ?: ?"https://api\.rctiplus\.com/api/v./(?P<type>[^/]+)/(?P<id>\d+)/url', webpage, 'video link', group=('type', 'id'))
        return self.url_result('https://www.rctiplus.com/%s/%s/%s' % (video_type, video_id, tv_id), 'RCTIPlus')


Review comment (suggestion):
```suggestion
            r'url\s*:\s*["\']https://api\.rctiplus\.com/api/v./(?P<type>[^/]+)/(?P<id>\d+)/url', webpage, 'video link', group=('type', 'id'))
```

a bit more robust

Code after:
            'upload_date': '20190101',
        },
        'params': {
            'skip_download': True,
            'format': 'bestvideo',
        }
    }, {
        # Returned video will always change
        'url': 'https://www.rctiplus.com/live-event',
        'only_matching': True,
    }, {
        # Returned video will also always change
        'url': 'https://www.rctiplus.com/missed-event',
        'only_matching': True,
    }]

    @classmethod
    def suitable(cls, url):
        return False if RCTIPlusIE.suitable(url) else super(RCTIPlusTVIE, cls).suitable(url)

    def _real_extract(self, url):
        match = re.match(self._VALID_URL, url).groupdict()
        tv_id = match.get('tvname') or match.get('eventname')
        webpage = self._download_webpage(url, tv_id)
        video_type, video_id = self._search_regex(
            r'url\s*:\s*["\']https://api\.rctiplus\.com/api/v./(?P<type>[^/]+)/(?P<id>\d+)/url', webpage, 'video link', group=('type', 'id'))
        return self.url_result(f'https://www.rctiplus.com/{video_type}/{video_id}/{tv_id}', 'RCTIPlus')
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/blackboardcollaborate.py (Python)

Code before:
            'url': 'https://eu.bbcollab.com/recording/51ed7b50810c4444a106e48cefb3e6b5',
            'only_matching': True,
        },
        {
            'url': 'https://au.bbcollab.com/collab/ui/session/playback/load/2bccf7165d7c419ab87afc1ec3f3bb15',
            'only_matching': True,
        },
    ]

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        zone = mobj.group('zone')
        video_id = mobj.group('id')
        info = self._download_json(
            'https://{}.bbcollab.com/collab/api/csa/recordings/{}/data'.format(zone, video_id), video_id)
        duration = info.get('duration')
        title = info.get('name')
        upload_date = info.get('created')
        streams = info.get('streams')
        formats = []

        for k in streams:
            formats.append({
                'format_id': k,
                'url': streams[k],
            })

        return {
            'duration': duration,
            'formats': formats,
            'id': video_id,
            'timestamp': parse_iso8601(upload_date),
            'title': title,
        }


Review comment (suggestion):
```suggestion
        formats = [{'format_id': k, 'url': url} for k, url in streams.items()]
```

Code after:
            'only_matching': True,
        },
        {
            'url': 'https://ca.bbcollab.com/collab/ui/session/playback/load/b6399dcb44df4f21b29ebe581e22479d',
            'only_matching': True,
        },
        {
            'url': 'https://eu.bbcollab.com/recording/51ed7b50810c4444a106e48cefb3e6b5',
            'only_matching': True,
        },
        {
            'url': 'https://au.bbcollab.com/collab/ui/session/playback/load/2bccf7165d7c419ab87afc1ec3f3bb15',
            'only_matching': True,
        },
    ]

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        region = mobj.group('region')
        video_id = mobj.group('id')
        info = self._download_json(
            'https://{}.bbcollab.com/collab/api/csa/recordings/{}/data'.format(region, video_id), video_id)
        duration = info.get('duration')
        title = info['name']
        upload_date = info.get('created')
        streams = info['streams']
        formats = [{'format_id': k, 'url': url} for k, url in streams.items()]

        return {
            'duration': duration,
            'formats': formats,
            'id': video_id,
            'timestamp': parse_iso8601(upload_date),
            'title': title,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/blackboardcollaborate.py (Python)

Code before:
        {
            'url': 'https://us.bbcollab.com/collab/ui/session/playback/load/76761522adfe4345a0dee6794bbcabda',
            'only_matching': True,
        },
        {
            'url': 'https://ca.bbcollab.com/collab/ui/session/playback/load/b6399dcb44df4f21b29ebe581e22479d',
            'only_matching': True,
        },
        {
            'url': 'https://eu.bbcollab.com/recording/51ed7b50810c4444a106e48cefb3e6b5',
            'only_matching': True,
        },
        {
            'url': 'https://au.bbcollab.com/collab/ui/session/playback/load/2bccf7165d7c419ab87afc1ec3f3bb15',
            'only_matching': True,
        },
    ]

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        region = mobj.group('region')
        video_id = mobj.group('id')
        info = self._download_json(
            'https://{}.bbcollab.com/collab/api/csa/recordings/{}/data'.format(region, video_id), video_id)
        duration = info.get('duration')
        title = info.get('name')
        upload_date = info.get('created')
        streams = info.get('streams')
        formats = [{'format_id': k, 'url': url} for k, url in streams.items()]

        return {
            'duration': duration,
            'formats': formats,
            'id': video_id,
            'timestamp': parse_iso8601(upload_date),
            'title': title,
        }


Review comment (suggestion):
Don't use `.get` here imo, it will return `None` if the title is not present and title can't be None.
Better to use `title = info['name']` so in case it's missing, an error is thrown here.


Code after:
        {
            'url': 'https://us.bbcollab.com/collab/ui/session/playback/load/76761522adfe4345a0dee6794bbcabda',
            'only_matching': True,
        },
        {
            'url': 'https://ca.bbcollab.com/collab/ui/session/playback/load/b6399dcb44df4f21b29ebe581e22479d',
            'only_matching': True,
        },
        {
            'url': 'https://eu.bbcollab.com/recording/51ed7b50810c4444a106e48cefb3e6b5',
            'only_matching': True,
        },
        {
            'url': 'https://au.bbcollab.com/collab/ui/session/playback/load/2bccf7165d7c419ab87afc1ec3f3bb15',
            'only_matching': True,
        },
    ]

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        region = mobj.group('region')
        video_id = mobj.group('id')
        info = self._download_json(
            'https://{}.bbcollab.com/collab/api/csa/recordings/{}/data'.format(region, video_id), video_id)
        duration = info.get('duration')
        title = info['name']
        upload_date = info.get('created')
        streams = info['streams']
        formats = [{'format_id': k, 'url': url} for k, url in streams.items()]

        return {
            'duration': duration,
            'formats': formats,
            'id': video_id,
            'timestamp': parse_iso8601(upload_date),
            'title': title,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/voicy.py (Python)

Code before:
            pager = '&pid=%d&p_date=%s&play_count=%s' % (last['PlaylistId'], last['Published'], last['PlayCount'])

    def _real_extract(self, url):
        channel_id = self._match_id(url)
        articles = self._entries(channel_id)

        first_article = next(articles, None)  # need the first item to get some info
        title = traverse_obj(first_article, ('ChannelName', ), expected_type=compat_str)
        if not title:
            spaker_name = traverse_obj(first_article, ('SpeakerName', ), expected_type=compat_str)
            if spaker_name:
                title = 'Uploads from %s' % spaker_name
        if not title:
            title = 'Uploads from channel ID %s' % channel_id

        articles = itertools.chain([first_article], articles) if first_article else articles  # push back first item

        playlist = (  # intentionally use () to keep lazyness
            self.url_result(smuggle_url('https://voicy.jp/channel/%s/%d' % (channel_id, value['PlaylistId']), value), VoicyIE.ie_key())
            for value in articles)
        return {
            '_type': 'playlist',
            'entries': playlist,
            'id': channel_id,
            'title': title,
            'channel': channel_id,
            'channel_id': channel_id,
        }


Review comment (suggestion):
Shouldn't this be either the speaker_name or channel name?
Maybe channel=channel name, uploader=speaker_name

Code after:

    def _real_extract(self, url):
        channel_id = self._match_id(url)
        articles = self._entries(channel_id)

        first_article = next(articles, None)
        title = traverse_obj(first_article, ('ChannelName', ), expected_type=compat_str)
        speaker_name = traverse_obj(first_article, ('SpeakerName', ), expected_type=compat_str)
        if not title and speaker_name:
            title = 'Uploads from %s' % speaker_name
        if not title:
            title = 'Uploads from channel ID %s' % channel_id

        articles = itertools.chain([first_article], articles) if first_article else articles

        playlist = (
            self.url_result(smuggle_url('https://voicy.jp/channel/%s/%d' % (channel_id, value['PlaylistId']), value), VoicyIE.ie_key())
            for value in articles)
        return {
            '_type': 'playlist',
            'entries': playlist,
            'id': channel_id,
            'title': title,
            'channel': speaker_name,
            'channel_id': channel_id,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/filmmodu.py (Python)

Code before:
        video_type = self._search_regex(r'var\s*videoType\s*=\s*\'([a-z]+)\'', webpage, 'video_type')
        data = self._download_json('https://www.filmmodu.org/get-source', real_video_id, query={
            'movie_id': real_video_id,
            'type': video_type,
        })
        formats = [
            {
                'url': source['src'],
                'format_id': source['label'],
                'resolution': '{}p'.format(source['res']),
                'width': int_or_none(source['res']),
            }
            for source in data['sources']
        ]

        self._sort_formats(formats)

        subtitles = {}

        if data.get('subtitle'):
            subtitles['tr'] = [{
                'url': data['subtitle'],
            }]

        return {
            'id': real_video_id,
            'title': title,
            'description': description,
            'formats': formats,
            'subtitles': subtitles,
            'thumbnail': thumbnail,
        }


Review comment (suggestion):
```suggestion
            'display_id': video_id,
            'title': title,
```

Code after:
        video_type = self._search_regex(r'var\s*videoType\s*=\s*\'([a-z]+)\'', webpage, 'video_type')
        data = self._download_json('https://www.filmmodu.org/get-source', real_video_id, query={
            'movie_id': real_video_id,
            'type': video_type,
        })
        formats = [{
            'url': source['src'],
            'ext': 'mp4',
            'format_id': source['label'],
            'height': int_or_none(source.get('res')),
            'protocol': 'm3u8_native',
        } for source in data['sources']]

        self._sort_formats(formats)

        subtitles = {}

        if data.get('subtitle'):
            subtitles['tr'] = [{
                'url': data['subtitle'],
            }]

        return {
            'id': real_video_id,
            'display_id': video_id,
            'title': title,
            'description': description,
            'formats': formats,
            'subtitles': subtitles,
            'thumbnail': thumbnail,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/filmmodu.py (Python)

Code before:
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor
from ..utils import int_or_none


class FilmmoduIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www.)?filmmodu.org/(?P<id>[^/]+-(?:turkce-dublaj-izle|altyazili-izle))'
    _TESTS = [{
        'url': 'https://www.filmmodu.org/f9-altyazili-izle',
        'md5': '26eb61d8bab018b9189ded692c352a53',
        'info_dict': {
            'id': '10804',
            'ext': 'm3u8',
            'title': 'F9',
            'description': 'md5:2713f584a4d65afa2611e2948d0b953c',
            'subtitles': {
                'tr': [{
                    'ext': 'vtt',
                }],
            },
            'thumbnail': r're:https://s[0-9]+.filmmodu.org/uploads/movie/cover/10804/xXHZeb1yhJvnSHPzZDqee0zfMb6.jpg',
        },
    }, {
        'url': 'https://www.filmmodu.org/the-godfather-turkce-dublaj-izle',
        'md5': '04c16707a945130246876b9b58b3a365',
        'info_dict': {
            'id': '3646',
            'ext': 'm3u8',
            'title': 'Baba',
            'description': 'md5:d43fd651937cd75cc650883ebd8d8461',
            'thumbnail': r're:https://s[0-9]+.filmmodu.org/uploads/movie/cover/3646/6xKCYgH16UuwEGAyroLU6p8HLIn.jpg',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        title = self._og_search_title(webpage, fatal=True)

Review comment (suggestion):
The video's ext is clearly not `m3u8`. This should be set correctly

Code after:
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor
from ..utils import int_or_none


class FilmmoduIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www.)?filmmodu.org/(?P<id>[^/]+-(?:turkce-dublaj-izle|altyazili-izle))'
    _TESTS = [{
        'url': 'https://www.filmmodu.org/f9-altyazili-izle',
        'md5': 'aeefd955c2a508a5bdaa3bcec8eeb0d4',
        'info_dict': {
            'id': '10804',
            'ext': 'mp4',
            'title': 'F9',
            'description': 'md5:2713f584a4d65afa2611e2948d0b953c',
            'subtitles': {
                'tr': [{
                    'ext': 'vtt',
                }],
            },
            'thumbnail': r're:https://s[0-9]+.filmmodu.org/uploads/movie/cover/10804/xXHZeb1yhJvnSHPzZDqee0zfMb6.jpg',
        },
    }, {
        'url': 'https://www.filmmodu.org/the-godfather-turkce-dublaj-izle',
        'md5': '109f2fcb9c941330eed133971c035c00',
        'info_dict': {
            'id': '3646',
            'ext': 'mp4',
            'title': 'Baba',
            'description': 'md5:d43fd651937cd75cc650883ebd8d8461',
            'thumbnail': r're:https://s[0-9]+.filmmodu.org/uploads/movie/cover/3646/6xKCYgH16UuwEGAyroLU6p8HLIn.jpg',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        title = self._og_search_title(webpage, fatal=True)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/bannedvideo.py (Python)

Code before:
        __typename
    }
    voteCount {
        positive
        __typename
    }
    linkedUser {
        _id
        username
        __typename
    }
    createdAt
    __typename
}'''
    _GRAPHQL_GETCOMMENTSREPLIES_QUERY = '''
query GetCommentReplies($id: String!, $limit: Float, $offset: Float) {
    getCommentReplies(id: $id, limit: $limit, offset: $offset) {
        ...VideoComment
        replyTo {
            _id
            __typename
        }
        __typename
    }
}
fragment VideoComment on Comment {
    _id
    content
    liked
    user {
        _id
        username
        __typename
    }
    voteCount {
        positive
        __typename
    }
    linkedUser {
        _id
        username
        __typename
    }
    createdAt
    __typename
}'''
    _VALID_URL = r'https?://(?:www\.)?banned\.video/watch\?id=(?P<id>[0-f]{24})'
    _TEST = {
        'url': 'https://banned.video/watch?id=5e7a859644e02200c6ef5f11',
        'md5': '14b6e81d41beaaee2215cd75c6ed56e4',
        'info_dict': {

Review comment (suggestion):
This `fragment` is the same as on line 69-89. Could be represented once and the concatenated to the comment queries.

Code after:
        voteCount {
            positive
        }
        createdAt
        replyCount
    }
}'''

    _GRAPHQL_QUERIES = {
        'GetVideoAndComments': _GRAPHQL_GETMETADATA_QUERY,
        'GetCommentReplies': _GRAPHQL_GETCOMMENTSREPLIES_QUERY,
    }

    def _call_api(self, video_id, id, operation, note):
        return self._download_json(
            'https://api.infowarsmedia.com/graphql', video_id, note=note,
            headers={
                'Content-Type': 'application/json; charset=utf-8'
            }, data=json.dumps({
                'variables': {'id': id},
                'operationName': operation,
                'query': self._GRAPHQL_QUERIES[operation]
            }).encode('utf8')).get('data')

    def _extract_comments(self, video_id, comments, comment_data):
        for comment in comment_data.copy():
            comment_id = comment.get('_id')
            if comment.get('replyCount') > 0:
                reply_json = self._call_api(
                    video_id, comment_id, 'GetCommentReplies',
                    f'Downloading replies for comment {comment_id}')
                comments.extend(
                    self._parse_comment(reply, comment_id)
                    for reply in reply_json.get('getCommentReplies'))

        return {
            'comments': comments,
            'comment_count': len(comments),
        }

    @staticmethod
    def _parse_comment(comment_data, parent):
        return {
            'id': comment_data.get('_id'),
            'text': comment_data.get('content'),
            'author': try_get(comment_data, lambda x: x['user']['username']),
            'author_id': try_get(comment_data, lambda x: x['user']['_id']),
            'timestamp': unified_timestamp(comment_data.get('createdAt')),
            'parent': parent,
            'like_count': try_get(comment_data, lambda x: x['voteCount']['positive']),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/radiko.py (Python)

Code before:
# coding: utf-8
from __future__ import unicode_literals

import re
import base64
import calendar
import datetime

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    update_url_query,
    clean_html,
    unified_timestamp,
)
from ..compat import compat_urllib_parse


class RadikoBaseIE(InfoExtractor):
    _FULL_KEY = None
    _AUTH_CACHE = ()

    def _auth_client(self):
        if self._AUTH_CACHE:
            return self._AUTH_CACHE

        _, auth1_handle = self._download_webpage_handle(
            'https://radiko.jp/v2/api/auth1', None, 'Downloading authentication page',
            headers={
                'x-radiko-app': 'pc_html5',
                'x-radiko-app-version': '0.0.1',
                'x-radiko-device': 'pc',
                'x-radiko-user': 'dummy_user',
            })
        auth1_header = auth1_handle.info()

        auth_token = auth1_header['X-Radiko-AuthToken']
        kl = int(auth1_header['X-Radiko-KeyLength'])
        ko = int(auth1_header['X-Radiko-KeyOffset'])
        raw_partial_key = self._extract_full_key()[ko:ko + kl]
        partial_key = base64.b64encode(raw_partial_key).decode()

        area_id = self._download_webpage(
            'https://radiko.jp/v2/api/auth2', None, 'Authenticating',
            headers={
                'x-radiko-device': 'pc',

Review comment (performance):
If these are not expected to change between runs, you can cache them in `self._downloader.cache`. See soundcloud/youtube for example

Code after:
# coding: utf-8
from __future__ import unicode_literals

import re
import base64
import calendar
import datetime

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    update_url_query,
    clean_html,
    unified_timestamp,
)
from ..compat import compat_urllib_parse


class RadikoBaseIE(InfoExtractor):
    _FULL_KEY = None

    def _auth_client(self):
        auth_cache = self._downloader.cache.load('radiko', 'auth_data')
        if auth_cache:
            return auth_cache

        _, auth1_handle = self._download_webpage_handle(
            'https://radiko.jp/v2/api/auth1', None, 'Downloading authentication page',
            headers={
                'x-radiko-app': 'pc_html5',
                'x-radiko-app-version': '0.0.1',
                'x-radiko-device': 'pc',
                'x-radiko-user': 'dummy_user',
            })
        auth1_header = auth1_handle.info()

        auth_token = auth1_header['X-Radiko-AuthToken']
        kl = int(auth1_header['X-Radiko-KeyLength'])
        ko = int(auth1_header['X-Radiko-KeyOffset'])
        raw_partial_key = self._extract_full_key()[ko:ko + kl]
        partial_key = base64.b64encode(raw_partial_key).decode()

        area_id = self._download_webpage(
            'https://radiko.jp/v2/api/auth2', None, 'Authenticating',
            headers={
                'x-radiko-device': 'pc',