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

Code before:
from yt_dlp.utils._utils import unified_strdate

from .common import InfoExtractor
from ..networking import HEADRequest
from ..utils import (
    UserNotLive,
    determine_ext,
    float_or_none,
    int_or_none,
    merge_dicts,
    traverse_obj,
    unified_timestamp,
    url_or_none,
)

# Routes ----------------------

# Clips
# https://kick.com/mxddy?clip=clip_01GYXVB5Y8PWAPWCWMSBCFB05X
# https://kick.com/api/v2/clips/clip_01GYXVB5Y8PWAPWCWMSBCFB05X

# Livestream
# https://kick.com/xqc
# https://kick.com/api/v2/channels/xqc

# VODs
# https://kick.com/video/e74614f4-5270-4319-90ad-32179f19a45c
# https://kick.com/api/v1/video/e74614f4-5270-4319-90ad-32179f19a45c


class KickBaseIE(InfoExtractor):
    def _real_initialize(self):
        self._request_webpage(
            HEADRequest('https://kick.com/'), None, 'Setting up session', fatal=False, impersonate=True)
        xsrf_token = self._get_cookies('https://kick.com/').get('XSRF-TOKEN')

Review comment (suggestion):
```suggestion
    merge_dicts,
    parse_iso8601,
    str_or_none,
```

Code after:
import functools

from .common import InfoExtractor
from ..networking import HEADRequest
from ..utils import (
    UserNotLive,
    determine_ext,
    float_or_none,
    int_or_none,
    merge_dicts,
    parse_iso8601,
    str_or_none,
    traverse_obj,
    unified_timestamp,
    url_or_none,
)


class KickBaseIE(InfoExtractor):
    def _real_initialize(self):
        self._request_webpage(
            HEADRequest('https://kick.com/'), None, 'Setting up session', fatal=False, impersonate=True)
        xsrf_token = self._get_cookies('https://kick.com/').get('XSRF-TOKEN')
        if not xsrf_token:
            self.write_debug('kick.com did not set XSRF-TOKEN cookie')
        KickBaseIE._API_HEADERS = {
            'Authorization': f'Bearer {xsrf_token.value}',
            'X-XSRF-TOKEN': xsrf_token.value,
        } if xsrf_token else {}

    def _call_api(self, path, display_id, note='Downloading API JSON', headers={}, **kwargs):
        return self._download_json(
            f'https://kick.com/api/{path}', display_id, note=note,
            headers=merge_dicts(headers, self._API_HEADERS), impersonate=True, **kwargs)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/_extractors.py (Python)

Code before:
    JioCinemaSeriesIE,
)
from .jiosaavn import (
    JioSaavnAlbumIE,
    JioSaavnPlaylistIE,
    JioSaavnSongIE,
)
from .joj import JojIE
from .joqrag import JoqrAgIE
from .jove import JoveIE
from .jstream import JStreamIE
from .jtbc import (
    JTBCIE,
    JTBCProgramIE,
)
from .jwplatform import JWPlatformIE
from .kakao import KakaoIE
from .kaltura import KalturaIE
from .kankanews import KankaNewsIE
from .karaoketv import KaraoketvIE
from .kelbyone import KelbyOneIE
from .khanacademy import (
    KhanAcademyIE,
    KhanAcademyUnitIE,
)
from .kick import KickClipIE, KickIE, KickVODIE
from .kicker import KickerIE
from .kickstarter import KickStarterIE
from .kinja import KinjaEmbedIE
from .kinopoisk import KinoPoiskIE
from .kommunetv import KommunetvIE
from .kompas import KompasVideoIE
from .koo import KooIE
from .krasview import KrasViewIE
from .kth import KTHIE
from .ku6 import Ku6IE
from .kukululive import KukuluLiveIE
from .kuwo import (
    KuwoAlbumIE,
    KuwoCategoryIE,
    KuwoChartIE,
    KuwoIE,
    KuwoMvIE,
    KuwoSingerIE,
)
from .la7 import (
    LA7IE,
    LA7PodcastEpisodeIE,
    LA7PodcastIE,
)
from .laracasts import (

Review comment (suggestion):
```suggestion
from .kick import (
    KickClipIE,
    KickIE,
    KickVODIE,
)
```

Code after:
    JioCinemaSeriesIE,
)
from .jiosaavn import (
    JioSaavnAlbumIE,
    JioSaavnPlaylistIE,
    JioSaavnSongIE,
)
from .joj import JojIE
from .joqrag import JoqrAgIE
from .jove import JoveIE
from .jstream import JStreamIE
from .jtbc import (
    JTBCIE,
    JTBCProgramIE,
)
from .jwplatform import JWPlatformIE
from .kakao import KakaoIE
from .kaltura import KalturaIE
from .kankanews import KankaNewsIE
from .karaoketv import KaraoketvIE
from .kelbyone import KelbyOneIE
from .khanacademy import (
    KhanAcademyIE,
    KhanAcademyUnitIE,
)
from .kick import (
    KickClipIE,
    KickIE,
    KickVODIE,
)
from .kicker import KickerIE
from .kickstarter import KickStarterIE
from .kinja import KinjaEmbedIE
from .kinopoisk import KinoPoiskIE
from .kommunetv import KommunetvIE
from .kompas import KompasVideoIE
from .koo import KooIE
from .krasview import KrasViewIE
from .kth import KTHIE
from .ku6 import Ku6IE
from .kukululive import KukuluLiveIE
from .kuwo import (
    KuwoAlbumIE,
    KuwoCategoryIE,
    KuwoChartIE,
    KuwoIE,
    KuwoMvIE,
    KuwoSingerIE,
)
from .la7 import (
    LA7IE,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/kick.py (Python)

Code before:
from .common import InfoExtractor
from ..networking import HEADRequest
from ..utils import (
    UserNotLive,
    determine_ext,
    float_or_none,
    int_or_none,
    merge_dicts,
    parse_iso8601,
    str_or_none,
    traverse_obj,
    unified_timestamp,
    url_or_none,
)
class KickBaseIE(InfoExtractor):
    def _real_initialize(self):
        self._request_webpage(
            HEADRequest('https://kick.com/'), None, 'Setting up session', fatal=False, impersonate=True)
        xsrf_token = self._get_cookies('https://kick.com/').get('XSRF-TOKEN')
        if not xsrf_token:
            self.write_debug('kick.com did not set XSRF-TOKEN cookie')
        KickBaseIE._API_HEADERS = {
            'Authorization': f'Bearer {xsrf_token.value}',
            'X-XSRF-TOKEN': xsrf_token.value,
        } if xsrf_token else {}

    def _call_api(self, path, display_id, note='Downloading API JSON', headers={}, **kwargs):
        return self._download_json(
            f'https://kick.com/api/{path}', display_id, note=note,
            headers=merge_dicts(headers, self._API_HEADERS), impersonate=True, **kwargs)


class KickIE(KickBaseIE):
    IE_NAME = 'kick:live'
    _VALID_URL = r'https?://(?:www\.)?kick\.com/(?!(?:video|categories|search|auth)(?:[/?#]|$))(?P<id>[\w-]+)'
    _TESTS = [{
        'url': 'https://kick.com/xqc',
        'info_dict': {
            'id': '09886759-clickliveall-nightgamesstuff',
            'ext': 'mp4',

Review comment (refactor):
```suggestion


class KickBaseIE(InfoExtractor):
```

Code after:
import functools

from .common import InfoExtractor
from ..networking import HEADRequest
from ..utils import (
    UserNotLive,
    determine_ext,
    float_or_none,
    int_or_none,
    merge_dicts,
    parse_iso8601,
    str_or_none,
    traverse_obj,
    unified_timestamp,
    url_or_none,
)


class KickBaseIE(InfoExtractor):
    def _real_initialize(self):
        self._request_webpage(
            HEADRequest('https://kick.com/'), None, 'Setting up session', fatal=False, impersonate=True)
        xsrf_token = self._get_cookies('https://kick.com/').get('XSRF-TOKEN')
        if not xsrf_token:
            self.write_debug('kick.com did not set XSRF-TOKEN cookie')
        KickBaseIE._API_HEADERS = {
            'Authorization': f'Bearer {xsrf_token.value}',
            'X-XSRF-TOKEN': xsrf_token.value,
        } if xsrf_token else {}

    def _call_api(self, path, display_id, note='Downloading API JSON', headers={}, **kwargs):
        return self._download_json(
            f'https://kick.com/api/{path}', display_id, note=note,
            headers=merge_dicts(headers, self._API_HEADERS), impersonate=True, **kwargs)


class KickIE(KickBaseIE):
    IE_NAME = 'kick:live'
    _VALID_URL = r'https?://(?:www\.)?kick\.com/(?!(?:video|categories|search|auth)(?:[/?#]|$))(?P<id>[\w-]+)'
    _TESTS = [{
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/learningonscreen.py (Python)

Code before:
import functools
import re

from yt_dlp.extractor.common import InfoExtractor
from yt_dlp.utils import (
    ExtractorError,
    clean_html,
    extract_attributes,
    get_element_by_class,
    get_element_html_by_id,
    join_nonempty,
    parse_duration,
    unified_timestamp,
)
from yt_dlp.utils.traversal import traverse_obj


class LearningOnScreenIE(InfoExtractor):
    _VALID_URL = r'https?://learningonscreen\.ac\.uk/ondemand/index\.php/prog/(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://learningonscreen.ac.uk/ondemand/index.php/prog/005D81B2?bcast=22757013',
        'info_dict': {
            'id': '005D81B2',
            'ext': 'mp4',
            'title': 'Planet Earth',
            'duration': 3600.0,
            'timestamp': 1164567600.0,
            'upload_date': '20061126',
            'thumbnail': 'https://stream.learningonscreen.ac.uk/trilt-cover-images/005D81B2-Planet-Earth-2006-11-26T190000Z-BBC4.jpg',
        },
    }]

    def _real_initialize(self):
        if not self._get_cookies('https://learningonscreen.ac.uk/').get('PHPSESSID-BOB-LIVE'):
            self.raise_login_required(
                'Use --cookies for authentication. See '
                ' https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp  '
                'for how to manually pass cookies', method=None)

    def _real_extract(self, url):

Review comment (refactor):
```suggestion
from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    clean_html,
    extract_attributes,
    get_element_by_class,
    get_element_html_by_id,
    join_nonempty,
    parse_duration,
    unified_timestamp,
)
from ..utils.traversal import traverse_obj
```

Code after:
import functools
import re

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    clean_html,
    extract_attributes,
    get_element_by_class,
    get_element_html_by_id,
    join_nonempty,
    parse_duration,
    unified_timestamp,
)
from ..utils.traversal import traverse_obj


class LearningOnScreenIE(InfoExtractor):
    _VALID_URL = r'https?://learningonscreen\.ac\.uk/ondemand/index\.php/prog/(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://learningonscreen.ac.uk/ondemand/index.php/prog/005D81B2?bcast=22757013',
        'info_dict': {
            'id': '005D81B2',
            'ext': 'mp4',
            'title': 'Planet Earth',
            'duration': 3600.0,
            'timestamp': 1164567600.0,
            'upload_date': '20061126',
            'thumbnail': 'https://stream.learningonscreen.ac.uk/trilt-cover-images/005D81B2-Planet-Earth-2006-11-26T190000Z-BBC4.jpg',
        },
    }]

    def _real_initialize(self):
        if not self._get_cookies('https://learningonscreen.ac.uk/').get('PHPSESSID-BOB-LIVE'):
            self.raise_login_required(
                'Use --cookies for authentication. See '
                ' https://github.com/yt-dlp/yt-dlp/wiki/FAQ#how-do-i-pass-cookies-to-yt-dlp  '
                'for how to manually pass cookies', method=None)

    def _real_extract(self, url):
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/chaturbate.py (Python)

Code before:
import re

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    lowercase_escape,
    url_or_none,
)


class ChaturbateIE(InfoExtractor):
    _VALID_URL = r'https?://(?:[^/]+\.)?chaturbate\.(?P<domain>com|eu|global)/(?:fullvideo/?\?.*?\bb=)?(?P<id>[^/?&#]+)'
    _TESTS = [{
        'url': 'https://www.chaturbate.com/siswet19/',
        'info_dict': {
            'id': 'siswet19',
            'ext': 'mp4',
            'title': 're:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
            'age_limit': 18,
            'is_live': True,
        },
        'params': {
            'skip_download': True,
        },
        'skip': 'Room is offline',
    }, {
        'url': 'https://chaturbate.com/fullvideo/?b=caylin',
        'only_matching': True,
    }, {
        'url': 'https://en.chaturbate.com/siswet19/',
        'only_matching': True,
    }]

    _ROOM_OFFLINE = 'Room is currently offline'

    def _real_extract(self, url):
        mobj = self._match_valid_url(url)

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:[^/]+\.)?chaturbate\.(?P<tld>com|eu|global)/(?:fullvideo/?\?.*?\bb=)?(?P<id>[^/?&#]+)'
```

Code after:
import re

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    lowercase_escape,
    url_or_none,
)


class ChaturbateIE(InfoExtractor):
    _VALID_URL = r'https?://(?:[^/]+\.)?chaturbate\.(?P<tld>com|eu|global)/(?:fullvideo/?\?.*?\bb=)?(?P<id>[^/?&#]+)'
    _TESTS = [{
        'url': 'https://www.chaturbate.com/siswet19/',
        'info_dict': {
            'id': 'siswet19',
            'ext': 'mp4',
            'title': 're:^siswet19 [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
            'age_limit': 18,
            'is_live': True,
        },
        'params': {
            'skip_download': True,
        },
        'skip': 'Room is offline',
    }, {
        'url': 'https://chaturbate.com/fullvideo/?b=caylin',
        'only_matching': True,
    }, {
        'url': 'https://en.chaturbate.com/siswet19/',
        'only_matching': True,
    }, {
        'url': 'https://chaturbate.eu/siswet19/',
        'only_matching': True,
    }, {
        'url': 'https://chaturbate.eu/fullvideo/?b=caylin',
        'only_matching': True,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/piramidetv.py (Python)

Code before:
            video_id = next_video

    def _real_extract(self, url):
        url, smuggled_data = unsmuggle_url(url, {})
        video_id = self._match_id(url)
        if self._yes_playlist(video_id, video_id, smuggled_data):
            return self.playlist_result(self._entries(video_id), video_id)
        return self._extract_video(video_id)[1]


class PiramideTVChannelIE(InfoExtractor):
    _VALID_URL = r'https?://piramide\.tv/channel/(?P<id>[\w-]+)'
    _TESTS = [{
        'url': 'https://piramide.tv/channel/thekalo',
        'playlist_mincount': 10,
        'info_dict': {
            'id': 'thekalo',
        },
    }]

    def _entries(self, channel_name):
        videos = self._download_json(
            f'https://hermes.piramide.tv/channel/list/{channel_name}/date/100000', channel_name)
        for video in traverse_obj(videos, ('videos', lambda _, v: v['id'])):
            yield self.url_result(smuggle_url(
                f"https://piramide.tv/video/{video['id']}", {'force_noplaylist': True}),
                **traverse_obj(video, {
                    'id': ('id', {str}),
                    'title': ('title', {str}),
                    'description': ('description', {str}),
                }))

    def _real_extract(self, url):
        channel_name = self._match_id(url)
        return self.playlist_result(self._entries(channel_name), channel_name)


Review comment (suggestion):
```suggestion
                f'https://piramide.tv/video/{video["id"]}', {'force_noplaylist': True}),
```

Code after:
            video_id = next_video

    def _real_extract(self, url):
        url, smuggled_data = unsmuggle_url(url, {})
        video_id = self._match_id(url)
        if self._yes_playlist(video_id, video_id, smuggled_data):
            return self.playlist_result(self._entries(video_id), video_id)
        return self._extract_video(video_id)[1]


class PiramideTVChannelIE(InfoExtractor):
    _VALID_URL = r'https?://piramide\.tv/channel/(?P<id>[\w-]+)'
    _TESTS = [{
        'url': 'https://piramide.tv/channel/thekalo',
        'playlist_mincount': 10,
        'info_dict': {
            'id': 'thekalo',
        },
    }]

    def _entries(self, channel_name):
        videos = self._download_json(
            f'https://hermes.piramide.tv/channel/list/{channel_name}/date/100000', channel_name)
        for video in traverse_obj(videos, ('videos', lambda _, v: v['id'])):
            yield self.url_result(smuggle_url(
                f'https://piramide.tv/video/{video["id"]}', {'force_noplaylist': True}),
                **traverse_obj(video, {
                    'id': ('id', {str}),
                    'title': ('title', {str}),
                    'description': ('description', {str}),
                }))

    def _real_extract(self, url):
        channel_name = self._match_id(url)
        return self.playlist_result(self._entries(channel_name), channel_name)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/tvn24.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import (
    NO_DEFAULT,
    int_or_none,
    unescapeHTML,
)


class TVN24IE(InfoExtractor):
    _WORKING = False
    _VALID_URL = r'https?://(?:(?!eurosport)(?:[^/]+)\.)?tvn24(?:bis)?\.pl/(?:[^/]+/)*(?P<id>[^/]+)'
    _TESTS = [{
        'url': 'http://www.tvn24.pl/wiadomosci-z-kraju,3/oredzie-artura-andrusa,702428.html',
        'md5': 'fbdec753d7bc29d96036808275f2130c',
        'info_dict': {
            'id': '1584444',
            'ext': 'mp4',
            'title': '"Święta mają być wesołe, dlatego, ludziska, wszyscy pod jemiołę"',
            'description': 'Wyjątkowe orędzie Artura Andrusa, jednego z gości Szkła kontaktowego.',
            'thumbnail': 're:https?://.*[.]jpeg',
        },
    }, {
        # different layout
        'url': 'https://tvnmeteo.tvn24.pl/magazyny/maja-w-ogrodzie,13/odcinki-online,1,4,1,0/pnacza-ptaki-i-iglaki-odc-691-hgtv-odc-29,1771763.html',
        'info_dict': {
            'id': '1771763',
            'ext': 'mp4',
            'title': 'Pnącza, ptaki i iglaki (odc. 691 /HGTV odc. 29)',
            'thumbnail': 're:https?://.*',
        },
        'params': {
            'skip_download': True,
        },
    }, {
        'url': 'http://fakty.tvn24.pl/ogladaj-online,60/53-konferencja-bezpieczenstwa-w-monachium,716431.html',
        'only_matching': True,

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:(?!eurosport)[^/]+\.)?tvn24(?:bis)?\.pl/(?:[^/?#]+/)*(?P<id>[^/?#]+)'
```

Code after:
from .common import InfoExtractor
from ..utils import (
    NO_DEFAULT,
    int_or_none,
    unescapeHTML,
)


class TVN24IE(InfoExtractor):
    _WORKING = False
    _VALID_URL = r'https?://(?:(?!eurosport)[^/]+\.)?tvn24(?:bis)?\.pl/(?:[^/?#]+/)*(?P<id>[^/?#]+)'
    _TESTS = [{
        'url': 'http://www.tvn24.pl/wiadomosci-z-kraju,3/oredzie-artura-andrusa,702428.html',
        'md5': 'fbdec753d7bc29d96036808275f2130c',
        'info_dict': {
            'id': '1584444',
            'ext': 'mp4',
            'title': '"Święta mają być wesołe, dlatego, ludziska, wszyscy pod jemiołę"',
            'description': 'Wyjątkowe orędzie Artura Andrusa, jednego z gości Szkła kontaktowego.',
            'thumbnail': 're:https?://.*[.]jpeg',
        },
    }, {
        # different layout
        'url': 'https://tvnmeteo.tvn24.pl/magazyny/maja-w-ogrodzie,13/odcinki-online,1,4,1,0/pnacza-ptaki-i-iglaki-odc-691-hgtv-odc-29,1771763.html',
        'info_dict': {
            'id': '1771763',
            'ext': 'mp4',
            'title': 'Pnącza, ptaki i iglaki (odc. 691 /HGTV odc. 29)',
            'thumbnail': 're:https?://.*',
        },
        'params': {
            'skip_download': True,
        },
    }, {
        'url': 'http://fakty.tvn24.pl/ogladaj-online,60/53-konferencja-bezpieczenstwa-w-monachium,716431.html',
        'only_matching': True,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/cda.py (Python)

Code before:
            'playlist_count': 71,
        },
        {
            'url': 'https://www.cda.pl/DeliciousBeauty/folder/19129979/vfilm',
            'info_dict': {
                'id': '19129979',
                'title': 'TESTY KOSMETYKÓW',
            },
            'playlist_count': 139,
        }]

    def _real_extract(self, url):
        folder_id = self._match_id(url)
        channel_name = self._search_regex(
            r'cda\.pl/([^/]+)', url, 'channel name')

        webpage = self._download_webpage(url, folder_id)

        title = self._og_search_title(webpage)

        def extract_page_entries(channel_name, folder_id, page):
            url = f'https://www.cda.pl/{channel_name}/folder/{folder_id}/vfilm/{page+1}'
            webpage = self._download_webpage(url, folder_id, f'Extracting videos list from {url}')
            items = re.findall(r'<a[^>]+href="/video/([0-9a-z]+)" class=', webpage)
            for video_id in items:
                yield self.url_result(f'https://www.cda.pl/video/{video_id}', CDAIE.ie_key(), video_id)

        entries = OnDemandPagedList(
            functools.partial(extract_page_entries, channel_name, folder_id),
            self._MAX_PAGE_SIZE)

        return self.playlist_result(entries, folder_id, playlist_title=title)


Review comment (suggestion):
```suggestion
                yield self.url_result(f'https://www.cda.pl/video/{video_id}', CDAIE, video_id)
```

Code after:
        {
            'url': 'https://www.cda.pl/DeliciousBeauty/folder/19129979/vfilm',
            'info_dict': {
                'id': '19129979',
                'title': 'TESTY KOSMETYKÓW',
            },
            'playlist_mincount': 139,
        }]

    def _real_extract(self, url):
        folder_id, channel = self._match_valid_url(url).group('id', 'channel')

        webpage = self._download_webpage(url, folder_id)

        def extract_page_entries(page):
            webpage = self._download_webpage(
                f'https://www.cda.pl/{channel}/folder/{folder_id}/vfilm/{page + 1}', folder_id,
                f'Downloading page {page + 1}', expected_status=404)
            items = re.findall(r'<a[^>]+href="/video/([0-9a-z]+)"', webpage)
            for video_id in items:
                yield self.url_result(f'https://www.cda.pl/video/{video_id}', CDAIE, video_id)

        return self.playlist_result(
            OnDemandPagedList(extract_page_entries, self._MAX_PAGE_SIZE),
            folder_id, self._og_search_title(webpage))