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

Code before:
from .common import InfoExtractor
from ..utils import int_or_none, parse_iso8601, str_or_none, url_or_none
from ..utils.traversal import traverse_obj


class CNBCVideoIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?cnbc\.com/video/(?:[^/]+/)+(?P<id>[^./?#&]+)\.html'

    _TESTS = [{
        'url': 'https://www.cnbc.com/video/2023/12/07/mcdonalds-just-unveiled-cosmcsits-new-spinoff-brand.html',
        'info_dict': {
            'ext': 'mp4',
            'id': '107344774',
            'display_id': 'mcdonalds-just-unveiled-cosmcsits-new-spinoff-brand',
            'modified_timestamp': 1702053483,
            'timestamp': 1701977810,
            'channel': 'News Videos',
            'upload_date': '20231207',
            'description': 'md5:882c001d85cb43d7579b514307b3e78b',
            'release_timestamp': 1701977375,
            'modified_date': '20231208',
            'release_date': '20231207',
            'duration': 65,
            'author': 'Sean Conlon',
            'title': 'Here\'s a first look at McDonald\'s new spinoff brand, CosMc\'s',
            'thumbnail': 'https://image.cnbcfm.com/api/v1/image/107344192-1701894812493-CosMcsskyHero_2336x1040_hero-desktop.jpg?v=1701894855',
        },
        'expected_warnings': ['Unable to download f4m manifest'],
    }, {
        'url': 'https://www.cnbc.com/video/2023/12/08/jim-cramer-shares-his-take-on-seattles-tech-scene.html',
        'info_dict': {
            'author': 'Jim Cramer',

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?cnbc\.com/video/(?:[^/?#]+/)+(?P<id>[^./?#&]+)\.html'
```

Code after:
from .common import InfoExtractor
from ..utils import int_or_none, parse_iso8601, str_or_none, url_or_none
from ..utils.traversal import traverse_obj


class CNBCVideoIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?cnbc\.com/video/(?:[^/?#]+/)+(?P<id>[^./?#&]+)\.html'

    _TESTS = [{
        'url': 'https://www.cnbc.com/video/2023/12/07/mcdonalds-just-unveiled-cosmcsits-new-spinoff-brand.html',
        'info_dict': {
            'ext': 'mp4',
            'id': '107344774',
            'display_id': 'mcdonalds-just-unveiled-cosmcsits-new-spinoff-brand',
            'modified_timestamp': 1702053483,
            'timestamp': 1701977810,
            'channel': 'News Videos',
            'upload_date': '20231207',
            'description': 'md5:882c001d85cb43d7579b514307b3e78b',
            'release_timestamp': 1701977375,
            'modified_date': '20231208',
            'release_date': '20231207',
            'duration': 65,
            'author': 'Sean Conlon',
            'title': 'Here\'s a first look at McDonald\'s new spinoff brand, CosMc\'s',
            'thumbnail': 'https://image.cnbcfm.com/api/v1/image/107344192-1701894812493-CosMcsskyHero_2336x1040_hero-desktop.jpg?v=1701894855',
        },
        'expected_warnings': ['Unable to download f4m manifest'],
    }, {
        'url': 'https://www.cnbc.com/video/2023/12/08/jim-cramer-shares-his-take-on-seattles-tech-scene.html',
        'info_dict': {
            'author': 'Jim Cramer',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/amadeustv.py (Python)

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


class AmadeusTVIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?amadeus\.tv/library/(?P<id>[\da-f]+)'
    _TESTS = [{
        'url': 'http://www.amadeus.tv/library/65091a87ff85af59d9fc54c3',
        'info_dict': {
            'id': '5576678021301411311',
            'ext': 'mp4',
            'title': '02Jieon Park.mp4',
            'thumbnail': 'http://1253584441.vod2.myqcloud.com/a0046a27vodtransbj1253584441/7db4af535576678021301411311/coverBySnapshot_10_0.jpg',
            'duration': 1264,
        }
    }]

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

        nuxt_data = self._search_nuxt_data(webpage, video_id, traverse=('fetch', '0'))
        actual_video_id = traverse_obj(nuxt_data, ('item', 'video'))

        if not actual_video_id:
            raise ExtractorError('Unable to extract actual video ID')


Review comment (refactor):
Sorted and with the additional imports:
```suggestion
    ExtractorError,
    float_or_none,
    int_or_none,
    parse_iso8601,
    url_or_none,
)
from ..utils.traversal import traverse_obj
```

Code after:
from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    float_or_none,
    int_or_none,
    parse_iso8601,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class AmadeusTVIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?amadeus\.tv/library/(?P<id>[\da-f]+)'
    _TESTS = [{
        'url': 'http://www.amadeus.tv/library/65091a87ff85af59d9fc54c3',
        'info_dict': {
            'id': '5576678021301411311',
            'ext': 'mp4',
            'title': 'Jieon Park - 第五届珠海莫扎特国际青少年音乐周小提琴C组第三轮',
            'thumbnail': 'http://1253584441.vod2.myqcloud.com/a0046a27vodtransbj1253584441/7db4af535576678021301411311/coverBySnapshot_10_0.jpg',
            'duration': 1264.8,
            'upload_date': '20230918',
            'timestamp': 1695034800,
            'display_id': '65091a87ff85af59d9fc54c3',
            'view_count': int,
            'description': 'md5:a0357b9c215489e2067cbae0b777bb95',
        }
    }]

    def _real_extract(self, url):
        display_id = self._match_id(url)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/amadeustv.py (Python)

Code before:
            formats.append({
                **traverse_obj(video, {
                    'url': 'url',
                    'format_id': ('definition', {lambda x: f'http-{x or "0"}'}),
                    'width': ('width', {int_or_none}),
                    'height': ('height', {int_or_none}),
                    'filesize': (('totalSize', 'size'), {int_or_none}),
                    'vcodec': ('videoStreamList', 0, 'codec'),
                    'acodec': ('audioStreamList', 0, 'codec'),
                    'fps': ('videoStreamList', 0, 'fps', {float_or_none}),
                }, get_all=False),
                'http_headers': {'Referer': 'http://www.amadeus.tv/'},
            })

        return {
            'id': video_id,
            'display_id': display_id,
            'formats': formats,
            **traverse_obj(video_data, {
                'title': ('videoInfo', 'basicInfo', 'name'),
                'thumbnail': ('coverInfo', 'coverUrl', {url_or_none}),
                'duration': ('videoInfo', 'sourceVideo', ('floatDuration', 'duration'), {float_or_none}),
            }, get_all=False),
            **traverse_obj(nuxt_data, ('item', {
                'title': (('title', 'title_en', 'title_cn'), ),
                'description': (('description', 'description_en', 'description_cn'), ),
                'timestamp': ('date', {parse_iso8601}),
                'view_count': ('view', {int_or_none}),
            }), get_all=False),
        }


Review comment (suggestion):
```suggestion
                'description': (('description', 'description_en', 'description_cn'), {str}),
```

Code after:
            formats.append({
                **traverse_obj(video, {
                    'url': 'url',
                    'format_id': ('definition', {lambda x: f'http-{x or "0"}'}),
                    'width': ('width', {int_or_none}),
                    'height': ('height', {int_or_none}),
                    'filesize': (('totalSize', 'size'), {int_or_none}),
                    'vcodec': ('videoStreamList', 0, 'codec'),
                    'acodec': ('audioStreamList', 0, 'codec'),
                    'fps': ('videoStreamList', 0, 'fps', {float_or_none}),
                }, get_all=False),
                'http_headers': {'Referer': 'http://www.amadeus.tv/'},
            })

        return {
            'id': video_id,
            'display_id': display_id,
            'formats': formats,
            **traverse_obj(video_data, {
                'title': ('videoInfo', 'basicInfo', 'name', {str}),
                'thumbnail': ('coverInfo', 'coverUrl', {url_or_none}),
                'duration': ('videoInfo', 'sourceVideo', ('floatDuration', 'duration'), {float_or_none}),
            }, get_all=False),
            **traverse_obj(nuxt_data, ('item', {
                'title': (('title', 'title_en', 'title_cn'), {str}),
                'description': (('description', 'description_en', 'description_cn'), {str}),
                'timestamp': ('date', {parse_iso8601}),
                'view_count': ('view', {int_or_none}),
            }), get_all=False),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mixch.py (Python)

Code before:
        'info_dict': {
            'id': '421',
            'title': '96NEKO SHOW TIME',
        }
    }, {
        'url': 'https://mixch.tv/archive/1213',
        'skip': 'paid video, no DRM. expires at Dec 31, 2023',
        'info_dict': {
            'id': '1213',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'live_status': 'not_live',
            'release_timestamp': 1701421200,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        info_json, urlh = self._download_json_handle(
            f'https://mixch.tv/api-web/archive/{video_id}', video_id, expected_status=(401))
        if urlh.status == 401:
            self.raise_login_required(method='cookies')
            return

        release_timestamp = None
        month, day, hour, min = self._search_regex(
            r'(?P<month>\d{1,2})月(?P<day>\d{1,2})日\([月火水木金土日]\)(?P<hour>\d{1,2}):(?P<min>\d{1,2})',
            traverse_obj(info_json, ('archive', 'start')), name='start datetime',
            default=(None, None, None, None), group=('month', 'day', 'hour', 'min'))
        if month and day and hour and min:
            year = (datetime_from_str('today') + datetime.timedelta(hours=9)).strftime('%Y')
            release_timestamp = unified_timestamp(f'{year}/{month}/{day} {hour}:{min} +09:00')

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('archive', 'title')),
            'formats': self._extract_m3u8_formats(
                traverse_obj(info_json, ('archive', 'archiveURL')), video_id),
            'live_status': 'not_live',
            'thumbnail': traverse_obj(info_json, ('archive', 'thumbnailURL')),
            'release_timestamp': release_timestamp,
        }


Review comment (suggestion):
Since we raise an error no return is needed
```suggestion
```

Code after:
    }, {
        'url': 'https://mixch.tv/archive/1213',
        'skip': 'paid video, no DRM. expires at Dec 31, 2023',
        'info_dict': {
            'id': '1213',
            'ext': 'mp4',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'release_date': '20231201',
            'thumbnail': str,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        try:
            info_json = self._download_json(
                f'https://mixch.tv/api-web/archive/{video_id}', video_id)['archive']
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 401:
                self.raise_login_required()
            raise

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('title', {str})),
            'formats': self._extract_m3u8_formats(info_json['archiveURL'], video_id),
            'thumbnail': traverse_obj(info_json, ('thumbnailURL', {url_or_none})),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mixch.py (Python)

Code before:
        'url': 'https://mixch.tv/archive/1213',
        'skip': 'paid video, no DRM. expires at Dec 31, 2023',
        'info_dict': {
            'id': '1213',
            'ext': 'mp4',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'live_status': 'not_live',
            'release_date': '20231201',
            'thumbnail': str,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        info_json, urlh = self._download_json_handle(
            f'https://mixch.tv/api-web/archive/{video_id}', video_id, expected_status=401)
        if urlh.status == 401:
            self.raise_login_required()

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('archive', 'title')),
            'formats': self._extract_m3u8_formats(
                traverse_obj(info_json, ('archive', 'archiveURL')), video_id),
            'live_status': 'not_live',
            'thumbnail': traverse_obj(info_json, ('archive', 'thumbnailURL')),
        }


Review comment (suggestion):
```suggestion
            'title': traverse_obj(info_json, ('archive', 'title', {str})),
```

Code after:
    }, {
        'url': 'https://mixch.tv/archive/1213',
        'skip': 'paid video, no DRM. expires at Dec 31, 2023',
        'info_dict': {
            'id': '1213',
            'ext': 'mp4',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'release_date': '20231201',
            'thumbnail': str,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        try:
            info_json = self._download_json(
                f'https://mixch.tv/api-web/archive/{video_id}', video_id)['archive']
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 401:
                self.raise_login_required()
            raise

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('title', {str})),
            'formats': self._extract_m3u8_formats(info_json['archiveURL'], video_id),
            'thumbnail': traverse_obj(info_json, ('thumbnailURL', {url_or_none})),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mixch.py (Python)

Code before:
            'ext': 'mp4',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'live_status': 'not_live',
            'release_date': '20231201',
            'thumbnail': str,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        info_json, urlh = self._download_json_handle(
            f'https://mixch.tv/api-web/archive/{video_id}', video_id, expected_status=401)
        if urlh.status == 401:
            self.raise_login_required()

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('archive', 'title')),
            'formats': self._extract_m3u8_formats(
                traverse_obj(info_json, ('archive', 'archiveURL')), video_id),
            'live_status': 'not_live',
            'thumbnail': traverse_obj(info_json, ('archive', 'thumbnailURL')),
        }


Review comment (suggestion):
```suggestion
            'thumbnail': traverse_obj(info_json, ('archive', 'thumbnailURL', {url_or_none})),
```

Code after:
            'id': '1213',
            'ext': 'mp4',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'release_date': '20231201',
            'thumbnail': str,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        try:
            info_json = self._download_json(
                f'https://mixch.tv/api-web/archive/{video_id}', video_id)['archive']
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 401:
                self.raise_login_required()
            raise

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('title', {str})),
            'formats': self._extract_m3u8_formats(info_json['archiveURL'], video_id),
            'thumbnail': traverse_obj(info_json, ('thumbnailURL', {url_or_none})),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mixch.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import UserNotLive
from ..utils.traversal import 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):

Review comment (suggestion):
```suggestion
from ..utils import UserNotLive, url_or_none
```

Code after:
from .common import InfoExtractor
from ..networking.exceptions import HTTPError
from ..utils import ExtractorError, UserNotLive, url_or_none
from ..utils.traversal import 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,
    }]
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mixch.py (Python)

Code before:
            'ext': 'mp4',
            'title': '96NEKO SHOW TIME',
        }
    }, {
        'url': 'https://mixch.tv/archive/1213',
        'skip': 'paid video, no DRM. expires at Dec 31, 2023',
        'info_dict': {
            'id': '1213',
            'ext': 'mp4',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'live_status': 'not_live',
            'release_date': '20231201',
            'thumbnail': str,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        info_json, urlh = self._download_json_handle(
            f'https://mixch.tv/api-web/archive/{video_id}', video_id, expected_status=401)
        if urlh.status == 401:
            self.raise_login_required()

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('archive', 'title', {str})),
            'formats': self._extract_m3u8_formats(
                traverse_obj(info_json, ('archive', 'archiveURL')), video_id),
            'live_status': 'not_live',
            'thumbnail': traverse_obj(info_json, ('archive', 'thumbnailURL', {url_or_none})),
        }


Review comment (suggestion):
I'd use `try/except` here instead in case the response body is not valid JSON (current code would raise a JSONDecodeError instead of raising for login required)

Code after:
            'id': '421',
            'ext': 'mp4',
            'title': '96NEKO SHOW TIME',
        }
    }, {
        'url': 'https://mixch.tv/archive/1213',
        'skip': 'paid video, no DRM. expires at Dec 31, 2023',
        'info_dict': {
            'id': '1213',
            'ext': 'mp4',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'release_date': '20231201',
            'thumbnail': str,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        try:
            info_json = self._download_json(
                f'https://mixch.tv/api-web/archive/{video_id}', video_id)['archive']
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 401:
                self.raise_login_required()
            raise

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('title', {str})),
            'formats': self._extract_m3u8_formats(info_json['archiveURL'], video_id),
            'thumbnail': traverse_obj(info_json, ('thumbnailURL', {url_or_none})),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mixch.py (Python)

Code before:
            'id': '1213',
            'ext': 'mp4',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'live_status': 'not_live',
            'release_date': '20231201',
            'thumbnail': str,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        info_json, urlh = self._download_json_handle(
            f'https://mixch.tv/api-web/archive/{video_id}', video_id, expected_status=401)
        if urlh.status == 401:
            self.raise_login_required()

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('archive', 'title', {str})),
            'formats': self._extract_m3u8_formats(
                traverse_obj(info_json, ('archive', 'archiveURL')), video_id),
            'live_status': 'not_live',
            'thumbnail': traverse_obj(info_json, ('archive', 'thumbnailURL', {url_or_none})),
        }


Review comment (suggestion):
IMO probably better to not return anything for `live_status` if we're not sure of the accuracy of `not_live`

Code after:
        'info_dict': {
            'id': '1213',
            'ext': 'mp4',
            'title': '【特別トーク番組アーカイブス】Merm4id×燐舞曲 2nd LIVE「VERSUS」',
            'release_date': '20231201',
            'thumbnail': str,
        }
    }, {
        'url': 'https://mixch.tv/archive/1214',
        'only_matching': True,
    }]

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

        try:
            info_json = self._download_json(
                f'https://mixch.tv/api-web/archive/{video_id}', video_id)['archive']
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 401:
                self.raise_login_required()
            raise

        return {
            'id': video_id,
            'title': traverse_obj(info_json, ('title', {str})),
            'formats': self._extract_m3u8_formats(info_json['archiveURL'], video_id),
            'thumbnail': traverse_obj(info_json, ('thumbnailURL', {url_or_none})),
        }