ronantakizawa/codereview-bench huggingface dataset:
Repository: yt-dlp/yt-dlp
File: test/test_jsinterp.py (Python)

Code before:
        self._test('function f(){return "012345678".slice(0, 0)}', '')
        self._test('function f(){return "012345678".slice(1, 0)}', '')
        self._test('function f(){return "012345678".slice(0, 1)}', '0')
        self._test('function f(){return "012345678".slice(3, 6)}', '345')
        self._test('function f(){return "012345678".slice(1, -1)}', '1234567')
        self._test('function f(){return "012345678".slice(-1, 1)}', '')
        self._test('function f(){return "012345678".slice(-3, -1)}', '67')

    def test_js_number_to_string(self):
        for test, radix, expected in [
            (0, None, '0'),
            (-0, None, '0'),
            (0.0, None, '0'),
            (-0.0, None, '0'),
            (math.nan, None, 'NaN'),
            (-math.nan, None, 'NaN'),
            (math.inf, None, 'Infinity'),
            (-math.inf, None, '-Infinity'),
            (10 ** 21.5, 8, '526665530627250154000000'),
            (6, 2, '110'),
            (254, 16, 'fe'),
            (-10, 2, '-1010'),
            (-0xff, 2, '-11111111'),
            (0.1 + 0.2, 16, '0.4cccccccccccd'),
            (1234.1234, 10, '1234.1234'),
            # (1000000000000000128, 10, "1000000000000000100")
        ]:
            assert js_number_to_string(test, radix) == expected


if __name__ == '__main__':
    unittest.main()


Review comment (suggestion):
very important code review suggestion
```suggestion
            # (1000000000000000128, 10, '1000000000000000100')
```

Code after:
        self._test('function f(){return "012345678".slice(0, 0)}', '')
        self._test('function f(){return "012345678".slice(1, 0)}', '')
        self._test('function f(){return "012345678".slice(0, 1)}', '0')
        self._test('function f(){return "012345678".slice(3, 6)}', '345')
        self._test('function f(){return "012345678".slice(1, -1)}', '1234567')
        self._test('function f(){return "012345678".slice(-1, 1)}', '')
        self._test('function f(){return "012345678".slice(-3, -1)}', '67')

    def test_js_number_to_string(self):
        for test, radix, expected in [
            (0, None, '0'),
            (-0, None, '0'),
            (0.0, None, '0'),
            (-0.0, None, '0'),
            (math.nan, None, 'NaN'),
            (-math.nan, None, 'NaN'),
            (math.inf, None, 'Infinity'),
            (-math.inf, None, '-Infinity'),
            (10 ** 21.5, 8, '526665530627250154000000'),
            (6, 2, '110'),
            (254, 16, 'fe'),
            (-10, 2, '-1010'),
            (-0xff, 2, '-11111111'),
            (0.1 + 0.2, 16, '0.4cccccccccccd'),
            (1234.1234, 10, '1234.1234'),
            # (1000000000000000128, 10, '1000000000000000100')
        ]:
            assert js_number_to_string(test, radix) == expected


if __name__ == '__main__':
    unittest.main()
Repository: yt-dlp/yt-dlp
File: yt_dlp/jsinterp.py (Python)

Code before:

    if math.isnan(val):
        return 'NaN'
    if val == 0:
        return '0'
    if math.isinf(val):
        return '-Infinity' if val < 0 else 'Infinity'
    if radix == 10:
        # TODO: implement special cases
        ...

    ALPHABET = b'0123456789abcdefghijklmnopqrstuvwxyz.-'

    result = collections.deque()
    sign = val < 0
    val = abs(val)
    fraction, integer = math.modf(val)
    delta = max(math.nextafter(.0, math.inf), math.ulp(val) / 2)

    if fraction >= delta:
        result.append(-2)
    while fraction >= delta:
        delta *= radix
        fraction, digit = math.modf(fraction * radix)
        result.append(int(digit))
        # rounding cringe
        needs_rounding = fraction > 0.5 or (fraction == 0.5 and int(digit) & 1)
        if needs_rounding and fraction + delta > 1:
            for index in reversed(range(1, len(result))):
                if result[index] + 1 < radix:
                    result[index] += 1
                    break
                result.pop()

            else:
                integer += 1
                break
            break

    integer, digit = divmod(int(integer), radix)
    result.appendleft(digit)
    while integer > 0:
        integer, digit = divmod(integer, radix)
        result.appendleft(digit)

    if sign:
        result.appendleft(-1)

    return bytes(ALPHABET[digit] for digit in result).decode('ascii')



Review comment (suggestion):
```suggestion
        # if we need to round, propagate potential carry through fractional part
```

Code after:

    if math.isnan(val):
        return 'NaN'
    if val == 0:
        return '0'
    if math.isinf(val):
        return '-Infinity' if val < 0 else 'Infinity'
    if radix == 10:
        # TODO: implement special cases
        ...

    ALPHABET = b'0123456789abcdefghijklmnopqrstuvwxyz.-'

    result = collections.deque()
    sign = val < 0
    val = abs(val)
    fraction, integer = math.modf(val)
    delta = max(math.nextafter(.0, math.inf), math.ulp(val) / 2)

    if fraction >= delta:
        result.append(-2)  # `.`
    while fraction >= delta:
        delta *= radix
        fraction, digit = math.modf(fraction * radix)
        result.append(int(digit))
        # if we need to round, propagate potential carry through fractional part
        needs_rounding = fraction > 0.5 or (fraction == 0.5 and int(digit) & 1)
        if needs_rounding and fraction + delta > 1:
            for index in reversed(range(1, len(result))):
                if result[index] + 1 < radix:
                    result[index] += 1
                    break
                result.pop()

            else:
                integer += 1
            break

    integer, digit = divmod(int(integer), radix)
    result.appendleft(digit)
    while integer > 0:
        integer, digit = divmod(integer, radix)
        result.appendleft(digit)

    if sign:
        result.appendleft(-1)  # `-`

    return bytes(ALPHABET[digit] for digit in result).decode('ascii')


# Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/goodgame.py (Python)

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


class GoodGameIE(InfoExtractor):
    IE_NAME = 'goodgame:stream'
    _VALID_URL = r'https?://goodgame\.ru/(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://goodgame.ru/Pomi#autoplay',
        'info_dict': {
            'id': 'pomi',
            'ext': 'mp4',
            'title': r're:Reynor vs Special \(1/2,bo3\) Wardi Spring EU \- playoff \(финальный день\) \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
            'channel_id': '1644',
            'channel': 'Pomi',
            'channel_url': 'https://goodgame.ru/Pomi',
            'description': 'md5:4a87b775ee7b2b57bdccebe285bbe171',
            'thumbnail': r're:^https?://.*\.jpg$',
            'live_status': 'is_live',
            'view_count': int,
        },
        'params': {'skip_download': 'm3u8'},
        'skip': 'May not be online',
    }]

    def _real_extract(self, url):
        channel_name = self._match_id(url)
        response = self._download_json(f'https://api2.goodgame.ru/v2/streams/{channel_name}', channel_name)
        player_id = response['channel']['gg_player_src']

        formats, subtitles = [], {}
        if response.get('status') == 'Live':

Review comment (suggestion):
As the old URLs still work, let's also match them
```suggestion
    _VALID_URL = r'https?://goodgame\.ru/(?:channel/)?(?P<id>\w+)'
```

Code after:
from .common import InfoExtractor
from ..utils import (
    int_or_none,
    str_or_none,
    traverse_obj,
    url_or_none,
)


class GoodGameIE(InfoExtractor):
    IE_NAME = 'goodgame:stream'
    _VALID_URL = r'https?://goodgame\.ru/(?!channel/)(?P<id>[\w.*-]+)'
    _TESTS = [{
        'url': 'https://goodgame.ru/TGW#autoplay',
        'info_dict': {
            'id': '7998',
            'ext': 'mp4',
            'channel_id': '7998',
            'title': r're:шоуматч Happy \(NE\) vs Fortitude \(UD\), потом ладдер и дс \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
            'channel_url': 'https://goodgame.ru/TGW',
            'thumbnail': 'https://hls.goodgame.ru/previews/7998_240.jpg',
            'uploader': 'TGW',
            'channel': 'JosephStalin',
            'live_status': 'is_live',
            'age_limit': 18,
            'channel_follower_count': int,
            'uploader_id': '2899',
            'concurrent_view_count': int,
        },
        'params': {'skip_download': 'm3u8'},
    }, {
        'url': 'https://goodgame.ru/Mr.Gray',
        'only_matching': True,
    }, {
        'url': 'https://goodgame.ru/HeDoPa3yMeHue*',
        'only_matching': True,
    }]
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/goodgame.py (Python)

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


class GoodGameIE(InfoExtractor):
    IE_NAME = 'goodgame:stream'
    _VALID_URL = r'https?://goodgame\.ru/(?:channel/)?(?P<id>[\w.*-]+)'
    _TESTS = [{
        'url': 'https://goodgame.ru/Pomi#autoplay',
        'info_dict': {
            'id': 'pomi',
            'ext': 'mp4',
            'title': r're:Reynor vs Special \(1/2,bo3\) Wardi Spring EU \- playoff \(финальный день\) \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
            'channel_id': '1644',
            'channel': 'Pomi',
            'channel_url': 'https://goodgame.ru/Pomi',
            'description': 'md5:4a87b775ee7b2b57bdccebe285bbe171',
            'thumbnail': r're:^https?://.*\.jpg$',
            'live_status': 'is_live',
            'view_count': int,
        },
        'params': {'skip_download': 'm3u8'},
        'skip': 'May not be online',
    }]

    def _real_extract(self, url):
        channel_name = self._match_id(url)
        response = self._download_json(f'https://goodgame.ru/api/4/users/{channel_name}/stream', channel_name)
        player_id = response['streamkey']

        formats, subtitles = [], {}
        if response.get('status'):

Review comment (suggestion):
Okay, my bad we actually need to follow the redirects as channels can differ from the user
```suggestion
    _VALID_URL = r'https?://goodgame\.ru/(?P<id>[\w.*-]+)'
```
`https://goodgame.ru/channel/JosephStalin` -> `https://goodgame.ru/TGW`

Code after:
from .common import InfoExtractor
from ..utils import (
    int_or_none,
    str_or_none,
    traverse_obj,
    url_or_none,
)


class GoodGameIE(InfoExtractor):
    IE_NAME = 'goodgame:stream'
    _VALID_URL = r'https?://goodgame\.ru/(?!channel/)(?P<id>[\w.*-]+)'
    _TESTS = [{
        'url': 'https://goodgame.ru/TGW#autoplay',
        'info_dict': {
            'id': '7998',
            'ext': 'mp4',
            'channel_id': '7998',
            'title': r're:шоуматч Happy \(NE\) vs Fortitude \(UD\), потом ладдер и дс \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
            'channel_url': 'https://goodgame.ru/TGW',
            'thumbnail': 'https://hls.goodgame.ru/previews/7998_240.jpg',
            'uploader': 'TGW',
            'channel': 'JosephStalin',
            'live_status': 'is_live',
            'age_limit': 18,
            'channel_follower_count': int,
            'uploader_id': '2899',
            'concurrent_view_count': int,
        },
        'params': {'skip_download': 'm3u8'},
    }, {
        'url': 'https://goodgame.ru/Mr.Gray',
        'only_matching': True,
    }, {
        'url': 'https://goodgame.ru/HeDoPa3yMeHue*',
        'only_matching': True,
    }]
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/cwtv.py (Python)

Code before:
            'series': 'The Crush',
            'season': 'Season 1',
            'uploader': 'CWTV',
            'season_number': 1,
            'episode': 'Episode 1',
            'episode_number': 1,
            'thumbnail': r're:https?://.+\.jpe?g',
        },
        'params': {
            # m3u8 download
            'skip_download': True,
        },
    }]
    _UUID_RE = r'[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12}'

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        app_url = (
            self._html_search_meta('al:ios:url', webpage, default=None)
            or self._html_search_meta('al:android:url', webpage, default=None))
        video_id = (
            traverse_obj(parse_qs(app_url), ('video_id', 0, {lambda x: re.fullmatch(self._UUID_RE, x)}, 0))
            or self._search_regex([
                rf'CWTV\.Site\.curPlayingGUID\s*=\s*["\']({self._UUID_RE})["\']',
                rf'CWTV\.Site\.viewInAppURL\s*=\s*["\']/shows/[^/?#"\']+/watch-in-app/\?play=({self._UUID_RE})',
            ], webpage, 'video ID'))

        return self.url_result(
            f'https://www.cwtv.com/shows/{display_id}/{display_id}/?play={video_id}', CWTVIE, video_id)


Review comment (suggestion):
```suggestion
                rf'CWTV\.Site\.viewInAppURL\s*=\s*["\']/shows/[\w-]+/watch-in-app/\?play=({self._UUID_RE})',
```

Code after:
            'series': 'The Crush',
            'season': 'Season 1',
            'uploader': 'CWTV',
            'season_number': 1,
            'episode': 'Episode 1',
            'episode_number': 1,
            'thumbnail': r're:https?://.+\.jpe?g',
        },
        'params': {
            # m3u8 download
            'skip_download': True,
        },
    }]
    _UUID_RE = r'[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12}'

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        app_url = (
            self._html_search_meta('al:ios:url', webpage, default=None)
            or self._html_search_meta('al:android:url', webpage, default=None))
        video_id = (
            traverse_obj(parse_qs(app_url), ('video_id', 0, {lambda x: re.fullmatch(self._UUID_RE, x)}, 0))
            or self._search_regex([
                rf'CWTV\.Site\.curPlayingGUID\s*=\s*["\']({self._UUID_RE})',
                rf'CWTV\.Site\.viewInAppURL\s*=\s*["\']/shows/[\w-]+/watch-in-app/\?play=({self._UUID_RE})',
            ], webpage, 'video ID'))

        return self.url_result(
            f'https://www.cwtv.com/shows/{display_id}/{display_id}/?play={video_id}', CWTVIE, video_id)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/cwtv.py (Python)

Code before:
            'duration': 5337,
            'series': 'The Crush',
            'season': 'Season 1',
            'uploader': 'CWTV',
            'season_number': 1,
            'episode': 'Episode 1',
            'episode_number': 1,
            'thumbnail': r're:https?://.+\.jpe?g',
        },
        'params': {
            # m3u8 download
            'skip_download': True,
        },
    }]
    _UUID_RE = r'[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12}'

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        app_url = (
            self._html_search_meta('al:ios:url', webpage, default=None)
            or self._html_search_meta('al:android:url', webpage, default=None))
        video_id = (
            traverse_obj(parse_qs(app_url), ('video_id', 0, {lambda x: re.fullmatch(self._UUID_RE, x)}, 0))
            or self._search_regex([
                rf'CWTV\.Site\.curPlayingGUID\s*=\s*["\']({self._UUID_RE})["\']',
                rf'CWTV\.Site\.viewInAppURL\s*=\s*["\']/shows/[^/?#"\']+/watch-in-app/\?play=({self._UUID_RE})',
            ], webpage, 'video ID'))

        return self.url_result(
            f'https://www.cwtv.com/shows/{display_id}/{display_id}/?play={video_id}', CWTVIE, video_id)


Review comment (suggestion):
```suggestion
                rf'CWTV\.Site\.curPlayingGUID\s*=\s*["\']({self._UUID_RE})',
```

Code after:
            'duration': 5337,
            'series': 'The Crush',
            'season': 'Season 1',
            'uploader': 'CWTV',
            'season_number': 1,
            'episode': 'Episode 1',
            'episode_number': 1,
            'thumbnail': r're:https?://.+\.jpe?g',
        },
        'params': {
            # m3u8 download
            'skip_download': True,
        },
    }]
    _UUID_RE = r'[\da-f]{8}-(?:[\da-f]{4}-){3}[\da-f]{12}'

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        app_url = (
            self._html_search_meta('al:ios:url', webpage, default=None)
            or self._html_search_meta('al:android:url', webpage, default=None))
        video_id = (
            traverse_obj(parse_qs(app_url), ('video_id', 0, {lambda x: re.fullmatch(self._UUID_RE, x)}, 0))
            or self._search_regex([
                rf'CWTV\.Site\.curPlayingGUID\s*=\s*["\']({self._UUID_RE})',
                rf'CWTV\.Site\.viewInAppURL\s*=\s*["\']/shows/[\w-]+/watch-in-app/\?play=({self._UUID_RE})',
            ], webpage, 'video ID'))

        return self.url_result(
            f'https://www.cwtv.com/shows/{display_id}/{display_id}/?play={video_id}', CWTVIE, video_id)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/tvw.py (Python)

Code before:
import json

from .common import InfoExtractor
from ..networking.exceptions import HTTPError
from ..utils import ExtractorError, RegexNotFoundError, clean_html, traverse_obj, unified_timestamp


class TVWIE(InfoExtractor):
    BACKUP_API_KEY = '7WhiEBzijpritypp8bqcU7pfU9uicDR'

    _VALID_URL = r'https?://(?:www\.)?tvw\.org/video/(?P<id>[^/]+)'
    _TESTS = [{
        'url': 'https://tvw.org/video/billy-frank-jr-statue-maquette-unveiling-ceremony-2024011211/',
        'md5': '9ceb94fe2bb7fd726f74f16356825703',
        'info_dict': {
            'id': '2024011211',
            'ext': 'mp4',
            'title': 'Billy Frank Jr. Statue Maquette Unveiling Ceremony',
            'thumbnail': r're:^https?://.*\.jpg$',
            'description': 'md5:58a8150017d985b4f377e11ee8f6f36e',
            'timestamp': 1704902400,
            'upload_date': '20240110',
            'location': 'Legislative Building',
        }}, {
        'url': 'https://tvw.org/video/ebeys-landing-state-park-2024081007/',
        'md5': '71e87dae3deafd65d75ff3137b9a32fc',
        'info_dict': {
            'id': '2024081007',
            'ext': 'mp4',
            'title': 'Ebey\'s Landing State Park',
            'thumbnail': r're:^https?://.*\.jpg$',
            'description': 'md5:50c5bd73bde32fa6286a008dbc853386',
            'timestamp': 1724310900,
            'upload_date': '20240822',
            'location': 'Ebey’s Landing State Park',
        }},

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

Code after:
import json

from .common import InfoExtractor
from ..utils import clean_html, remove_end, unified_timestamp, url_or_none
from ..utils.traversal import traverse_obj


class TvwIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?tvw\.org/video/(?P<id>[^/?#]+)'

    _TESTS = [{
        'url': 'https://tvw.org/video/billy-frank-jr-statue-maquette-unveiling-ceremony-2024011211/',
        'md5': '9ceb94fe2bb7fd726f74f16356825703',
        'info_dict': {
            'id': '2024011211',
            'ext': 'mp4',
            'title': 'Billy Frank Jr. Statue Maquette Unveiling Ceremony',
            'thumbnail': r're:^https?://.*\.(?:jpe?g|png)$',
            'description': 'md5:58a8150017d985b4f377e11ee8f6f36e',
            'timestamp': 1704902400,
            'upload_date': '20240110',
            'location': 'Legislative Building',
            'display_id': 'billy-frank-jr-statue-maquette-unveiling-ceremony-2024011211',
            'categories': ['General Interest'],
        },
    }, {
        'url': 'https://tvw.org/video/ebeys-landing-state-park-2024081007/',
        'md5': '71e87dae3deafd65d75ff3137b9a32fc',
        'info_dict': {
            'id': '2024081007',
            'ext': 'mp4',
            'title': 'Ebey\'s Landing State Park',
            'thumbnail': r're:^https?://.*\.(?:jpe?g|png)$',
            'description': 'md5:50c5bd73bde32fa6286a008dbc853386',
            'timestamp': 1724310900,
            'upload_date': '20240822',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/azmedien.py (Python)

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


class AZMedienIE(InfoExtractor):
    IE_DESC = 'AZ Medien videos'
    _VALID_URL = r'''(?x)
                    https?://
                        (?:www\.|tv\.)?
                        (?:
                            telezueri\.ch|
                            telebaern\.tv|
                            telem1\.ch|
                            tvo-online\.ch
                        )/
                        [^/]+/
                        (?P<id>
                            [^/]+-\d+
                        )
                        (?:
                            \#video=
                            (?P<kaltura_id>
                                [_0-9a-z]+
                            )
                        )?
                    '''

    _TESTS = [{
        'url': 'https://tv.telezueri.ch/sonntalk/bundesrats-vakanzen-eu-rahmenabkommen-133214569',
        'info_dict': {
            'id': '1_anruz3wy',
            'ext': 'mp4',
            'title': 'Bundesrats-Vakanzen / EU-Rahmenabkommen',
            'uploader_id': 'TVOnline',
            'upload_date': '20180930',
            'timestamp': 1538328802,
            'view_count': int,
            'thumbnail': 'http://cfvod.kaltura.com/p/1719221/sp/171922100/thumbnail/entry_id/1_anruz3wy/version/100031',
            'duration': 1930,
        },
        'params': {

Review comment (suggestion):
```suggestion
                        [^/?#]+/
```

Code after:
from .common import InfoExtractor
from .kaltura import KalturaIE
from ..utils.traversal import require, traverse_obj


class AZMedienIE(InfoExtractor):
    IE_DESC = 'AZ Medien videos'
    _VALID_URL = r'''(?x)
                    https?://
                        (?:www\.|tv\.)?
                        (?:
                            telezueri\.ch|
                            telebaern\.tv|
                            telem1\.ch|
                            tvo-online\.ch
                        )/
                        [^/?#]+/
                        (?P<id>
                            [^/?#]+-\d+
                        )
                        (?:
                            \#video=
                            (?P<kaltura_id>
                                [_0-9a-z]+
                            )
                        )?
                    '''

    _TESTS = [{
        'url': 'https://tv.telezueri.ch/sonntalk/bundesrats-vakanzen-eu-rahmenabkommen-133214569',
        'info_dict': {
            'id': '1_anruz3wy',
            'ext': 'mp4',
            'title': 'Bundesrats-Vakanzen / EU-Rahmenabkommen',
            'uploader_id': 'TVOnline',
            'upload_date': '20180930',
            'timestamp': 1538328802,
            'view_count': int,
            'thumbnail': 'http://cfvod.kaltura.com/p/1719221/sp/171922100/thumbnail/entry_id/1_anruz3wy/version/100031',
            'duration': 1930,
        },
        'params': {
            'skip_download': True,
        },
    }, {