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

Code before:
        },
    }

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

        webpage = self._download_webpage(url, video_id=video_id)

        title = self._html_search_meta(['og:title', 'twitter:title'], webpage, fatal=True)
        description = self._html_search_meta(['og:description', 'twitter:description'], webpage, fatal=True)

        src_iframe = self._search_regex(r'\<iframe.*?src=\"(.*?)\"', webpage, 'src iframe')

        webpage_iframe = self._download_webpage(src_iframe.replace('player.php', 'config2.php'), video_id=video_id,
                                                headers={'Referer': src_iframe})

        sources = self._parse_json(
            js_to_json(self._search_regex(r'sources\:.*?(\[.*?\])', webpage_iframe, 'm3u8 source')), video_id=video_id)

        thumbnail = self._search_regex(r'image\:.*?\"(.*?)\"', webpage_iframe, 'thumbnail')

        formats = []

        for source in sources:
            file = source.get('file')
            if source.get('type') == 'm3u8':
                formats.extend(self._extract_m3u8_formats(urljoin(self._DOMAIN, file), video_id, 'mp4', fatal=False,
                                                          headers={'Referer': src_iframe}))
        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': title,
            'description': description,
            'thumbnail': thumbnail,
            'formats': formats,
        }


Review comment (suggestion):
```suggestion
            if file and source.get('type') == 'm3u8':
```

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

        src_iframe = self._search_regex(r'\<iframe[^>]+src="([^"]+)"', webpage, 'src iframe')
        webpage_iframe = self._download_webpage(
            src_iframe.replace('player.php', 'config2.php'), video_id, headers={'Referer': src_iframe})

        sources = self._parse_json(self._search_regex(
            r'sources\:\s*(\[.*?\])', webpage_iframe, 'm3u8 source'), video_id, transform_source=js_to_json)

        formats, subtitles = [], {}
        for source in sources:
            file = source.get('file')
            if file and source.get('type') == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(
                    urljoin('https://www.lightcast.com/embed/', file),
                    video_id, 'mp4', fatal=False, headers={'Referer': src_iframe})
                formats.extend(fmts)
                subtitles = self._merge_subtitles(subtitles, subs)
        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': self._html_search_meta(['og:title', 'twitter:title'], webpage),
            'description': self._html_search_meta(['og:description', 'twitter:description'], webpage),
            'thumbnail': self._search_regex(r'image:\s*"([^"]+)', webpage_iframe, 'thumbnail'),
            'formats': formats,
            'subtitles': subtitles,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/daystar.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import js_to_json, urljoin


class DaystarClipIE(InfoExtractor):
    IE_NAME = 'daystar:clip'
    _VALID_URL = r'https?:\/\/player\.daystar\.tv\/(?P<id>\w+)($|\W)'
    _DOMAIN = 'https://www.lightcast.com/embed/'
    _TEST = {
        'url': 'https://player.daystar.tv/0MTO2ITM',
        'info_dict': {
            'id': '0MTO2ITM',
            'ext': 'mp4',
            'title': 'The Dark World of COVID Pt. 1 | Aaron Siri',
            'description': 'Is the fear of the pandemic being used to suppress and erode your constitutional '
                           'freedoms? Attorney Aaron Siri exposes the truth about what’s happening and how you can '
                           'join the fight to preserve your liberties. (J2167)',
            'thumbnail': r're:^https?://.+\.jpg',
        },
    }

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

        webpage = self._download_webpage(url, video_id=video_id)

        title = self._html_search_meta(['og:title', 'twitter:title'], webpage, fatal=True)
        description = self._html_search_meta(['og:description', 'twitter:description'], webpage, fatal=True)

        src_iframe = self._search_regex(r'\<iframe.*?src=\"(.*?)\"', webpage, 'src iframe')

        webpage_iframe = self._download_webpage(src_iframe.replace('player.php', 'config2.php'), video_id=video_id,

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://player\.daystar\.tv/(?P<id>\w+)'
```

Code after:
from .common import InfoExtractor
from ..utils import js_to_json, urljoin


class DaystarClipIE(InfoExtractor):
    IE_NAME = 'daystar:clip'
    _VALID_URL = r'https?://player\.daystar\.tv/(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://player.daystar.tv/0MTO2ITM',
        'info_dict': {
            'id': '0MTO2ITM',
            'ext': 'mp4',
            'title': 'The Dark World of COVID Pt. 1 | Aaron Siri',
            'description': 'a420d320dda734e5f29458df3606c5f4',
            'thumbnail': r're:^https?://.+\.jpg',
        },
    }]

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

        src_iframe = self._search_regex(r'\<iframe[^>]+src="([^"]+)"', webpage, 'src iframe')
        webpage_iframe = self._download_webpage(
            src_iframe.replace('player.php', 'config2.php'), video_id, headers={'Referer': src_iframe})

        sources = self._parse_json(self._search_regex(
            r'sources\:\s*(\[.*?\])', webpage_iframe, 'm3u8 source'), video_id, transform_source=js_to_json)

        formats, subtitles = [], {}
        for source in sources:
            file = source.get('file')
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/daystar.py (Python)

Code before:
        video_id = self._match_id(url)
        src_iframe = self._search_regex(
            r'\<iframe[^>]+src="([^"]+)"', self._download_webpage(url, video_id), 'src iframe')

        webpage_iframe = self._download_webpage(
            src_iframe.replace('player.php', 'config2.php'), video_id, headers={'Referer': src_iframe})

        sources = self._parse_json(self._search_regex(
            r'sources\:[^>](\[.*?\])', webpage_iframe, 'm3u8 source'), video_id, transform_source=js_to_json)

        formats, subtitles = [], {}
        for source in sources:
            file = source.get('file')
            if file and source.get('type') == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(
                    urljoin('https://www.lightcast.com/embed/', file),
                    video_id, 'mp4', fatal=False, headers={'Referer': src_iframe})
                formats.extend(fmts)
                subtitles = self._merge_subtitles(subtitles, subs)
        self._sort_formats(formats)
        
        return {
            'id': video_id,
            'title': self._html_search_meta(['og:title', 'twitter:title'], webpage),
            'description': self._html_search_meta(['og:description', 'twitter:description'], webpage),
            'thumbnail': self._search_regex(r'image\:[^>]\"([^"]+)\"', webpage_iframe, 'thumbnail'),
            'formats': formats,
            'subtitles': subtitles,
        }


Review comment (suggestion):
did u mean this?
```suggestion
            'thumbnail': self._search_regex(r'image:\s*"([^"]+)', webpage_iframe, 'thumbnail'),
```

Code after:
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)

        src_iframe = self._search_regex(r'\<iframe[^>]+src="([^"]+)"', webpage, 'src iframe')
        webpage_iframe = self._download_webpage(
            src_iframe.replace('player.php', 'config2.php'), video_id, headers={'Referer': src_iframe})

        sources = self._parse_json(self._search_regex(
            r'sources\:\s*(\[.*?\])', webpage_iframe, 'm3u8 source'), video_id, transform_source=js_to_json)

        formats, subtitles = [], {}
        for source in sources:
            file = source.get('file')
            if file and source.get('type') == 'm3u8':
                fmts, subs = self._extract_m3u8_formats_and_subtitles(
                    urljoin('https://www.lightcast.com/embed/', file),
                    video_id, 'mp4', fatal=False, headers={'Referer': src_iframe})
                formats.extend(fmts)
                subtitles = self._merge_subtitles(subtitles, subs)
        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': self._html_search_meta(['og:title', 'twitter:title'], webpage),
            'description': self._html_search_meta(['og:description', 'twitter:description'], webpage),
            'thumbnail': self._search_regex(r'image:\s*"([^"]+)', webpage_iframe, 'thumbnail'),
            'formats': formats,
            'subtitles': subtitles,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mildom.py (Python)

Code before:
        'info_dict': {
            'id': '10093333',
            'title': 'Uploads from ねこばたけ',
        },
        'playlist_mincount': 732,
    }, {
        'url': 'https://www.mildom.com/profile/10882672',
        'info_dict': {
            'id': '10882672',
            'title': 'Uploads from kson組長(けいそん)',
        },
        'playlist_mincount': 201,
    }]

    def _fetch_page(self, user_id, page):
        page += 1
        reply = self._call_api(
            'https://cloudac.mildom.com/nonolive/videocontent/profile/playbackList',
            user_id, note=f'Downloading page {page}', query={
                'user_id': user_id,
                'page': page,
                'limit': '30',
            })
        if not reply:
            return
        yield from (self.url_result(f'https://www.mildom.com/playback/{user_id}/{x["v_id"]}') for x in reply)

    def _real_extract(self, url):
        user_id = self._match_id(url)
        self.to_screen('This will download all VODs belonging to user. To download ongoing live video, use "https://www.mildom.com/%s" instead' % user_id)

        profile = self._call_api(
            'https://cloudac.mildom.com/nonolive/gappserv/user/profileV2', user_id,
            query={'user_id': user_id}, note='Downloading user profile')['user_info']

        return self.playlist_result(
            OnDemandPagedList(functools.partial(self._fetch_page, user_id), 30),
            user_id, f'Uploads from {profile["loginname"]}')


Review comment (suggestion):
```suggestion
        for x in reply:
            yield self.url_result(f'https://www.mildom.com/playback/{user_id}/{x["v_id"]}')
```

Code after:
        page += 1
        reply = self._call_api(
            'https://cloudac.mildom.com/nonolive/videocontent/profile/playbackList',
            user_id, note=f'Downloading page {page}', query={
                'user_id': user_id,
                'page': page,
                'limit': '30',
            })
        if not reply:
            return
        for x in reply:
            v_id = x.get('v_id')
            if not v_id:
                continue
            yield self.url_result(f'https://www.mildom.com/playback/{user_id}/{v_id}')

    def _real_extract(self, url):
        user_id = self._match_id(url)
        self.to_screen('This will download all VODs belonging to user. To download ongoing live video, use "https://www.mildom.com/%s" instead' % user_id)

        profile = self._call_api(
            'https://cloudac.mildom.com/nonolive/gappserv/user/profileV2', user_id,
            query={'user_id': user_id}, note='Downloading user profile')['user_info']

        return self.playlist_result(
            OnDemandPagedList(functools.partial(self._fetch_page, user_id), 30),
            user_id, f'Uploads from {profile["loginname"]}')
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mildom.py (Python)

Code before:
            'id': '10093333',
            'title': 'Uploads from ねこばたけ',
        },
        'playlist_mincount': 732,
    }, {
        'url': 'https://www.mildom.com/profile/10882672',
        'info_dict': {
            'id': '10882672',
            'title': 'Uploads from kson組長(けいそん)',
        },
        'playlist_mincount': 201,
    }]

    def _fetch_page(self, user_id, page):
        page += 1
        reply = self._call_api(
            'https://cloudac.mildom.com/nonolive/videocontent/profile/playbackList',
            user_id, note=f'Downloading page {page}', query={
                'user_id': user_id,
                'page': page,
                'limit': '30',
            })
        if not reply:
            return
        for x in reply:
            yield self.url_result(f'https://www.mildom.com/playback/{user_id}/{x["v_id"]}')

    def _real_extract(self, url):
        user_id = self._match_id(url)
        self.to_screen('This will download all VODs belonging to user. To download ongoing live video, use "https://www.mildom.com/%s" instead' % user_id)

        profile = self._call_api(
            'https://cloudac.mildom.com/nonolive/gappserv/user/profileV2', user_id,
            query={'user_id': user_id}, note='Downloading user profile')['user_info']

        return self.playlist_result(
            OnDemandPagedList(functools.partial(self._fetch_page, user_id), 30),
            user_id, f'Uploads from {profile["loginname"]}')


Review comment (suggestion):
```suggestion
        for x in reply:
            v_id = x.get('v_id')
            if not v_id:
                continue
            yield self.url_result(f'https://www.mildom.com/playback/{user_id}/{v_id}')
```

Code after:
    }]

    def _fetch_page(self, user_id, page):
        page += 1
        reply = self._call_api(
            'https://cloudac.mildom.com/nonolive/videocontent/profile/playbackList',
            user_id, note=f'Downloading page {page}', query={
                'user_id': user_id,
                'page': page,
                'limit': '30',
            })
        if not reply:
            return
        for x in reply:
            v_id = x.get('v_id')
            if not v_id:
                continue
            yield self.url_result(f'https://www.mildom.com/playback/{user_id}/{v_id}')

    def _real_extract(self, url):
        user_id = self._match_id(url)
        self.to_screen('This will download all VODs belonging to user. To download ongoing live video, use "https://www.mildom.com/%s" instead' % user_id)

        profile = self._call_api(
            'https://cloudac.mildom.com/nonolive/gappserv/user/profileV2', user_id,
            query={'user_id': user_id}, note='Downloading user profile')['user_info']

        return self.playlist_result(
            OnDemandPagedList(functools.partial(self._fetch_page, user_id), 30),
            user_id, f'Uploads from {profile["loginname"]}')
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/fptplay.py (Python)

Code before:
        r = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
        for o in range(len(t) // 2):
            n.append(int(f'0x{t[2 * o: 2 * o + 2]}', 16))

        def convert(e):
            t = ''
            n = 0
            i = [0, 0, 0]
            a = [0, 0, 0, 0]
            s = len(e)
            c = 0
            for z in range(s, 0, -1):
                if n <= 3:
                    i[n] = e[c]
                n += 1
                c += 1
                if 3 == n:
                    a[0] = (252 & i[0]) >> 2
                    a[1] = ((3 & i[0]) << 4) + ((240 & i[1]) >> 4)
                    a[2] = ((15 & i[1]) << 2) + ((192 & i[2]) >> 6)
                    a[3] = (63 & i[2])
                    for v in range(4):
                        t += r[a[v]]
                    n = 0
            if n:
                for o in range(n, 3, 1):
                    i[o] = 0

                for o in range(n + 1):
                    a[0] = (252 & i[0]) >> 2
                    a[1] = ((3 & i[0]) << 4) + ((240 & i[1]) >> 4)
                    a[2] = ((15 & i[1]) << 2) + ((192 & i[2]) >> 6)
                    a[3] = (63 & i[2])
                    t += r[a[o]]
                n += 1
                while n < 3:
                    t += ''
                    n += 1
            return t

        return convert(n).replace('+', '-').replace('/', '_').replace('=', '')


Review comment (suggestion):
```suggestion
                for o in range(n, 3):
```

Code after:
        t = hashlib.md5(f'WEBv6Dkdsad90dasdjlALDDDS{timestamp}{path}'.encode()).hexdigest().upper()
        r = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
        n = [int(f'0x{t[2 * o: 2 * o + 2]}', 16) for o in range(len(t) // 2)]

        def convert(e):
            t = ''
            n = 0
            i = [0, 0, 0]
            a = [0, 0, 0, 0]
            s = len(e)
            c = 0
            for z in range(s, 0, -1):
                if n <= 3:
                    i[n] = e[c]
                n += 1
                c += 1
                if 3 == n:
                    a[0] = (252 & i[0]) >> 2
                    a[1] = ((3 & i[0]) << 4) + ((240 & i[1]) >> 4)
                    a[2] = ((15 & i[1]) << 2) + ((192 & i[2]) >> 6)
                    a[3] = (63 & i[2])
                    for v in range(4):
                        t += r[a[v]]
                    n = 0
            if n:
                for o in range(n, 3):
                    i[o] = 0

                for o in range(n + 1):
                    a[0] = (252 & i[0]) >> 2
                    a[1] = ((3 & i[0]) << 4) + ((240 & i[1]) >> 4)
                    a[2] = ((15 & i[1]) << 2) + ((192 & i[2]) >> 6)
                    a[3] = (63 & i[2])
                    t += r[a[o]]
                n += 1
                while n < 3:
                    t += ''
                    n += 1
            return t

        st_token = convert(n).replace('+', '-').replace('/', '_').replace('=', '')
        return f'https://api.fptplay.net{path}?{urllib.parse.urlencode({"st": st_token, "e": timestamp})}'
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/banbye.py (Python)

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


from .common import InfoExtractor
from ..utils import unified_timestamp


class BanByeBaseIE(InfoExtractor):
    _API_BASE = 'https://api.banbye.com'
    _CDN_BASE = 'https://cdn.banbye.com'

    def _extract_playlist(self, playlist_id):
        data = self._download_json('%s/playlists/%s' % (self._API_BASE, playlist_id), playlist_id)
        return self.playlist_result([
            self.url_result('https://banbye.com/watch/%s' % video_id, ie_key='BanBye')
            for video_id in data['videoIds']], playlist_id, data['name'])


class BanByeIE(BanByeBaseIE):
    _VALID_URL = r'''(?x)
                    https?://
                        (?:www\.)?banbye.com/
                        (?:en/)?watch/
                        (?P<id>[^/?\#&]+)/?
                        \??(?:playlistId=(?P<playlist_id>[^/?\#&]+))?'''
    _TESTS = [{
        'url': 'https://banbye.com/watch/v_ytfmvkVYLE8T',
        'md5': '2f4ea15c5ca259a73d909b2cfd558eb5',
        'info_dict': {
            'id': 'v_ytfmvkVYLE8T',
            'ext': 'mp4',
            'title': 'md5:5ec098f88a0d796f987648de6322ba0f',
            'description': 'md5:4d94836e73396bc18ef1fa0f43e5a63a',
            'uploader': 'wRealu24',
            'channel_id': 'ch_wrealu24',
            'channel_url': 'https://banbye.com/channel/ch_wrealu24',
            'timestamp': 1647604800,
            'upload_date': '20220318',
            'duration': 1931,
            'thumbnail': r're:https?://.*\.webp',

Review comment (suggestion):
```suggestion
            self.url_result(f'https://banbye.com/watch/{video_id}', BanByeIE)
```

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

import math

from .common import InfoExtractor
from ..compat import (
    compat_urllib_parse_urlparse,
    compat_parse_qs,
)
from ..utils import (
    format_field,
    InAdvancePagedList,
    traverse_obj,
    unified_timestamp,
)


class BanByeBaseIE(InfoExtractor):
    _API_BASE = 'https://api.banbye.com'
    _CDN_BASE = 'https://cdn.banbye.com'
    _VIDEO_BASE = 'https://banbye.com/watch'

    @staticmethod
    def _extract_playlist_id(url, param='playlist'):
        return compat_parse_qs(
            compat_urllib_parse_urlparse(url).query).get(param, [None])[0]

    def _extract_playlist(self, playlist_id):
        data = self._download_json(f'{self._API_BASE}/playlists/{playlist_id}', playlist_id)
        return self.playlist_result([
            self.url_result(f'{self._VIDEO_BASE}/{video_id}', BanByeIE)
            for video_id in data['videoIds']], playlist_id, data.get('name'))


class BanByeIE(BanByeBaseIE):
    _VALID_URL = r'https?://(?:www\.)?banbye.com/(?:en/)?watch/(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://banbye.com/watch/v_ytfmvkVYLE8T',
        'md5': '2f4ea15c5ca259a73d909b2cfd558eb5',
        'info_dict': {
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/banbye.py (Python)

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


from .common import InfoExtractor
from ..utils import unified_timestamp


class BanByeBaseIE(InfoExtractor):
    _API_BASE = 'https://api.banbye.com'
    _CDN_BASE = 'https://cdn.banbye.com'

    def _extract_playlist(self, playlist_id):
        data = self._download_json('%s/playlists/%s' % (self._API_BASE, playlist_id), playlist_id)
        return self.playlist_result([
            self.url_result('https://banbye.com/watch/%s' % video_id, ie_key='BanBye')
            for video_id in data['videoIds']], playlist_id, data['name'])


class BanByeIE(BanByeBaseIE):
    _VALID_URL = r'''(?x)
                    https?://
                        (?:www\.)?banbye.com/
                        (?:en/)?watch/
                        (?P<id>[^/?\#&]+)/?
                        \??(?:playlistId=(?P<playlist_id>[^/?\#&]+))?'''
    _TESTS = [{
        'url': 'https://banbye.com/watch/v_ytfmvkVYLE8T',
        'md5': '2f4ea15c5ca259a73d909b2cfd558eb5',
        'info_dict': {
            'id': 'v_ytfmvkVYLE8T',
            'ext': 'mp4',
            'title': 'md5:5ec098f88a0d796f987648de6322ba0f',
            'description': 'md5:4d94836e73396bc18ef1fa0f43e5a63a',
            'uploader': 'wRealu24',
            'channel_id': 'ch_wrealu24',
            'channel_url': 'https://banbye.com/channel/ch_wrealu24',
            'timestamp': 1647604800,
            'upload_date': '20220318',
            'duration': 1931,
            'thumbnail': r're:https?://.*\.webp',
            'tags': 'count:5',

Review comment (suggestion):
```suggestion
            for video_id in data['videoIds']], playlist_id, data.get('name'))
```

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

import math

from .common import InfoExtractor
from ..compat import (
    compat_urllib_parse_urlparse,
    compat_parse_qs,
)
from ..utils import (
    format_field,
    InAdvancePagedList,
    traverse_obj,
    unified_timestamp,
)


class BanByeBaseIE(InfoExtractor):
    _API_BASE = 'https://api.banbye.com'
    _CDN_BASE = 'https://cdn.banbye.com'
    _VIDEO_BASE = 'https://banbye.com/watch'

    @staticmethod
    def _extract_playlist_id(url, param='playlist'):
        return compat_parse_qs(
            compat_urllib_parse_urlparse(url).query).get(param, [None])[0]

    def _extract_playlist(self, playlist_id):
        data = self._download_json(f'{self._API_BASE}/playlists/{playlist_id}', playlist_id)
        return self.playlist_result([
            self.url_result(f'{self._VIDEO_BASE}/{video_id}', BanByeIE)
            for video_id in data['videoIds']], playlist_id, data.get('name'))


class BanByeIE(BanByeBaseIE):
    _VALID_URL = r'https?://(?:www\.)?banbye.com/(?:en/)?watch/(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://banbye.com/watch/v_ytfmvkVYLE8T',
        'md5': '2f4ea15c5ca259a73d909b2cfd558eb5',
        'info_dict': {
            'id': 'v_ytfmvkVYLE8T',