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

Code before:

    _TESTS = [{
        'url': 'https://www.ondemandkorea.com/player/vod/uskn-news',
        'info_dict': {
            'id': 'uskn-news',
        },
        'playlist_mincount': 755,
    }, {
        'url': 'https://www.ondemandkorea.com/en/player/vod/the-land',
        'info_dict': {
            'id': 'the-land',
        },
        'playlist_count': 52,
    }]

    _PAGE_SIZE = 100

    def _fetch_page(self, display_id, page):
        page += 1
        page_data = self._download_json(
            f'https://odkmedia.io/odx/api/v3/program/{display_id}/episodes/', display_id,
            headers={'service-name': 'odk'}, query={
                'page': page,
                'page_size': self._PAGE_SIZE,
            }, note=f'Downloading page {page}')
        for episode in traverse_obj(page_data, ('result', 'results')):
            yield self.url_result(
                f'https://www.ondemandkorea.com/player/vod/{display_id}?contentId={episode["id"]}',
                ie=OnDemandKoreaIE, video_title=episode.get('title')
            )

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

        entries = OnDemandPagedList(functools.partial(
            self._fetch_page, display_id), self._PAGE_SIZE)

        return self.playlist_result(entries, display_id)


Review comment (refactor):
branch here to ensure list

you could filter an `'id'` key instead of `...`, if you want, depending if you want the extractor to error or not when it's not found
```suggestion
        for episode in traverse_obj(page_data, ('result', 'results', ...)):
```

Code after:

class OnDemandKoreaProgramIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?ondemandkorea\.com/(?:en/)?player/vod/(?P<id>[a-z0-9-]+)(?:$|#)'
    _GEO_COUNTRIES = ['US', 'CA']

    _TESTS = [{
        'url': 'https://www.ondemandkorea.com/player/vod/uskn-news',
        'info_dict': {
            'id': 'uskn-news',
        },
        'playlist_mincount': 755,
    }, {
        'url': 'https://www.ondemandkorea.com/en/player/vod/the-land',
        'info_dict': {
            'id': 'the-land',
        },
        'playlist_count': 52,
    }]

    _PAGE_SIZE = 100

    def _fetch_page(self, display_id, page):
        page += 1
        page_data = self._download_json(
            f'https://odkmedia.io/odx/api/v3/program/{display_id}/episodes/', display_id,
            headers={'service-name': 'odk'}, query={
                'page': page,
                'page_size': self._PAGE_SIZE,
            }, note=f'Downloading page {page}', expected_status=404)
        for episode in traverse_obj(page_data, ('result', 'results', ...)):
            yield self.url_result(
                f'https://www.ondemandkorea.com/player/vod/{display_id}?contentId={episode["id"]}',
                ie=OnDemandKoreaIE, video_title=episode.get('title'))

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

        entries = OnDemandPagedList(functools.partial(
            self._fetch_page, display_id), self._PAGE_SIZE)

        return self.playlist_result(entries, display_id)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/ondemandkorea.py (Python)

Code before:
            'id': 'uskn-news',
        },
        'playlist_mincount': 755,
    }, {
        'url': 'https://www.ondemandkorea.com/en/player/vod/the-land',
        'info_dict': {
            'id': 'the-land',
        },
        'playlist_count': 52,
    }]

    _PAGE_SIZE = 100

    def _fetch_page(self, display_id, page):
        page += 1
        page_data = self._download_json(
            f'https://odkmedia.io/odx/api/v3/program/{display_id}/episodes/', display_id,
            headers={'service-name': 'odk'}, query={
                'page': page,
                'page_size': self._PAGE_SIZE,
            }, note=f'Downloading page {page}')
        for episode in traverse_obj(page_data, ('result', 'results')):
            yield self.url_result(
                f'https://www.ondemandkorea.com/player/vod/{display_id}?contentId={episode["id"]}',
                ie=OnDemandKoreaIE, video_title=episode.get('title')
            )

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

        entries = OnDemandPagedList(functools.partial(
            self._fetch_page, display_id), self._PAGE_SIZE)

        return self.playlist_result(entries, display_id)


Review comment (suggestion):
```suggestion
                ie=OnDemandKoreaIE, video_title=episode.get('title'))
```

Code after:

    _TESTS = [{
        'url': 'https://www.ondemandkorea.com/player/vod/uskn-news',
        'info_dict': {
            'id': 'uskn-news',
        },
        'playlist_mincount': 755,
    }, {
        'url': 'https://www.ondemandkorea.com/en/player/vod/the-land',
        'info_dict': {
            'id': 'the-land',
        },
        'playlist_count': 52,
    }]

    _PAGE_SIZE = 100

    def _fetch_page(self, display_id, page):
        page += 1
        page_data = self._download_json(
            f'https://odkmedia.io/odx/api/v3/program/{display_id}/episodes/', display_id,
            headers={'service-name': 'odk'}, query={
                'page': page,
                'page_size': self._PAGE_SIZE,
            }, note=f'Downloading page {page}', expected_status=404)
        for episode in traverse_obj(page_data, ('result', 'results', ...)):
            yield self.url_result(
                f'https://www.ondemandkorea.com/player/vod/{display_id}?contentId={episode["id"]}',
                ie=OnDemandKoreaIE, video_title=episode.get('title'))

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

        entries = OnDemandPagedList(functools.partial(
            self._fetch_page, display_id), self._PAGE_SIZE)

        return self.playlist_result(entries, display_id)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/laxarxames.py (Python)

Code before:
import json

from .brightcove import BrightcoveNewIE
from .common import InfoExtractor


class LaXarxaMesIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/]+/)*?(player|movie-details)/(?P<id>[0-9]+)'
    _NETRC_MACHINE = 'laxarxames'
    _TOKEN = None
    _LOGIN_URL = 'https://www.laxarxames.cat/login'
    _TESTS = [{
        'url': 'https://www.laxarxames.cat/player/3459421',
        'md5': '0966f46c34275934c19af78f3df6e2bc',
        'info_dict': {
            'id': '3459421',
            'ext': 'mp4',
            'title': 'Resum | UA Horta — UD Viladecans',
            'type': 'video/mp4',
        },
        'skip': 'Requires login',
    }]

    def _perform_login(self, username, password):
        if self._TOKEN:
            return
        login = self._download_json(
            'https://api.laxarxames.cat/Authorization/SignIn', None, note='Logging in', headers={
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
                'Accept': 'application/json, text/plain, */*',
                'Origin': 'https://www.laxarxames.cat',
            }, data=json.dumps({

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/]+/)*?(player|movie-details)/(?P<id>\d+)'
```

Code after:
import json

from .brightcove import BrightcoveNewIE
from .common import InfoExtractor
from ..utils import ExtractorError
from ..utils.traversal import traverse_obj


class LaXarxaMesIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/?#]+/)*?(player|movie-details)/(?P<id>\d+)'
    _NETRC_MACHINE = 'laxarxames'
    _TOKEN = None
    _TESTS = [{
        'url': 'https://www.laxarxames.cat/player/3459421',
        'md5': '0966f46c34275934c19af78f3df6e2bc',
        'info_dict': {
            'id': '6339612436112',
            'ext': 'mp4',
            'title': 'Resum | UA Horta — UD Viladecans',
            'timestamp': 1697905186,
            'thumbnail': r're:https?://.*\.jpg',
            'description': '',
            'upload_date': '20231021',
            'duration': 129.44,
            'tags': ['ott', 'esports', '23-24', ' futbol', ' futbol-partits', 'elit', 'resum'],
            'uploader_id': '5779379807001',
        },
        'skip': 'Requires login',
    }]

    def _perform_login(self, username, password):
        if self._TOKEN:
            return
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/laxarxames.py (Python)

Code before:
        video_id = self._match_id(url)

        if not self._TOKEN:
            self.raise_login_required()
        mediaplayinfo = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo',
            video_id,
            data=json.dumps({
                'MediaId': int(video_id),
                'StreamType': 'MAIN'
            }).encode('utf-8'),
            headers={
                'Authorization': 'Bearer ' + self._TOKEN,
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
                'Accept': 'application/json, text/plain, */*',
                'Origin': 'https://www.laxarxames.cat',
            }
        )

        content_url = mediaplayinfo['ContentUrl']
        video_title = mediaplayinfo['Title']

        return self.url_result(
            f'http://players.brightcove.net/5779379807001/default_default/index.html?videoId={content_url}',
            BrightcoveNewIE, video_id, video_title)


Review comment (suggestion):
```suggestion
        if not mediaplayinfo.get('ContentUrl'):
            self.raise_no_formats('No video found', expected=True)

        return self.url_result(
            f'http://players.brightcove.net/5779379807001/default_default/index.html?videoId={mediaplayinfo["ContentUrl"]}',
            BrightcoveNewIE, video_id, mediaplayinfo.get('Title'))
```

Code after:
        if not self._TOKEN:
            raise ExtractorError('Login failed', expected=True)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        if not self._TOKEN:
            self.raise_login_required()

        media_play_info = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
            data=json.dumps({
                'MediaId': int(video_id),
                'StreamType': 'MAIN'
            }).encode(), headers={
                'Authorization': f'Bearer {self._TOKEN}',
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
            })

        if not traverse_obj(media_play_info, ('ContentUrl', {str})):
            self.raise_no_formats('No video found', expected=True)

        return self.url_result(
            f'https://players.brightcove.net/5779379807001/default_default/index.html?videoId={media_play_info["ContentUrl"]}',
            BrightcoveNewIE, video_id, media_play_info.get('Title'))
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/laxarxames.py (Python)

Code before:
import json

from .brightcove import BrightcoveNewIE
from .common import InfoExtractor
from ..utils import ExtractorError
from ..utils.traversal import traverse_obj


class LaXarxaMesIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/]+/)*?(player|movie-details)/(?P<id>\d+)'
    _NETRC_MACHINE = 'laxarxames'
    _TOKEN = None
    _LOGIN_URL = 'https://www.laxarxames.cat/login'
    _TESTS = [{
        'url': 'https://www.laxarxames.cat/player/3459421',
        'md5': '0966f46c34275934c19af78f3df6e2bc',
        'info_dict': {
            'id': '6339612436112',
            'ext': 'mp4',
            'title': 'Resum | UA Horta — UD Viladecans',
            'timestamp': 1697905186,
            'thumbnail': r're:https?://.*\.jpg',
            'description': '',
            'upload_date': '20231021',
            'duration': 129.44,
            'tags': ['ott', 'esports', '23-24', ' futbol', ' futbol-partits', 'elit', 'resum'],
            'uploader_id': '5779379807001',
        },
        'skip': 'Requires login',
    }]

    def _perform_login(self, username, password):
        if self._TOKEN:
            return
        login = self._download_json(

Review comment (suggestion):
don't match query/fragment with the character class
```suggestion
    _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/?#]+/)*?(player|movie-details)/(?P<id>\d+)'
```

Code after:
import json

from .brightcove import BrightcoveNewIE
from .common import InfoExtractor
from ..utils import ExtractorError
from ..utils.traversal import traverse_obj


class LaXarxaMesIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?laxarxames\.cat/(?:[^/?#]+/)*?(player|movie-details)/(?P<id>\d+)'
    _NETRC_MACHINE = 'laxarxames'
    _TOKEN = None
    _TESTS = [{
        'url': 'https://www.laxarxames.cat/player/3459421',
        'md5': '0966f46c34275934c19af78f3df6e2bc',
        'info_dict': {
            'id': '6339612436112',
            'ext': 'mp4',
            'title': 'Resum | UA Horta — UD Viladecans',
            'timestamp': 1697905186,
            'thumbnail': r're:https?://.*\.jpg',
            'description': '',
            'upload_date': '20231021',
            'duration': 129.44,
            'tags': ['ott', 'esports', '23-24', ' futbol', ' futbol-partits', 'elit', 'resum'],
            'uploader_id': '5779379807001',
        },
        'skip': 'Requires login',
    }]

    def _perform_login(self, username, password):
        if self._TOKEN:
            return

        login = self._download_json(
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/laxarxames.py (Python)

Code before:
                'Password': password,
                'Device': {
                    'PlatformCode': 'WEB',
                    'Name': 'Mac OS ()',
                },
            }).encode('utf-8'),
            expected_status=401,
        )

        if not traverse_obj(login, ('AuthorizationToken', 'Token')):
            raise ExtractorError('Login failed', expected=True)
        else:
            self._TOKEN = login['AuthorizationToken']['Token']

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

        if not self._TOKEN:
            self.raise_login_required()
        mediaplayinfo = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
            data=json.dumps({
                'MediaId': int(video_id),
                'StreamType': 'MAIN'
            }).encode('utf-8'),
            headers={
                'Authorization': 'Bearer ' + self._TOKEN,
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
            }
        )

        if not mediaplayinfo.get('ContentUrl'):
            self.raise_no_formats('No video found', expected=True)
        return self.url_result(
            f'http://players.brightcove.net/5779379807001/default_default/index.html?videoId={mediaplayinfo["ContentUrl"]}',
            BrightcoveNewIE, video_id, mediaplayinfo.get('Title'))


Review comment (suggestion):
```suggestion
            }).encode(), headers={
```

Code after:
                'Password': password,
                'Device': {
                    'PlatformCode': 'WEB',
                    'Name': 'Mac OS ()',
                },
            }).encode(), expected_status=401)

        self._TOKEN = traverse_obj(login, ('AuthorizationToken', 'Token', {str}))
        if not self._TOKEN:
            raise ExtractorError('Login failed', expected=True)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        if not self._TOKEN:
            self.raise_login_required()

        media_play_info = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
            data=json.dumps({
                'MediaId': int(video_id),
                'StreamType': 'MAIN'
            }).encode(), headers={
                'Authorization': f'Bearer {self._TOKEN}',
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
            })

        if not traverse_obj(media_play_info, ('ContentUrl', {str})):
            self.raise_no_formats('No video found', expected=True)

        return self.url_result(
            f'https://players.brightcove.net/5779379807001/default_default/index.html?videoId={media_play_info["ContentUrl"]}',
            BrightcoveNewIE, video_id, media_play_info.get('Title'))
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/laxarxames.py (Python)

Code before:
                'Device': {
                    'PlatformCode': 'WEB',
                    'Name': 'Mac OS ()',
                },
            }).encode('utf-8'),
            expected_status=401,
        )

        if not traverse_obj(login, ('AuthorizationToken', 'Token')):
            raise ExtractorError('Login failed', expected=True)
        else:
            self._TOKEN = login['AuthorizationToken']['Token']

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

        if not self._TOKEN:
            self.raise_login_required()
        mediaplayinfo = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
            data=json.dumps({
                'MediaId': int(video_id),
                'StreamType': 'MAIN'
            }).encode('utf-8'),
            headers={
                'Authorization': 'Bearer ' + self._TOKEN,
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
            }
        )

        if not mediaplayinfo.get('ContentUrl'):
            self.raise_no_formats('No video found', expected=True)
        return self.url_result(
            f'http://players.brightcove.net/5779379807001/default_default/index.html?videoId={mediaplayinfo["ContentUrl"]}',
            BrightcoveNewIE, video_id, mediaplayinfo.get('Title'))


Review comment (security):
f-string
```suggestion
                'Authorization': f'Bearer {self._TOKEN}',
```

Code after:
                'Device': {
                    'PlatformCode': 'WEB',
                    'Name': 'Mac OS ()',
                },
            }).encode(), expected_status=401)

        self._TOKEN = traverse_obj(login, ('AuthorizationToken', 'Token', {str}))
        if not self._TOKEN:
            raise ExtractorError('Login failed', expected=True)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        if not self._TOKEN:
            self.raise_login_required()

        media_play_info = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
            data=json.dumps({
                'MediaId': int(video_id),
                'StreamType': 'MAIN'
            }).encode(), headers={
                'Authorization': f'Bearer {self._TOKEN}',
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
            })

        if not traverse_obj(media_play_info, ('ContentUrl', {str})):
            self.raise_no_formats('No video found', expected=True)

        return self.url_result(
            f'https://players.brightcove.net/5779379807001/default_default/index.html?videoId={media_play_info["ContentUrl"]}',
            BrightcoveNewIE, video_id, media_play_info.get('Title'))
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/laxarxames.py (Python)

Code before:
        )

        if not traverse_obj(login, ('AuthorizationToken', 'Token')):
            raise ExtractorError('Login failed', expected=True)
        else:
            self._TOKEN = login['AuthorizationToken']['Token']

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

        if not self._TOKEN:
            self.raise_login_required()
        mediaplayinfo = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
            data=json.dumps({
                'MediaId': int(video_id),
                'StreamType': 'MAIN'
            }).encode('utf-8'),
            headers={
                'Authorization': 'Bearer ' + self._TOKEN,
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
            }
        )

        if not mediaplayinfo.get('ContentUrl'):
            self.raise_no_formats('No video found', expected=True)
        return self.url_result(
            f'http://players.brightcove.net/5779379807001/default_default/index.html?videoId={mediaplayinfo["ContentUrl"]}',
            BrightcoveNewIE, video_id, mediaplayinfo.get('Title'))


Review comment (suggestion):
```suggestion
        if not traverse_obj(media_play_info, ('ContentUrl', {str})):
```

Code after:
        self._TOKEN = traverse_obj(login, ('AuthorizationToken', 'Token', {str}))
        if not self._TOKEN:
            raise ExtractorError('Login failed', expected=True)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        if not self._TOKEN:
            self.raise_login_required()

        media_play_info = self._download_json(
            'https://api.laxarxames.cat/Media/GetMediaPlayInfo', video_id,
            data=json.dumps({
                'MediaId': int(video_id),
                'StreamType': 'MAIN'
            }).encode(), headers={
                'Authorization': f'Bearer {self._TOKEN}',
                'X-Tenantorigin': 'https://laxarxames.cat',
                'Content-Type': 'application/json',
            })

        if not traverse_obj(media_play_info, ('ContentUrl', {str})):
            self.raise_no_formats('No video found', expected=True)

        return self.url_result(
            f'https://players.brightcove.net/5779379807001/default_default/index.html?videoId={media_play_info["ContentUrl"]}',
            BrightcoveNewIE, video_id, media_play_info.get('Title'))