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

Code before:
    }]

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

        data = traverse_obj(self._download_json(
            'https://ptvintern.picarto.tv/ptvapi', video_id, query={
                'query': '''{
  video(id: "%s") {
    id
    title
    file_name
    video_recording_image_url
    channel {
      name
    }
  }
}''' % (video_id),
            }), ('data', 'video'))

        title = data["file_name"]
        netloc = urllib.parse.urlparse(data["video_recording_image_url"]).netloc

        formats = self._extract_m3u8_formats(
            f"https://{netloc}/stream/hls/{title}/index.m3u8", video_id, 'mp4',
            entry_protocol='m3u8_native', m3u8_id='hls')

        return {
            'id': video_id,
            'title': title,
            'thumbnail': data['video_recording_image_url'],
            'formats': formats,
        }


Review comment (suggestion):
```suggestion
            f'https://{netloc}/stream/hls/{title}/index.m3u8', video_id, 'mp4', m3u8_id='hls')
```

Code after:
        'info_dict': {
            'id': '772650',
            'ext': 'mp4',
            'title': 'Art of Zod - Drawing and Painting',
            'thumbnail': r're:^https?://.*\.jpg',
            'channel': 'ArtofZod',
            'age_limit': 18,
        }
    }, {
        'url': 'https://picarto.tv/videopopout/Plague',
        'only_matching': True,
    }]

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

        data = self._download_json(
            'https://ptvintern.picarto.tv/ptvapi', video_id, query={
                'query': f'''{{
  video(id: "{video_id}") {{
    id
    title
    adult
    file_name
    video_recording_image_url
    channel {{
      name
    }}
  }}
}}'''
            })['data']['video']

        file_name = data['file_name']
        netloc = urllib.parse.urlparse(data['video_recording_image_url']).netloc

        formats = self._extract_m3u8_formats(
            f'https://{netloc}/stream/hls/{file_name}/index.m3u8', video_id, 'mp4', m3u8_id='hls')

        return {
            'id': video_id,
            **traverse_obj(data, {
                'id': ('id', {str_or_none}),
                'title': ('title', {str}),
                'thumbnail': 'video_recording_image_url',
                'channel': ('channel', 'name', {str}),
                'age_limit': ('adult', {lambda x: 18 if x else 0}),
            }),
            'formats': formats,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/picarto.py (Python)

Code before:
        data = traverse_obj(self._download_json(
            'https://ptvintern.picarto.tv/ptvapi', video_id, query={
                'query': '''{
  video(id: "%s") {
    id
    title
    file_name
    video_recording_image_url
    channel {
      name
    }
  }
}''' % (video_id),
            }), ('data', 'video'))

        title = data["file_name"]
        netloc = urllib.parse.urlparse(data["video_recording_image_url"]).netloc

        formats = self._extract_m3u8_formats(
            f"https://{netloc}/stream/hls/{title}/index.m3u8", video_id, 'mp4',
            entry_protocol='m3u8_native', m3u8_id='hls')

        return {
            'id': video_id,
            'title': title,
            'thumbnail': data['video_recording_image_url'],
            'formats': formats,
        }


Review comment (refactor):
metadata extraction should be non-fatal
```suggestion
            'thumbnail': data.get('video_recording_image_url'),
```

Code after:
            'channel': 'ArtofZod',
            'age_limit': 18,
        }
    }, {
        'url': 'https://picarto.tv/videopopout/Plague',
        'only_matching': True,
    }]

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

        data = self._download_json(
            'https://ptvintern.picarto.tv/ptvapi', video_id, query={
                'query': f'''{{
  video(id: "{video_id}") {{
    id
    title
    adult
    file_name
    video_recording_image_url
    channel {{
      name
    }}
  }}
}}'''
            })['data']['video']

        file_name = data['file_name']
        netloc = urllib.parse.urlparse(data['video_recording_image_url']).netloc

        formats = self._extract_m3u8_formats(
            f'https://{netloc}/stream/hls/{file_name}/index.m3u8', video_id, 'mp4', m3u8_id='hls')

        return {
            'id': video_id,
            **traverse_obj(data, {
                'id': ('id', {str_or_none}),
                'title': ('title', {str}),
                'thumbnail': 'video_recording_image_url',
                'channel': ('channel', 'name', {str}),
                'age_limit': ('adult', {lambda x: 18 if x else 0}),
            }),
            'formats': formats,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/picarto.py (Python)

Code before:
        'skip': 'The VOD does not exist',
    }, {
        'url': 'https://picarto.tv/ArtofZod/videos/772650',
        'md5': '00067a0889f1f6869cc512e3e79c521b',
        'info_dict': {
            'id': '772650',
            'ext': 'mp4',
            'title': 'govod+golive+ArtofZod_2023.06.12.23.28.30_nsfw.mkv',
            'thumbnail': r're:^https?://.*\.jpg'
        }
    }, {
        'url': 'https://picarto.tv/videopopout/Plague',
        'only_matching': True,
    }]

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

        data = self._download_json(
            'https://ptvintern.picarto.tv/ptvapi', video_id, query={
                'query': '''{
  video(id: "%s") {
    id
    title
    file_name
    video_recording_image_url
    channel {
      name
    }
  }
}''' % video_id,
            })['data']['video']

        title = data['file_name']
        netloc = urllib.parse.urlparse(data['video_recording_image_url']).netloc

        formats = self._extract_m3u8_formats(
            f'https://{netloc}/stream/hls/{title}/index.m3u8', video_id, 'mp4', m3u8_id='hls')

        return {
            'id': video_id,
            'title': title,
            'thumbnail': data.get('video_recording_image_url'),
            'formats': formats,
        }


Review comment (refactor):
This shares some common code with the API call in `PicartoIE._real_extract`, but not enough to make adding a baseclass worth it IMO

Code after:
            'ext': 'mp4',
            'title': 'ArtofZod_2017.12.12.00.13.23.flv',
            'thumbnail': r're:^https?://.*\.jpg'
        },
        'skip': 'The VOD does not exist',
    }, {
        'url': 'https://picarto.tv/ArtofZod/videos/772650',
        'md5': '00067a0889f1f6869cc512e3e79c521b',
        'info_dict': {
            'id': '772650',
            'ext': 'mp4',
            'title': 'Art of Zod - Drawing and Painting',
            'thumbnail': r're:^https?://.*\.jpg',
            'channel': 'ArtofZod',
            'age_limit': 18,
        }
    }, {
        'url': 'https://picarto.tv/videopopout/Plague',
        'only_matching': True,
    }]

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

        data = self._download_json(
            'https://ptvintern.picarto.tv/ptvapi', video_id, query={
                'query': f'''{{
  video(id: "{video_id}") {{
    id
    title
    adult
    file_name
    video_recording_image_url
    channel {{
      name
    }}
  }}
}}'''
            })['data']['video']

        file_name = data['file_name']
        netloc = urllib.parse.urlparse(data['video_recording_image_url']).netloc

        formats = self._extract_m3u8_formats(
            f'https://{netloc}/stream/hls/{file_name}/index.m3u8', video_id, 'mp4', m3u8_id='hls')

        return {
            'id': video_id,
            **traverse_obj(data, {
                'id': ('id', {str_or_none}),
                'title': ('title', {str}),
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/picarto.py (Python)

Code before:

        data = self._download_json(
            'https://ptvintern.picarto.tv/ptvapi', video_id, query={
                'query': '''{
  video(id: "%s") {
    id
    title
    file_name
    video_recording_image_url
    channel {
      name
    }
  }
}''' % video_id,
            })['data']['video']

        title = data['file_name']
        netloc = urllib.parse.urlparse(data['video_recording_image_url']).netloc

        formats = self._extract_m3u8_formats(
            f'https://{netloc}/stream/hls/{title}/index.m3u8', video_id, 'mp4', m3u8_id='hls')

        return {
            'id': video_id,
            'title': title,
            'thumbnail': data.get('video_recording_image_url'),
            'formats': formats,
        }


Review comment (suggestion):
could do this and leave the graphql query as-is
```suggestion
            **traverse_obj(data, {
                'id': ('id', {str_or_none}),
                'title': ('title', {str}),
                'thumbnail': 'video_recording_image_url',
                'channel': ('channel', 'name', {str}),
            }),
```

Code after:
        'url': 'https://picarto.tv/videopopout/Plague',
        'only_matching': True,
    }]

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

        data = self._download_json(
            'https://ptvintern.picarto.tv/ptvapi', video_id, query={
                'query': f'''{{
  video(id: "{video_id}") {{
    id
    title
    adult
    file_name
    video_recording_image_url
    channel {{
      name
    }}
  }}
}}'''
            })['data']['video']

        file_name = data['file_name']
        netloc = urllib.parse.urlparse(data['video_recording_image_url']).netloc

        formats = self._extract_m3u8_formats(
            f'https://{netloc}/stream/hls/{file_name}/index.m3u8', video_id, 'mp4', m3u8_id='hls')

        return {
            'id': video_id,
            **traverse_obj(data, {
                'id': ('id', {str_or_none}),
                'title': ('title', {str}),
                'thumbnail': 'video_recording_image_url',
                'channel': ('channel', 'name', {str}),
                'age_limit': ('adult', {lambda x: 18 if x else 0}),
            }),
            'formats': formats,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/s4c.py (Python)

Code before:
from .common import InfoExtractor

from ..utils import (
    traverse_obj
)


class S4CIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>[0-9]+)'
    _TESTS = [{
        'url': 'https://www.s4c.cymru/clic/programme/861362209',
        'info_dict': {
            'id': '861362209',
            'ext': 'mp4',
            'title': 'Y Swn',
            'description': 'When Margaret Thatcher\'s government breaks a promise to establish a Welsh language channel in 1979 it unleashes a wave of anger across Wales.  This film portrays the efforts of the Welsh Language Society and Plaid Cymru to realise a television channel and Gwynfor Evans\'s declaration to fast until death over the matter.  A unique film about one of the most colourful chapters in modern Welsh history.',
            'duration': 5340
        }
    },
        {
        'url': 'https://www.s4c.cymru/clic/programme/856636948',
        'info_dict': {
            'id': '856636948',
            'ext': 'mp4',
            'title': 'Am Dro',
            'duration': 2880,
            'description': 'In this programme Geraint will be leading the crew on a walk through Llanelli while introducing them to some unusual creatures. Barney will be taking them on a walk along the border near Oswestry. Ena will be following St David\'s footsteps in Pembrokeshire, while Ann-Marie will take them up the mountain in Eglwysilan before descending to the town of Senghenydd',
        }
    },
    ]

Review comment (suggestion):
```suggestion
from ..utils import traverse_obj
```

Code after:
from .common import InfoExtractor
from ..utils import traverse_obj


class S4CIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://www.s4c.cymru/clic/programme/861362209',
        'info_dict': {
            'id': '861362209',
            'ext': 'mp4',
            'title': 'Y Swn',
            'description': 'md5:f7681a30e4955b250b3224aa9fe70cf0',
            'duration': 5340
        },
    }, {
        'url': 'https://www.s4c.cymru/clic/programme/856636948',
        'info_dict': {
            'id': '856636948',
            'ext': 'mp4',
            'title': 'Am Dro',
            'duration': 2880,
            'description': 'md5:100d8686fc9a632a0cb2db52a3433ffe',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        details = self._download_json(
            f'https://www.s4c.cymru/df/full_prog_details?lang=e&programme_id={video_id}',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/s4c.py (Python)

Code before:
from .common import InfoExtractor

from ..utils import (
    traverse_obj
)


class S4CIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>[0-9]+)'
    _TESTS = [{
        'url': 'https://www.s4c.cymru/clic/programme/861362209',
        'info_dict': {
            'id': '861362209',
            'ext': 'mp4',
            'title': 'Y Swn',
            'description': 'When Margaret Thatcher\'s government breaks a promise to establish a Welsh language channel in 1979 it unleashes a wave of anger across Wales.  This film portrays the efforts of the Welsh Language Society and Plaid Cymru to realise a television channel and Gwynfor Evans\'s declaration to fast until death over the matter.  A unique film about one of the most colourful chapters in modern Welsh history.',
            'duration': 5340
        }
    },
        {
        'url': 'https://www.s4c.cymru/clic/programme/856636948',
        'info_dict': {
            'id': '856636948',
            'ext': 'mp4',
            'title': 'Am Dro',
            'duration': 2880,
            'description': 'In this programme Geraint will be leading the crew on a walk through Llanelli while introducing them to some unusual creatures. Barney will be taking them on a walk along the border near Oswestry. Ena will be following St David\'s footsteps in Pembrokeshire, while Ann-Marie will take them up the mountain in Eglwysilan before descending to the town of Senghenydd',
        }
    },
    ]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        programme_metadata = self._download_json(f'https://www.s4c.cymru/df/full_prog_details?lang=e&programme_id={video_id}', video_id)

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>\d+)'
```

Code after:
from .common import InfoExtractor
from ..utils import traverse_obj


class S4CIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://www.s4c.cymru/clic/programme/861362209',
        'info_dict': {
            'id': '861362209',
            'ext': 'mp4',
            'title': 'Y Swn',
            'description': 'md5:f7681a30e4955b250b3224aa9fe70cf0',
            'duration': 5340
        },
    }, {
        'url': 'https://www.s4c.cymru/clic/programme/856636948',
        'info_dict': {
            'id': '856636948',
            'ext': 'mp4',
            'title': 'Am Dro',
            'duration': 2880,
            'description': 'md5:100d8686fc9a632a0cb2db52a3433ffe',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        details = self._download_json(
            f'https://www.s4c.cymru/df/full_prog_details?lang=e&programme_id={video_id}',
            video_id, fatal=False)

        filename = self._download_json(
            'https://player-api.s4c-cdn.co.uk/player-configuration/prod', video_id, query={
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/s4c.py (Python)

Code before:
from .common import InfoExtractor

from ..utils import traverse_obj


class S4CIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://www.s4c.cymru/clic/programme/861362209',
        'info_dict': {
            'id': '861362209',
            'ext': 'mp4',
            'title': 'Y Swn',
            'description': 'md5:f7681a30e4955b250b3224aa9fe70cf0',
            'duration': 5340
        }
    },
        {
        'url': 'https://www.s4c.cymru/clic/programme/856636948',
        'info_dict': {
            'id': '856636948',
            'ext': 'mp4',
            'title': 'Am Dro',
            'duration': 2880,
            'description': 'md5:100d8686fc9a632a0cb2db52a3433ffe',
        }
    },
    ]

Review comment (refactor):
```suggestion
from .common import InfoExtractor
from ..utils import traverse_obj
```

Code after:
from .common import InfoExtractor
from ..utils import traverse_obj


class S4CIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/programme/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://www.s4c.cymru/clic/programme/861362209',
        'info_dict': {
            'id': '861362209',
            'ext': 'mp4',
            'title': 'Y Swn',
            'description': 'md5:f7681a30e4955b250b3224aa9fe70cf0',
            'duration': 5340
        },
    }, {
        'url': 'https://www.s4c.cymru/clic/programme/856636948',
        'info_dict': {
            'id': '856636948',
            'ext': 'mp4',
            'title': 'Am Dro',
            'duration': 2880,
            'description': 'md5:100d8686fc9a632a0cb2db52a3433ffe',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/tbsjp.py (Python)

Code before:
from .common import InfoExtractor
from ..networking.exceptions import HTTPError
from ..utils import (
    ExtractorError,
    clean_html,
    get_element_text_and_html_by_tag,
    int_or_none,
    str_or_none,
    traverse_obj,
    try_call,
    unified_timestamp,
    urljoin,
)


class TBSJPEpisodeIE(InfoExtractor):
    _VALID_URL = r'https://cu\.tbs\.co\.jp/episode/(?P<id>[\d_]+)'
    _GEO_BYPASS = False
    _TESTS = [{
        'url': 'https://cu.tbs.co.jp/episode/23613_2044134_1000049010',
        'skip': 'streams geo-restricted, Japan only. Also, will likely expire eventually',
        'info_dict': {
            'title': 'VIVANT 第三話 誤送金完結へ!絶体絶命の反撃開始',
            'id': '23613_2044134_1000049010',
            'ext': 'mp4',
            'upload_date': '20230728',
            'duration': 3517,
            'release_timestamp': 1691118230,
            'episode': '第三話 誤送金完結へ!絶体絶命の反撃開始',
            'release_date': '20230804',
            'categories': 'count:11',
            'episode_number': 3,
            'timestamp': 1690522538,
            'description': 'md5:2b796341af1ef772034133174ba4a895',
            'series': 'VIVANT',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        meta = self._search_json(r'window\.app\s*=', webpage, 'episode info', video_id, fatal=False)

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://cu\.tbs\.co\.jp/episode/(?P<id>[\d_]+)'
```

Code after:
from .common import InfoExtractor
from ..networking.exceptions import HTTPError
from ..utils import (
    ExtractorError,
    clean_html,
    get_element_text_and_html_by_tag,
    int_or_none,
    str_or_none,
    traverse_obj,
    try_call,
    unified_timestamp,
    urljoin,
)


class TBSJPEpisodeIE(InfoExtractor):
    _VALID_URL = r'https?://cu\.tbs\.co\.jp/episode/(?P<id>[\d_]+)'
    _GEO_BYPASS = False
    _TESTS = [{
        'url': 'https://cu.tbs.co.jp/episode/23613_2044134_1000049010',
        'skip': 'streams geo-restricted, Japan only. Also, will likely expire eventually',
        'info_dict': {
            'title': 'VIVANT 第三話 誤送金完結へ!絶体絶命の反撃開始',
            'id': '23613_2044134_1000049010',
            'ext': 'mp4',
            'upload_date': '20230728',
            'duration': 3517,
            'release_timestamp': 1691118230,
            'episode': '第三話 誤送金完結へ!絶体絶命の反撃開始',
            'release_date': '20230804',
            'categories': 'count:11',
            'episode_number': 3,
            'timestamp': 1690522538,
            'description': 'md5:2b796341af1ef772034133174ba4a895',
            'series': 'VIVANT',
        },
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        meta = self._search_json(r'window\.app\s*=', webpage, 'episode info', video_id, fatal=False)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/s4c.py (Python)

Code before:
        }


class S4CSeriesIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/series/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://www.s4c.cymru/clic/series/864982911',
        'playlist_mincount': 6,
        'info_dict': {
            'id': '864982911',
            'title': 'Iaith ar Daith',
            'description': 'md5:e878ebf660dce89bd2ef521d7ce06397'
        },
    }, {
        'url': 'https://www.s4c.cymru/clic/series/866852587',
        'playlist_mincount': 8,
        'info_dict': {
            'id': '866852587',
            'title': 'FFIT Cymru',
            'description': 'md5:abcb3c129cb68dbb6cd304fd33b07e96'
        },
    }]

    def _real_extract(self, url):
        series_id = self._match_id(url)
        seriesDetails = self._download_json(
            'https://www.s4c.cymru/df/series_details', series_id, query={
                'lang': 'e',
                'series_id': series_id,
                'show_prog_in_series': 'Y'
            }, note='Downloading player config JSON')
        episodes = (self.url_result(
                    'https://www.s4c.cymru/clic/programme/%s' % episode['id'],
                    video_id=episode['id'])
                    for episode in traverse_obj(seriesDetails, ('other_progs_in_series')))

        return self.playlist_result(
            entries=episodes,
            playlist_id=series_id,
            **traverse_obj(seriesDetails, ('full_prog_details', 0, {
                'title': (('series_title'), {str}),
                'description': ('full_billing', {str.strip}),
            }), get_all=False))


Review comment (suggestion):
snake_case
```suggestion
        series_details = self._download_json(
```

Code after:
class S4CSeriesIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?s4c\.cymru/clic/series/(?P<id>\d+)'
    _TESTS = [{
        'url': 'https://www.s4c.cymru/clic/series/864982911',
        'playlist_mincount': 6,
        'info_dict': {
            'id': '864982911',
            'title': 'Iaith ar Daith',
            'description': 'md5:e878ebf660dce89bd2ef521d7ce06397'
        },
    }, {
        'url': 'https://www.s4c.cymru/clic/series/866852587',
        'playlist_mincount': 8,
        'info_dict': {
            'id': '866852587',
            'title': 'FFIT Cymru',
            'description': 'md5:abcb3c129cb68dbb6cd304fd33b07e96'
        },
    }]

    def _real_extract(self, url):
        series_id = self._match_id(url)
        series_details = self._download_json(
            'https://www.s4c.cymru/df/series_details', series_id, query={
                'lang': 'e',
                'series_id': series_id,
                'show_prog_in_series': 'Y'
            }, note='Downloading series details JSON')

        return self.playlist_result(
            [self.url_result(f'https://www.s4c.cymru/clic/programme/{episode_id}', S4CIE, episode_id)
             for episode_id in traverse_obj(series_details, ('other_progs_in_series', ..., 'id'))],
            series_id, traverse_obj(series_details, ('full_prog_details', 0, 'series_title', {str})))