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

Code before:

        self._access_token = access_token

    def _real_extract(self, url):
        video_id = self._match_id(url)
        formats, subtitles = [], {}
        airings = self._download_json(
            f'https://search-api-mlbtv.mlb.com/svc/search/v2/graphql/persisted/query/core/Airings?variables=%7B%22partnerProgramIds%22%3A%5B%22{video_id}%22%5D%2C%22applyEsniMediaRightsLabels%22%3Atrue%7D',
            video_id)['data']['Airings']
        for airing in airings:
            playback = self._download_json(
                airing['playbackUrls'][0]['href'].format(scenario='browser~csai'), video_id,
                headers={
                    'Authorization': self._access_token,
                    'Accept': 'application/vnd.media-service+json; version=2'
                })
            m3u8_url = playback['stream']['complete']
            f, s = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id, 'mp4', m3u8_id=airing['feedType'] + '-' + airing['feedLanguage'])
            formats.extend(f)
            self._merge_subtitles(s, subtitles)
            title = traverse_obj(airing, ('titles', 0, 'episodeName'))

        self._sort_formats(formats)

        return {
            'title': title,
            'formats': formats,
            'subtitles': subtitles,
            'http_headers': {'Authorization': f'Bearer {self._access_token}'},
            'id': video_id
        }


Review comment (suggestion):
```suggestion

        self._sort_formats(formats)
        return {
            'title': traverse_obj(airings, (..., 'titles', 0, 'episodeName'), get_all=False),
```

Code after:
                'Content-Type': 'application/x-www-form-urlencoded'
            }, data=data.encode())['access_token']

    def _real_extract(self, url):
        video_id = self._match_id(url)
        airings = self._download_json(
            f'https://search-api-mlbtv.mlb.com/svc/search/v2/graphql/persisted/query/core/Airings?variables=%7B%22partnerProgramIds%22%3A%5B%22{video_id}%22%5D%2C%22applyEsniMediaRightsLabels%22%3Atrue%7D',
            video_id)['data']['Airings']
    
        formats, subtitles = [], {}
        for airing in airings:
            m3u8_url = self._download_json(
                airing['playbackUrls'][0]['href'].format(scenario='browser~csai'), video_id,
                headers={
                    'Authorization': self._access_token,
                    'Accept': 'application/vnd.media-service+json; version=2'
                })['stream']['complete']
            f, s = self._extract_m3u8_formats_and_subtitles(
                m3u8_url, video_id, 'mp4', m3u8_id=join_nonempty(airing.get('feedType'), airing.get('feedLanguage')))
            formats.extend(f)
            self._merge_subtitles(s, target=subtitles)

        self._sort_formats(formats)
        return {
            'id': video_id,
            'title': traverse_obj(airings, (..., 'titles', 0, 'episodeName'), get_all=False),
            'formats': formats,
            'subtitles': subtitles,
            'http_headers': {'Authorization': f'Bearer {self._access_token}'},
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mlb.py (Python)

Code before:
    def _real_extract(self, url):
        video_id = self._match_id(url)
        formats, subtitles = [], {}
        airings = self._download_json(
            f'https://search-api-mlbtv.mlb.com/svc/search/v2/graphql/persisted/query/core/Airings?variables=%7B%22partnerProgramIds%22%3A%5B%22{video_id}%22%5D%2C%22applyEsniMediaRightsLabels%22%3Atrue%7D',
            video_id)['data']['Airings']
        for airing in airings:
            playback = self._download_json(
                airing['playbackUrls'][0]['href'].format(scenario='browser~csai'), video_id,
                headers={
                    'Authorization': self._access_token,
                    'Accept': 'application/vnd.media-service+json; version=2'
                })
            m3u8_url = playback['stream']['complete']
            f, s = self._extract_m3u8_formats_and_subtitles(
                m3u8_url, video_id, 'mp4', m3u8_id=join_nonempty(airing.get('feedType'), airing.get('feedLanguage')))
            formats.extend(f)
            self._merge_subtitles(s, subtitles)

        self._sort_formats(formats)
        return {
            'title': traverse_obj(airings, (..., 'titles', 0, 'episodeName'), get_all=False),
            'formats': formats,
            'subtitles': subtitles,
            'http_headers': {'Authorization': f'Bearer {self._access_token}'},
            'id': video_id
        }


Review comment (security):
```suggestion
            'id': video_id,
            'title': traverse_obj(airings, (..., 'titles', 0, 'episodeName'), get_all=False),
            'formats': formats,
            'subtitles': subtitles,
            'http_headers': {'Authorization': f'Bearer {self._access_token}'},
```

Code after:
    def _real_extract(self, url):
        video_id = self._match_id(url)
        airings = self._download_json(
            f'https://search-api-mlbtv.mlb.com/svc/search/v2/graphql/persisted/query/core/Airings?variables=%7B%22partnerProgramIds%22%3A%5B%22{video_id}%22%5D%2C%22applyEsniMediaRightsLabels%22%3Atrue%7D',
            video_id)['data']['Airings']
    
        formats, subtitles = [], {}
        for airing in airings:
            m3u8_url = self._download_json(
                airing['playbackUrls'][0]['href'].format(scenario='browser~csai'), video_id,
                headers={
                    'Authorization': self._access_token,
                    'Accept': 'application/vnd.media-service+json; version=2'
                })['stream']['complete']
            f, s = self._extract_m3u8_formats_and_subtitles(
                m3u8_url, video_id, 'mp4', m3u8_id=join_nonempty(airing.get('feedType'), airing.get('feedLanguage')))
            formats.extend(f)
            self._merge_subtitles(s, target=subtitles)

        self._sort_formats(formats)
        return {
            'id': video_id,
            'title': traverse_obj(airings, (..., 'titles', 0, 'episodeName'), get_all=False),
            'formats': formats,
            'subtitles': subtitles,
            'http_headers': {'Authorization': f'Bearer {self._access_token}'},
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/truth.py (Python)

Code before:
from .common import InfoExtractor

from ..utils import (
    clean_html,
    int_or_none,
    unified_timestamp,
    strip_or_none,
    traverse_obj
)


class TruthIE(InfoExtractor):
    """Extract videos from posts on Donald Trump's truthsocial.com."""

    _VALID_URL = r'https://truthsocial\.com/@[^/]+/posts/(?P<id>[\d]+)'
    _TESTS = [
        {
            'url': 'https://truthsocial.com/@realDonaldTrump/posts/108779000807761862',
            'md5': '4a5fb1470c192e493d9efd6f19e514d3',
            'info_dict': {
                'id': '108779000807761862',
                'ext': 'qt',
                'title': '0d8691160c73d663',
                'description': '',
                'timestamp': 1659835827,
                'upload_date': '20220807',
                'uploader': 'Donald J. Trump',
                'uploader_id': 'realDonaldTrump',
                'uploader_url': 'https://truthsocial.com/@realDonaldTrump',
                'repost_count': int,
                'comment_count': int,
                'like_count': int,
            },
        },
        {
            'url': 'https://truthsocial.com/@ProjectVeritasAction/posts/108618228543962049',
            'md5': 'fd47ba68933f9dce27accc52275be9c3',
            'info_dict': {
                'id': '108618228543962049',
                'ext': 'mp4',

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://truthsocial\.com/@[^/]+/posts/(?P<id>\d+)'
```

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


class TruthIE(InfoExtractor):
    _VALID_URL = r'https?://truthsocial\.com/@[^/]+/posts/(?P<id>\d+)'
    _TESTS = [
        {
            'url': 'https://truthsocial.com/@realDonaldTrump/posts/108779000807761862',
            'md5': '4a5fb1470c192e493d9efd6f19e514d3',
            'info_dict': {
                'id': '108779000807761862',
                'ext': 'qt',
                'title': 'Truth video #108779000807761862',
                'description': None,
                'timestamp': 1659835827,
                'upload_date': '20220807',
                'uploader': 'Donald J. Trump',
                'uploader_id': 'realDonaldTrump',
                'uploader_url': 'https://truthsocial.com/@realDonaldTrump',
                'repost_count': int,
                'comment_count': int,
                'like_count': int,
            },
        },
        {
            'url': 'https://truthsocial.com/@ProjectVeritasAction/posts/108618228543962049',
            'md5': 'fd47ba68933f9dce27accc52275be9c3',
            'info_dict': {
                'id': '108618228543962049',
                'ext': 'mp4',
                'title': 'md5:debde7186cf83f60ff7b44dbb9444e35',
                'description': 'md5:de2fc49045bf92bb8dc97e56503b150f',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/truth.py (Python)

Code before:
from .common import InfoExtractor

from ..utils import (
    clean_html,
    int_or_none,
    unified_timestamp,
    strip_or_none,
    traverse_obj
)


class TruthIE(InfoExtractor):
    """Extract videos from posts on Donald Trump's truthsocial.com."""

    _VALID_URL = r'https://truthsocial\.com/@[^/]+/posts/(?P<id>[\d]+)'
    _TESTS = [
        {
            'url': 'https://truthsocial.com/@realDonaldTrump/posts/108779000807761862',
            'md5': '4a5fb1470c192e493d9efd6f19e514d3',
            'info_dict': {
                'id': '108779000807761862',
                'ext': 'qt',
                'title': '0d8691160c73d663',
                'description': '',
                'timestamp': 1659835827,
                'upload_date': '20220807',
                'uploader': 'Donald J. Trump',
                'uploader_id': 'realDonaldTrump',
                'uploader_url': 'https://truthsocial.com/@realDonaldTrump',
                'repost_count': int,
                'comment_count': int,
                'like_count': int,
            },
        },
        {
            'url': 'https://truthsocial.com/@ProjectVeritasAction/posts/108618228543962049',
            'md5': 'fd47ba68933f9dce27accc52275be9c3',
            'info_dict': {
                'id': '108618228543962049',

Review comment (suggestion):
```suggestion
```
Set an IE_DESC if you want instead

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


class TruthIE(InfoExtractor):
    _VALID_URL = r'https?://truthsocial\.com/@[^/]+/posts/(?P<id>\d+)'
    _TESTS = [
        {
            'url': 'https://truthsocial.com/@realDonaldTrump/posts/108779000807761862',
            'md5': '4a5fb1470c192e493d9efd6f19e514d3',
            'info_dict': {
                'id': '108779000807761862',
                'ext': 'qt',
                'title': 'Truth video #108779000807761862',
                'description': None,
                'timestamp': 1659835827,
                'upload_date': '20220807',
                'uploader': 'Donald J. Trump',
                'uploader_id': 'realDonaldTrump',
                'uploader_url': 'https://truthsocial.com/@realDonaldTrump',
                'repost_count': int,
                'comment_count': int,
                'like_count': int,
            },
        },
        {
            'url': 'https://truthsocial.com/@ProjectVeritasAction/posts/108618228543962049',
            'md5': 'fd47ba68933f9dce27accc52275be9c3',
            'info_dict': {
                'id': '108618228543962049',
                'ext': 'mp4',
                'title': 'md5:debde7186cf83f60ff7b44dbb9444e35',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/parler.py (Python)

Code before:
from .common import InfoExtractor

from ..utils import (
    clean_html,
    format_field,
    int_or_none,
    strip_or_none,
    unified_timestamp,
    urlencode_postdata,
)


class ParlerIE(InfoExtractor):
    IE_DESC = "Extract videos from posts on parler.com"
    _UUID_RE = r'[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
    _VALID_URL = r'https://parler\.com/feed/(?P<id>%s)' % (_UUID_RE,)
    _TESTS = [
        {
            'url': 'https://parler.com/feed/df79fdba-07cc-48fe-b085-3293897520d7',
            'md5': '16e0f447bf186bb3cf64de5bbbf4d22d',
            'info_dict': {
                'id': 'df79fdba-07cc-48fe-b085-3293897520d7',
                'ext': 'mp4',
                'thumbnail': 'https://bl-images.parler.com/videos/6ce7cdf3-a27a-4d72-bf9c-d3e17ce39a66/thumbnail.jpeg',
                'title': 'Parler video #df79fdba-07cc-48fe-b085-3293897520d7',
                'description': 'md5:6f220bde2df4a97cbb89ac11f1fd8197',
                'timestamp': 1659744000,
                'upload_date': '20220806',
                'uploader': 'Tulsi Gabbard',
                'uploader_id': 'TulsiGabbard',
                'uploader_url': 'https://parler.com/TulsiGabbard',
                'view_count': int,
                'comment_count': int,
                'repost_count': int,
            },
        },
        {
            'url': 'https://parler.com/feed/a7406eb4-91e5-4793-b5e3-ade57a24e287',
            'md5': '11687e2f5bb353682cee338d181422ed',

Review comment (suggestion):
```suggestion
    IE_DESC = 'Posts on parler.com'
```

Code after:
import json

from .common import InfoExtractor
from .youtube import YoutubeIE

from ..utils import (
    clean_html,
    format_field,
    int_or_none,
    strip_or_none,
    traverse_obj,
    unified_timestamp,
    urlencode_postdata,
)


class ParlerIE(InfoExtractor):
    IE_DESC = 'Posts on parler.com'
    _VALID_URL = r'https://parler\.com/feed/(?P<id>[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12})'
    _TESTS = [
        {
            'url': 'https://parler.com/feed/df79fdba-07cc-48fe-b085-3293897520d7',
            'md5': '16e0f447bf186bb3cf64de5bbbf4d22d',
            'info_dict': {
                'id': 'df79fdba-07cc-48fe-b085-3293897520d7',
                'ext': 'mp4',
                'thumbnail': 'https://bl-images.parler.com/videos/6ce7cdf3-a27a-4d72-bf9c-d3e17ce39a66/thumbnail.jpeg',
                'title': 'Parler video #df79fdba-07cc-48fe-b085-3293897520d7',
                'description': 'md5:6f220bde2df4a97cbb89ac11f1fd8197',
                'timestamp': 1659744000,
                'upload_date': '20220806',
                'uploader': 'Tulsi Gabbard',
                'uploader_id': 'TulsiGabbard',
                'uploader_url': 'https://parler.com/TulsiGabbard',
                'view_count': int,
                'comment_count': int,
                'repost_count': int,
            },
        },
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/parler.py (Python)

Code before:
    ]

    def _real_extract(self, url):
        # Get the crucial data from the API
        video_id = self._match_id(url)
        data = self._download_json(
            'https://parler.com/open-api/ParleyDetailEndpoint.php', video_id,
            data=urlencode_postdata({'uuid': video_id}))['data'][0]
        primary = data['primary']

        # If this is a YouTube embed, skip out
        if primary.get("V2LINKLONG") and json.loads(primary.get("V2LINKLONG")):
            return self.url_result(json.loads(primary.get("V2LINKLONG"))[0], YoutubeIE)

        # Otherwise, pull out all the stuff
        return {
            'id': video_id,
            'url': traverse_obj(primary, ('video_data', 'videoSrc')),
            'thumbnail': traverse_obj(primary, ('video_data', 'thumbnailUrl')),
            'title': '',
            'description': strip_or_none(clean_html(primary.get('full_body'))) or None,
            'timestamp': unified_timestamp(primary.get('date_created')),
            'uploader': strip_or_none(primary.get('name')),
            'uploader_id': strip_or_none(primary.get('username')),
            'uploader_url': format_field(strip_or_none(primary.get('username')), None, 'https://parler.com/%s'),
            'view_count': int_or_none(primary.get("view_count")),
            'comment_count': int_or_none(traverse_obj(data, ('engagement', 'commentCount'))),
            'repost_count': int_or_none(traverse_obj(data, ('engagement', 'echoCount'))),
        }


Review comment (suggestion):
```suggestion
            'view_count': int_or_none(primary.get('view_count')),
```

Code after:
    ]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        data = self._download_json(
            'https://parler.com/open-api/ParleyDetailEndpoint.php', video_id,
            data=urlencode_postdata({'uuid': video_id}))['data'][0]
        primary = data['primary']

        embed = self._parse_json(primary.get('V2LINKLONG') or '', video_id, fatal=False)
        if embed:
            return self.url_result(embed[0], YoutubeIE)

        return {
            'id': video_id,
            'url': traverse_obj(primary, ('video_data', 'videoSrc')),
            'thumbnail': traverse_obj(primary, ('video_data', 'thumbnailUrl')),
            'title': '',
            'description': strip_or_none(clean_html(primary.get('full_body'))) or None,
            'timestamp': unified_timestamp(primary.get('date_created')),
            'uploader': strip_or_none(primary.get('name')),
            'uploader_id': strip_or_none(primary.get('username')),
            'uploader_url': format_field(strip_or_none(primary.get('username')), None, 'https://parler.com/%s'),
            'view_count': int_or_none(primary.get('view_count')),
            'comment_count': int_or_none(traverse_obj(data, ('engagement', 'commentCount'))),
            'repost_count': int_or_none(traverse_obj(data, ('engagement', 'echoCount'))),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/facebook.py (Python)

Code before:

class FacebookReelIE(InfoExtractor):
    _VALID_URL = r'https?://(?:[\w-]+\.)?facebook\.com/reel/(?P<id>\d+)'
    IE_NAME = 'facebook:reel'

    _TESTS = [{
        'url': 'https://www.facebook.com/reel/1195289147628387',
        'md5': 'c4ff9a7182ff9ff7d6f7a83603bae831',
        'info_dict': {
            'id': '1195289147628387',
            'ext': 'mp4',
            'title': 'md5:9f5b142921b2dc57004fa13f76005f87',
            'description': 'md5:24ea7ef062215d295bdde64e778f5474',
            'uploader': 'Beast Camp Training',
            'uploader_id': '1738535909799870',
            'duration': 9.536,
            'thumbnail': r're:^https?://.*',
            'upload_date': '20211121',
            'timestamp': 1637502604,
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        new_url = f'https://m.facebook.com/watch/?v={video_id}&_rdr'
        return self.url_result(new_url)


Review comment (suggestion):
```suggestion
        return self.url_result(
            f'https://m.facebook.com/watch/?v={video_id}&_rdr', FaceBookIE, video_id)
```

Code after:

class FacebookReelIE(InfoExtractor):
    _VALID_URL = r'https?://(?:[\w-]+\.)?facebook\.com/reel/(?P<id>\d+)'
    IE_NAME = 'facebook:reel'

    _TESTS = [{
        'url': 'https://www.facebook.com/reel/1195289147628387',
        'md5': 'c4ff9a7182ff9ff7d6f7a83603bae831',
        'info_dict': {
            'id': '1195289147628387',
            'ext': 'mp4',
            'title': 'md5:9f5b142921b2dc57004fa13f76005f87',
            'description': 'md5:24ea7ef062215d295bdde64e778f5474',
            'uploader': 'Beast Camp Training',
            'uploader_id': '1738535909799870',
            'duration': 9.536,
            'thumbnail': r're:^https?://.*',
            'upload_date': '20211121',
            'timestamp': 1637502604,
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        return self.url_result(
            f'https://m.facebook.com/watch/?v={video_id}&_rdr', FacebookIE, video_id)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/triller.py (Python)

Code before:
                        retry.error = e
                        continue
                    raise
            if not video_list.get('videos'):
                break
            yield from video_list['videos']
            query['before_time'] = traverse_obj(video_list, ('videos', -1, 'timestamp'))
            if not query['before_time']:
                break

    def _entries(self, videos, user_info):
        for video in videos:
            yield self._parse_video_info(video, user_info)

    def _real_extract(self, url):
        username = self._match_id(url)
        user_info = self._check_user_info(self._download_json(
            f'{self._API_BASE_URL}/api/users/by_username/{username}',
            username, note='Downloading user info',
            errnote='Failed to download user info', headers={
                'Authorization': f'Bearer {self._AUTH_TOKEN}',
                'Origin': 'https://triller.co',
            }).get('user', {}))

        user_id = str_or_none(user_info.get('user_id'))
        videos = LazyList(self._extract_video_list(username, user_id))
        thumbnail = user_info.get('avatar_url')

        return self.playlist_result(
            self._entries(videos, user_info), user_id, username, thumbnail=thumbnail)


Review comment (refactor):
```suggestion
        videos = self._extract_video_list(username, user_id)
```
why LazyList?

Code after:
            yield from video_list['videos']
            query['before_time'] = traverse_obj(video_list, ('videos', -1, 'timestamp'))
            if not query['before_time']:
                break

    def _entries(self, videos, username, user_info):
        for video in videos:
            yield self._parse_video_info(video, username, user_info)

    def _real_extract(self, url):
        username = self._match_id(url)
        user_info = self._check_user_info(self._download_json(
            f'{self._API_BASE_URL}/api/users/by_username/{username}',
            username, note='Downloading user info',
            errnote='Failed to download user info', headers={
                'Authorization': f'Bearer {self._AUTH_TOKEN}',
                'Origin': 'https://triller.co',
            }).get('user', {}))

        user_id = str_or_none(user_info.get('user_id'))
        videos = self._extract_video_list(username, user_id)
        thumbnail = user_info.get('avatar_url')

        return self.playlist_result(
            self._entries(videos, username, user_info), user_id, username, thumbnail=thumbnail)