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

Code before:
from datetime import datetime
import time
import json

from .common import InfoExtractor
from ..utils import (
    get_element_html_by_id,
    extract_attributes,
)


class FathomIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?fathom\.video/share/(?P<id>[^/?#&]+?)'
    _TESTS = [{
        'url': 'https://fathom.video/share/G9mkjkspnohVVZ_L5nrsoPycyWcB8y7s',
        'md5': '0decd5343b8f30ae268625e79a02b60f',
        'info_dict': {
            'id': '47200596',
            'ext': 'mp4',
            'title': 'eCom Inucbator - Coaching Session',
            'duration': 8125.380507,
            'timestamp': 1699036314.0,
            'upload_date': '20231103',
        },
    }, {
        'url': 'https://fathom.video/share/mEws3bybftHL2QLymxYEDeE21vtLxGVm',
        'md5': '4f5cb382126c22d1aba8a939f9c49690',
        'info_dict': {
            'id': '46812957',
            'ext': 'mp4',
            'title': 'Jon, Lawrence, Neman chat about practice',
            'duration': 3571.517847,
            'timestamp': 1698921000.0,
            'upload_date': '20231102',

Review comment (refactor):
you can easily keep these sorted with `isort` (though we may be moving to hatch/ruff in the near future)
```suggestion
import json

from .common import InfoExtractor
from ..utils import (
    extract_attributes,
    float_or_none,
    get_element_html_by_id,
    parse_iso8601,
)
from ..utils.traversal import traverse_obj
```

Code after:
import json

from .common import InfoExtractor
from ..utils import (
    extract_attributes,
    float_or_none,
    get_element_html_by_id,
    parse_iso8601,
)
from ..utils.traversal import traverse_obj


class FathomIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?fathom\.video/share/(?P<id>[^/?#&]+)'
    _TESTS = [{
        'url': 'https://fathom.video/share/G9mkjkspnohVVZ_L5nrsoPycyWcB8y7s',
        'md5': '0decd5343b8f30ae268625e79a02b60f',
        'info_dict': {
            'id': '47200596',
            'ext': 'mp4',
            'title': 'eCom Inucbator - Coaching Session',
            'duration': 8125.380507,
            'timestamp': 1699048914,
            'upload_date': '20231103',
        },
    }, {
        'url': 'https://fathom.video/share/mEws3bybftHL2QLymxYEDeE21vtLxGVm',
        'md5': '4f5cb382126c22d1aba8a939f9c49690',
        'info_dict': {
            'id': '46812957',
            'ext': 'mp4',
            'title': 'Jon, Lawrence, Neman chat about practice',
            'duration': 3571.517847,
            'timestamp': 1698933600,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/medici.py (Python)

Code before:
from urllib.parse import unquote
from .common import InfoExtractor
from ..utils import (
    unified_strdate,
    bool_or_none,
    str_or_none,
    traverse_obj,
)


class MediciIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?(?:medici|edu\.medici)\.tv/(?:(?:[a-zA-Z0-9-_\.]+)/)*(?:#!/)?(?P<id>[^?#&]+)'
    _TESTS = [
        {
            'url': 'https://www.medici.tv/en/operas/thomas-ades-the-exterminating-angel-calixto-bieito-opera-bastille-paris',
            'md5': 'd483f74e7a7a9eac0dbe152ab189050d',
            'expected_warnings': [r'preview'],
            'info_dict': {
                'id': '8032',
                'ext': 'mp4',
                'title': 'Thomas Adès\'s The Exterminating Angel',
                'thumbnail': r're:^https?://medicitv-[abc]\.imgix\.net/movie/[^?]+\.jpg(?:\?[^?]+)?',
                'description': 'md5:708ae6350dadc604225b4a6e32482bab',
                'upload_date': '20240304',
            },
        },

Review comment (suggestion):
this project prefers to import the whole module for code readability/uniformity
```suggestion
import urllib.parse

```

Code after:
import urllib.parse

from .common import InfoExtractor
from ..utils import (
    filter_dict,
    parse_iso8601,
    traverse_obj,
    try_call,
    url_or_none,
)


class MediciIE(InfoExtractor):
    _VALID_URL = r'https?://(?:(?P<sub>www|edu)\.)?medici\.tv/[a-z]{2}/[\w.-]+/(?P<id>[^/?#&]+)'
    _TESTS = [{
        'url': 'https://www.medici.tv/en/operas/thomas-ades-the-exterminating-angel-calixto-bieito-opera-bastille-paris',
        'md5': 'd483f74e7a7a9eac0dbe152ab189050d',
        'info_dict': {
            'id': '8032',
            'ext': 'mp4',
            'title': 'Thomas Adès\'s The Exterminating Angel',
            'description': 'md5:708ae6350dadc604225b4a6e32482bab',
            'thumbnail': r're:https://.+/.+\.jpg',
            'upload_date': '20240304',
            'timestamp': 1709561766,
            'display_id': 'thomas-ades-the-exterminating-angel-calixto-bieito-opera-bastille-paris',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/boosty.py (Python)

Code before:
import json
import urllib

from .common import InfoExtractor
from .youtube import YoutubeIE
from ..utils import (
    ExtractorError,
    int_or_none,
    qualities,
    str_or_none,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class BoostyIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?boosty\.to/(?P<user>[^/#?]+)/posts/(?P<post_id>[^/#?]+)'
    _TESTS = [{
        # single ok_video
        'url': 'https://boosty.to/kuplinov/posts/e55d050c-e3bb-4873-a7db-ac7a49b40c38',
        'info_dict': {
            'id': 'd7473824-352e-48e2-ae53-d4aa39459968',
            'title': 'phasma_3',
            'channel': 'Kuplinov',
            'channel_id': '7958701',
            'timestamp': 1655031975,
            'upload_date': '20220612',

Review comment (suggestion):
```suggestion
import urllib.parse
```
The fact that import `urllib` works here is due to a weird quirk of python and should not be relied on

Code after:
import json
import urllib.parse

from .common import InfoExtractor
from .youtube import YoutubeIE
from ..utils import (
    ExtractorError,
    bug_reports_message,
    int_or_none,
    qualities,
    str_or_none,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class BoostyIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?boosty\.to/(?P<user>[^/#?]+)/posts/(?P<post_id>[^/#?]+)'
    _TESTS = [{
        # single ok_video
        'url': 'https://boosty.to/kuplinov/posts/e55d050c-e3bb-4873-a7db-ac7a49b40c38',
        'info_dict': {
            'id': 'd7473824-352e-48e2-ae53-d4aa39459968',
            'title': 'phasma_3',
            'channel': 'Kuplinov',
            'channel_id': '7958701',
            'timestamp': 1655031975,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/godresource.py (Python)

Code before:
        webpage, _ = self._download_webpage_handle(url, display_id, expected_status=404)

        api_data = self._download_json(
            f'https://api.godresource.com/api/Streams/{display_id}', display_id)

        video_url = api_data['streamUrl']

        # TODO: better name?
        extraction_result = {}
        if determine_ext(video_url) == 'm3u8':
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                api_data['streamUrl'], display_id)

            extraction_result = {
                'formats': formats,
                'subtitles': subtitles
            }
        elif determine_ext(video_url) == 'mp4':
            extraction_result = {
                'url': video_url,
                'ext': 'mp4'
            }

        return {
            'id': display_id,
            **extraction_result,
            **merge_dicts(traverse_obj(api_data, {
                'title': ('title', {str}),  # can be None in API
                'thumbnail': ('thumbnail', {url_or_none}),
                'view_count': ('views', {int}),
                'channel': ('channelName', {str}),
                'channel_id': 'channelId',
                'timestamp': ('streamDateCreated', {unified_timestamp}),
                'modified_timestamp': ('streamDataModified', {unified_timestamp})
            }), {
                # This title is not reliable (only give the site name)
                'title': self._html_extract_title(webpage),
            }),
        }


Review comment (suggestion):
```suggestion
            'formats': formats,
            'subtitles': subtitles,
```

Code after:

        api_data = self._download_json(
            f'https://api.godresource.com/api/Streams/{display_id}', display_id)

        video_url = api_data['streamUrl']
        is_live = api_data.get('isLive') or False
        if (ext := determine_ext(video_url)) == 'm3u8':
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                video_url, display_id, live=is_live)
        elif ext == 'mp4':
            formats, subtitles = [{
                'url': video_url,
                'ext': ext
            }], {}
        else:
            raise ExtractorError(f'Unexpected video format {ext}')

        return {
            'id': display_id,
            'formats': formats,
            'subtitles': subtitles,
            'title': '',
            'is_live': is_live,
            **traverse_obj(api_data, {
                'title': ('title', {str}),
                'thumbnail': ('thumbnail', {url_or_none}),
                'view_count': ('views', {int}),
                'channel': ('channelName', {str}),
                'channel_id': ('channelId', {str_or_none}),
                'timestamp': ('streamDateCreated', {unified_timestamp}),
                'modified_timestamp': ('streamDataModified', {unified_timestamp})
            })
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/godresource.py (Python)

Code before:
    }]

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

        api_data = self._download_json(
            f'https://api.godresource.com/api/Streams/{display_id}', display_id)

        video_url = api_data['streamUrl']
        if (ext := determine_ext(video_url)) == 'm3u8':
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                api_data['streamUrl'], display_id)
        elif ext == 'mp4':
            formats, subtitles = [{
                'url': video_url,
                'ext': ext
            }], {}
        else:
            raise ExtractorError(f'Unexpected video format {ext}')

        return {
            'id': display_id,
            'formats': formats,
            'subtitles': subtitles,
            'title': '',
            **traverse_obj(api_data, {
                'title': ('title', {str}),
                'thumbnail': ('thumbnail', {url_or_none}),
                'view_count': ('views', {int}),
                'channel': ('channelName', {str}),
                'channel_id': ('channelId', {str_or_none}),
                'timestamp': ('streamDateCreated', {unified_timestamp}),
                'modified_timestamp': ('streamDataModified', {unified_timestamp})
            })
        }


Review comment (suggestion):
```suggestion
            'title': '',
            'is_live': is_live,
```

Code after:
    }]

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

        api_data = self._download_json(
            f'https://api.godresource.com/api/Streams/{display_id}', display_id)

        video_url = api_data['streamUrl']
        is_live = api_data.get('isLive') or False
        if (ext := determine_ext(video_url)) == 'm3u8':
            formats, subtitles = self._extract_m3u8_formats_and_subtitles(
                video_url, display_id, live=is_live)
        elif ext == 'mp4':
            formats, subtitles = [{
                'url': video_url,
                'ext': ext
            }], {}
        else:
            raise ExtractorError(f'Unexpected video format {ext}')

        return {
            'id': display_id,
            'formats': formats,
            'subtitles': subtitles,
            'title': '',
            'is_live': is_live,
            **traverse_obj(api_data, {
                'title': ('title', {str}),
                'thumbnail': ('thumbnail', {url_or_none}),
                'view_count': ('views', {int}),
                'channel': ('channelName', {str}),
                'channel_id': ('channelId', {str_or_none}),
                'timestamp': ('streamDateCreated', {unified_timestamp}),
                'modified_timestamp': ('streamDataModified', {unified_timestamp})
            })
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/nts.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import extract_attributes


class NTSLiveIE(InfoExtractor):
    IE_NAME = 'nts.live'
    _VALID_URL = r'https?://(?:www\.)?nts\.live/shows/[^/]+/episodes/(?P<id>[^./?#]+)'
    _TESTS = [
        {
            # embedded soundcloud
            'url': 'https://www.nts.live/shows/yu-su/episodes/yu-su-2nd-april-2024',
            'md5': 'b5444c04888c869d68758982de1a27d8',
            'info_dict': {
                'id': '1791563518',
                'ext': 'opus',
                'uploader_id': '995579326',
                'title': 'Pender Street Steppers & YU SU 020424',
                'timestamp': 1712143743,
                'upload_date': '20240403',
                'thumbnail': 'https://i1.sndcdn.com/artworks-qKcNO0z0AQGGbv9s-GljJCw-original.jpg',
                'license': 'all-rights-reserved',
                'repost_count': int,
                'uploader_url': 'https://soundcloud.com/user-643553014',
                'uploader': 'NTS Latest',
                'description': 'md5:cf9d7d7997ef00a7b6046c9615b72c55',
                'duration': 10784.157,
            }

Review comment (refactor):
Updated imports
```suggestion
from .common import InfoExtractor
from ..utils import parse_iso8601, url_or_none
from ..utils.traversal import traverse_obj
```

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


class NTSLiveIE(InfoExtractor):
    IE_NAME = 'nts.live'
    _VALID_URL = r'https?://(?:www\.)?nts\.live/shows/[^/?#]+/episodes/(?P<id>[^/?#]+)'
    _TESTS = [
        {
            # embedded soundcloud
            'url': 'https://www.nts.live/shows/yu-su/episodes/yu-su-2nd-april-2024',
            'md5': 'b5444c04888c869d68758982de1a27d8',
            'info_dict': {
                'id': '1791563518',
                'ext': 'opus',
                'uploader_id': '995579326',
                'title': 'Pender Street Steppers & YU SU',
                'timestamp': 1712073600,
                'upload_date': '20240402',
                'thumbnail': 'https://i1.sndcdn.com/artworks-qKcNO0z0AQGGbv9s-GljJCw-original.jpg',
                'license': 'all-rights-reserved',
                'repost_count': int,
                'uploader_url': 'https://soundcloud.com/user-643553014',
                'uploader': 'NTS Latest',
                'description': 'md5:cd00ac535a63caaad722483ae3ff802a',
                'duration': 10784.157,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/xiaohongshu.py (Python)

Code before:
                        'tbr': 'avgBitrate',
                        'format': 'qualityType',
                        'filesize': 'size',
                        'duration': ('duration', {lambda x: float_or_none(x, scale=1000)})
                    })
                })

        thumbnails = []
        for image_info in traverse_obj(note_info, ('imageList', ...)):
            for url in traverse_obj(image_info, (('urlDefault', 'urlPre'), {url_or_none})):
                thumbnails.append({
                    'url': url,
                    **traverse_obj(image_info, {
                        'height': 'height',
                        'width': 'width'
                    })
                })

        return {
            'id': display_id,
            'formats': formats or [{
                'url': self._html_search_meta(['og:video'], webpage, fatal=True),
                'ext': 'mp4'
            }],
            'thumbnails': thumbnails or [{
                'url': self._html_search_meta(['og:image'], webpage)
            }],
            'title': self._html_search_meta(['og:title'], webpage, default=None),
            **traverse_obj(note_info, {
                'title': 'title',
                'description': 'desc',
                'tags': ('tagList', ..., 'name', {str}),
                'uploader_id': ('user', 'userId'),
            }),
        }


Review comment (suggestion):
Maybe this should also have `default=None`?? Idk whether you want the warning if thumbnail's missing or not

Code after:
                'format': ('qualityType', {str}),
                'filesize': ('size', {int_or_none}),
                'duration': ('duration', {functools.partial(float_or_none, scale=1000)})
            })

            formats.extend(traverse_obj(info, (('mediaUrl', ('backupUrls', ...)), {
                lambda u: url_or_none(u) and {'url': u, **format_info}})))

        thumbnails = []
        for image_info in traverse_obj(note_info, ('imageList', ...)):
            thumbnail_info = traverse_obj(image_info, {
                'height': ('height', {int_or_none}),
                'width': ('width', {int_or_none}),
            })
            for thumb_url in traverse_obj(image_info, (('urlDefault', 'urlPre'), {url_or_none})):
                thumbnails.append({
                    'url': thumb_url,
                    **thumbnail_info,
                })

        return {
            'id': display_id,
            'formats': formats,
            'thumbnails': thumbnails,
            'title': self._html_search_meta(['og:title'], webpage, default=None),
            **traverse_obj(note_info, {
                'title': ('title', {str}),
                'description': ('desc', {str}),
                'tags': ('tagList', ..., 'name', {str}),
                'uploader_id': ('user', 'userId', {str}),
            }),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/xiaohongshu.py (Python)

Code before:
        for image_info in traverse_obj(note_info, ('imageList', ...)):
            thumbnail_info = traverse_obj(image_info, {
                'height': 'height',
                'width': 'width'
            })
            for url in traverse_obj(image_info, (('urlDefault', 'urlPre'), {url_or_none})):
                thumbnails.append({
                    'url': url,
                    **thumbnail_info
                })

        return {
            'id': display_id,
            'formats': formats or [{
                'url': self._html_search_meta(['og:video'], webpage, fatal=True),
                'ext': 'mp4'
            }],
            'thumbnails': thumbnails or [{
                'url': self._html_search_meta(['og:image'], webpage, default=None)
            }],
            'title': self._html_search_meta(['og:title'], webpage, default=None),
            **traverse_obj(note_info, {
                'title': 'title',
                'description': 'desc',
                'tags': ('tagList', ..., 'name', {str}),
                'uploader_id': ('user', 'userId'),
            }),
        }


Review comment (suggestion):
```suggestion
                'title': ('title', {str}),
                'description': ('desc', {str}),
                'tags': ('tagList', ..., 'name', {str}),
                'uploader_id': ('user', 'userId', {str}),
```

Code after:
                lambda u: url_or_none(u) and {'url': u, **format_info}})))

        thumbnails = []
        for image_info in traverse_obj(note_info, ('imageList', ...)):
            thumbnail_info = traverse_obj(image_info, {
                'height': ('height', {int_or_none}),
                'width': ('width', {int_or_none}),
            })
            for thumb_url in traverse_obj(image_info, (('urlDefault', 'urlPre'), {url_or_none})):
                thumbnails.append({
                    'url': thumb_url,
                    **thumbnail_info,
                })

        return {
            'id': display_id,
            'formats': formats,
            'thumbnails': thumbnails,
            'title': self._html_search_meta(['og:title'], webpage, default=None),
            **traverse_obj(note_info, {
                'title': ('title', {str}),
                'description': ('desc', {str}),
                'tags': ('tagList', ..., 'name', {str}),
                'uploader_id': ('user', 'userId', {str}),
            }),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/xiaohongshu.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import (
    float_or_none,
    js_to_json,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class XiaoHongShuIE(InfoExtractor):
    _VALID_URL = r'https?://www\.xiaohongshu.com/explore/(?P<id>[a-f0-9]+)'
    IE_DESC = '小红书'
    _TESTS = [{
        'url': 'https://www.xiaohongshu.com/explore/6411cf99000000001300b6d9',
        'md5': '2a87a77ddbedcaeeda8d7eae61b61228',
        'info_dict': {
            'id': '6411cf99000000001300b6d9',
            'ext': 'mp4',
            'uploader_id': '5c31698d0000000007018a31',
            'description': '#今日快乐今日发[话题]# #吃货薯看这里[话题]# #香妃蛋糕[话题]# #小五卷蛋糕[话题]# #新手蛋糕卷[话题]#',
            'title': '香妃蛋糕也太香了吧🔥不需要卷❗️绝对的友好',
            'tags': ['今日快乐今日发', '吃货薯看这里', '香妃蛋糕', '小五卷蛋糕', '新手蛋糕卷'],
            'duration': 101.726,
            'thumbnail': r're:https?://sns-webpic-qc\.xhscdn\.com/\d+/[a-z0-9]+/[\w]+',
        }
    }]

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

Review comment (suggestion):
Updated imports
```suggestion
    float_or_none,
    int_or_none,
```

Code after:
import functools

from .common import InfoExtractor
from ..utils import (
    float_or_none,
    int_or_none,
    js_to_json,
    url_or_none,
)
from ..utils.traversal import traverse_obj


class XiaoHongShuIE(InfoExtractor):
    _VALID_URL = r'https?://www\.xiaohongshu\.com/explore/(?P<id>[\da-f]+)'
    IE_DESC = '小红书'
    _TESTS = [{
        'url': 'https://www.xiaohongshu.com/explore/6411cf99000000001300b6d9',
        'md5': '2a87a77ddbedcaeeda8d7eae61b61228',
        'info_dict': {
            'id': '6411cf99000000001300b6d9',
            'ext': 'mp4',
            'uploader_id': '5c31698d0000000007018a31',
            'description': '#今日快乐今日发[话题]# #吃货薯看这里[话题]# #香妃蛋糕[话题]# #小五卷蛋糕[话题]# #新手蛋糕卷[话题]#',
            'title': '香妃蛋糕也太香了吧🔥不需要卷❗️绝对的友好',
            'tags': ['今日快乐今日发', '吃货薯看这里', '香妃蛋糕', '小五卷蛋糕', '新手蛋糕卷'],
            'duration': 101.726,
            'thumbnail': r're:https?://sns-webpic-qc\.xhscdn\.com/\d+/[a-z0-9]+/[\w]+',
        }
    }]