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

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


class EpochIE(InfoExtractor):
    _VALID_URL = r'https?://www.theepochtimes\.com/[\w-]+_(?P<id>\d+).html'
    _TESTS = [
        {
            'url': 'https://www.theepochtimes.com/they-can-do-audio-video-physical-surveillance-on-you-24h-365d-a-year-rex-lee-on-intrusive-apps_4661688.html',
            'info_dict': {
                "id": '4661688',
                'ext': 'mp4',
                'url': 'http://vs1.youmaker.com/assets/a3dd732c-4750-4bc8-8156-69180668bda1/playlist.m3u8',
                'title': '‘They Can Do Audio, Video, Physical Surveillance on You 24H/365D a Year’: Rex Lee on Intrusive Apps',
                'webpage_url_domain': 'theepochtimes.com',
                'extractor': 'Epoch',
                'extractor_key': 'Epoch'
            }
        },
        {
            'url': 'https://www.theepochtimes.com/the-communist-partys-cyberattacks-on-america-explained-rex-lee-talks-tech-hybrid-warfare_4342413.html',
            'info_dict': {
                'id': '4342413',
                'ext': 'mp4',
                'url': 'https://vs1.youmaker.com/assets/276c7f46-3bbf-475d-9934-b9bbe827cf0a/playlist.m3u8',
                'title': 'The Communist Party’s Cyberattacks on America Explained; Rex Lee Talks Tech Hybrid Warfare',
                'webpage_url_domain': 'theepochtimes.com',

Review comment (security):
```suggestion
from ..utils import unescapeHTML
```

Code after:
from .common import InfoExtractor


class EpochIE(InfoExtractor):
    _VALID_URL = r'https?://www.theepochtimes\.com/[\w-]+_(?P<id>\d+).html'
    _TESTS = [
        {
            'url': 'https://www.theepochtimes.com/they-can-do-audio-video-physical-surveillance-on-you-24h-365d-a-year-rex-lee-on-intrusive-apps_4661688.html',
            'info_dict': {
                'id': 'a3dd732c-4750-4bc8-8156-69180668bda1',
                'ext': 'mp4',
                'title': '‘They Can Do Audio, Video, Physical Surveillance on You 24H/365D a Year’: Rex Lee on Intrusive Apps',
            }
        },
        {
            'url': 'https://www.theepochtimes.com/the-communist-partys-cyberattacks-on-america-explained-rex-lee-talks-tech-hybrid-warfare_4342413.html',
            'info_dict': {
                'id': '276c7f46-3bbf-475d-9934-b9bbe827cf0a',
                'ext': 'mp4',
                'title': 'The Communist Party’s Cyberattacks on America Explained; Rex Lee Talks Tech Hybrid Warfare',
            }
        },
        {
            'url': 'https://www.theepochtimes.com/kash-patel-a-6-year-saga-of-government-corruption-from-russiagate-to-mar-a-lago_4690250.html',
            'info_dict': {
                'id': 'aa9ceecd-a127-453d-a2de-7153d6fd69b6',
                'ext': 'mp4',
                'title': 'Kash Patel: A ‘6-Year-Saga’ of Government Corruption, From Russiagate to Mar-a-Lago',
            }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/prankcast.py (Python)

Code before:
from .common import InfoExtractor
from ..utils import parse_iso8601


class PrankCastIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?prankcast\.com/.*/showreel/(?P<id>\d+)-(?P<display_id>.+)'
    _TESTS = [{
        'url': 'https://prankcast.com/Devonanustart/showreel/1561-Beverly-is-back-like-a-heart-attack-',
        'info_dict': {
            'id': '1561',
            'ext': 'mp3',
            'title': 'Beverly is back like a heart attack!',
            'uploader': 'Devonanustart',
            'upload_date': '20220825'
        }
    }]

    def _real_extract(self, url):
        video_id, display_id = self._match_valid_url(url).group('id', 'display_id')

        webpage = self._download_webpage(url, video_id)

        # Extract the JSON
        json_info = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['ssr_data_showreel']

        # Get author (AKA show host)
        uploader = json_info.get('user_name')

        # Get the co-hosts/guests
        guests_json = self._parse_json(json_info.get('guests_json') or '{}', video_id)
        guests = [] if not uploader else [uploader] + [x.get('name') for x in guests_json if x.get('name') is not None]

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?prankcast\.com/[^/?#]+/showreel/(?P<id>\d+)-(?P<display_id>[^/?#]+)'
```

Code after:
from .common import InfoExtractor
from ..utils import parse_iso8601, traverse_obj, try_call


class PrankCastIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?prankcast\.com/[^/?#]+/showreel/(?P<id>\d+)-(?P<display_id>[^/?#]+)'
    _TESTS = [{
        'url': 'https://prankcast.com/Devonanustart/showreel/1561-Beverly-is-back-like-a-heart-attack-',
        'info_dict': {
            'id': '1561',
            'ext': 'mp3',
            'title': 'Beverly is back like a heart attack!',
            'display_id': 'Beverly-is-back-like-a-heart-attack-',
            'timestamp': 1661391575,
            'uploader': 'Devonanustart',
            'channel_id': 4,
            'duration': 7918,
            'cast': ['Devonanustart', 'Phonelosers'],
            'description': '',
            'categories': ['prank'],
            'tags': ['prank call', 'prank'],
            'upload_date': '20220825'
        }
    }]

    def _real_extract(self, url):
        video_id, display_id = self._match_valid_url(url).group('id', 'display_id')

        webpage = self._download_webpage(url, video_id)
        json_info = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['ssr_data_showreel']
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mediaworksnz.py (Python)

Code before:
        content_type = asset.get('type')
        if content_type and content_type != 'video':
            self.report_warning(f'Unknown content type: {content_type}' + bug_reports_message(), video_id)

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(asset['streamingUrl'], video_id)

        audio_streaming_url = traverse_obj(
            asset, 'palyoutPathAudio', 'playoutpathaudio', get_all=False, expected_type=str)
        if audio_streaming_url:
            audio_formats = self._extract_m3u8_formats(audio_streaming_url, video_id, fatal=False, ext='mp3')
            for audio_format in audio_formats:
                # all the audio streams appear to be aac
                audio_format['vcodec'] = audio_format.get('vcodec') or 'none'
                audio_format['acodec'] = audio_format.get('acodec') or 'aac'
                formats.append(audio_format)

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': asset.get('title'),
            'description': asset.get('description'),
            'duration': float_or_none(asset.get('duration')),
            'timestamp': unified_timestamp(asset.get('dateadded')),
            'channel': asset.get('brand'),
            'thumbnails': [{'url': thumbnail_url} for thumbnail_url in asset.get('thumbnails', [])],
            'formats': formats,
            'subtitles': subtitles,
        }


Review comment (suggestion):
```suggestion
            'thumbnails': [{'url': thumbnail_url} for thumbnail_url in asset.get('thumbnails') or []],
```

Code after:
        content_type = asset.get('type')
        if content_type and content_type != 'video':
            self.report_warning(f'Unknown content type: {content_type}' + bug_reports_message(), video_id)

        formats, subtitles = self._extract_m3u8_formats_and_subtitles(asset['streamingUrl'], video_id)

        audio_streaming_url = traverse_obj(
            asset, 'palyoutPathAudio', 'playoutpathaudio', expected_type=str)
        if audio_streaming_url:
            audio_formats = self._extract_m3u8_formats(audio_streaming_url, video_id, fatal=False, ext='mp3')
            for audio_format in audio_formats:
                # all the audio streams appear to be aac
                audio_format.setdefault('vcodec', 'none')
                audio_format.setdefault('acodec', 'aac')
                formats.append(audio_format)

        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': asset.get('title'),
            'description': asset.get('description'),
            'duration': float_or_none(asset.get('duration')),
            'timestamp': unified_timestamp(asset.get('dateadded')),
            'channel': asset.get('brand'),
            'thumbnails': [{'url': thumbnail_url} for thumbnail_url in asset.get('thumbnails') or []],
            'formats': formats,
            'subtitles': subtitles,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/redgifs.py (Python)

Code before:
import functools

from .common import InfoExtractor
from ..compat import compat_parse_qs
from ..utils import (
    ExtractorError,
    int_or_none,
    qualities,
    try_get,
    OnDemandPagedList,
)


class RedGifsBaseInfoExtractor(InfoExtractor):
    _FORMATS = {
        'gif': 250,
        'sd': 480,
        'hd': None,
    }

    _API_HEADERS = {'referer': 'https://www.redgifs.com/',
                    'origin': 'https://www.redgifs.com',
                    'content-type': 'application/json'}

    def _parse_gif_data(self, gif_data):
        video_id = gif_data.get('id')
        quality = qualities(tuple(self._FORMATS.keys()))

        orig_height = int_or_none(gif_data.get('height'))
        aspect_ratio = try_get(gif_data, lambda x: orig_height / x['width'])

        formats = []
        for format_id, height in self._FORMATS.items():
            video_url = gif_data['urls'].get(format_id)
            if not video_url:
                continue
            height = min(orig_height, height or orig_height)
            formats.append({
                'url': video_url,
                'format_id': format_id,
                'width': height * aspect_ratio if aspect_ratio else None,
                'height': height,
                'quality': quality(format_id),
            })
        self._sort_formats(formats)

        return {
            'id': video_id,

Review comment (suggestion):
```suggestion
    _API_HEADERS = {
        'referer': 'https://www.redgifs.com/',
        'origin': 'https://www.redgifs.com',
        'content-type': 'application/json',
    }
```

Code after:
import functools

from .common import InfoExtractor
from ..compat import compat_parse_qs
from ..utils import (
    ExtractorError,
    int_or_none,
    qualities,
    try_get,
    OnDemandPagedList,
)


class RedGifsBaseInfoExtractor(InfoExtractor):
    _FORMATS = {
        'gif': 250,
        'sd': 480,
        'hd': None,
    }

    _API_HEADERS = {
        'referer': 'https://www.redgifs.com/',
        'origin': 'https://www.redgifs.com',
        'content-type': 'application/json',
    }

    def _parse_gif_data(self, gif_data):
        video_id = gif_data.get('id')
        quality = qualities(tuple(self._FORMATS.keys()))

        orig_height = int_or_none(gif_data.get('height'))
        aspect_ratio = try_get(gif_data, lambda x: orig_height / x['width'])

        formats = []
        for format_id, height in self._FORMATS.items():
            video_url = gif_data['urls'].get(format_id)
            if not video_url:
                continue
            height = min(orig_height, height or orig_height)
            formats.append({
                'url': video_url,
                'format_id': format_id,
                'width': height * aspect_ratio if aspect_ratio else None,
                'height': height,
                'quality': quality(format_id),
            })
        self._sort_formats(formats)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/berufetv.py (Python)

Code before:
from yt_dlp.extractor.common import InfoExtractor
from yt_dlp.utils import ExtractorError, mimetype2ext, traverse_obj


class BerufeTVIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?web\.arbeitsagentur\.de/berufetv/[a-z\-/]+/film;filmId=(?P<id>[a-zA-Z\d\-_]+)'
    _TESTS = [{
        'url': 'https://web.arbeitsagentur.de/berufetv/studienberufe/wirtschaftswissenschaften/wirtschaftswissenschaften-volkswirtschaft/film;filmId=DvKC3DUpMKvUZ_6fEnfg3u',
        'md5': '041b6432ec8e6838f84a5c30f31cc795',
        'info_dict': {
            'id': 'DvKC3DUpMKvUZ_6fEnfg3u',
            'ext': 'mp4',
            'title': 'Volkswirtschaftslehre',
            'description': 'md5:6bd87d0c63163480a6489a37526ee1c1',
            'categories': ['Studien&shy;beruf'],
            'tags': ['Studienfilm'],
            'duration': 602.440,
            'thumbnail': 'https://asset-out-cdn.video-cdn.net/private/videos/DvKC3DUpMKvUZ_6fEnfg3u/thumbnails/active',
        }
    }]

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

        movie_metadata = self._download_json(
            'https://rest.arbeitsagentur.de/infosysbub/berufetv/pc/v1/film-metadata',
            video_id, 'Downloading JSON metadata',

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

Code after:
from .common import InfoExtractor
from ..utils import float_or_none, mimetype2ext, traverse_obj


class BerufeTVIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?web\.arbeitsagentur\.de/berufetv/[^?#]+/film;filmId=(?P<id>[\w-]+)'
    _TESTS = [{
        'url': 'https://web.arbeitsagentur.de/berufetv/studienberufe/wirtschaftswissenschaften/wirtschaftswissenschaften-volkswirtschaft/film;filmId=DvKC3DUpMKvUZ_6fEnfg3u',
        'md5': '041b6432ec8e6838f84a5c30f31cc795',
        'info_dict': {
            'id': 'DvKC3DUpMKvUZ_6fEnfg3u',
            'ext': 'mp4',
            'title': 'Volkswirtschaftslehre',
            'description': 'md5:6bd87d0c63163480a6489a37526ee1c1',
            'categories': ['Studien&shy;beruf'],
            'tags': ['Studienfilm'],
            'duration': 602.440,
            'thumbnail': r're:^https://asset-out-cdn\.video-cdn\.net/private/videos/DvKC3DUpMKvUZ_6fEnfg3u/thumbnails/793063\?quality=thumbnail&__token__=[^\s]+$',
        }
    }]

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

        movie_metadata = self._download_json(
            'https://rest.arbeitsagentur.de/infosysbub/berufetv/pc/v1/film-metadata',
            video_id, 'Downloading JSON metadata',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/berufetv.py (Python)

Code before:
from yt_dlp.extractor.common import InfoExtractor
from yt_dlp.utils import ExtractorError, mimetype2ext, traverse_obj


class BerufeTVIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?web\.arbeitsagentur\.de/berufetv/[a-z\-/]+/film;filmId=(?P<id>[a-zA-Z\d\-_]+)'
    _TESTS = [{
        'url': 'https://web.arbeitsagentur.de/berufetv/studienberufe/wirtschaftswissenschaften/wirtschaftswissenschaften-volkswirtschaft/film;filmId=DvKC3DUpMKvUZ_6fEnfg3u',
        'md5': '041b6432ec8e6838f84a5c30f31cc795',
        'info_dict': {
            'id': 'DvKC3DUpMKvUZ_6fEnfg3u',
            'ext': 'mp4',
            'title': 'Volkswirtschaftslehre',
            'description': 'md5:6bd87d0c63163480a6489a37526ee1c1',
            'categories': ['Studien&shy;beruf'],
            'tags': ['Studienfilm'],
            'duration': 602.440,
            'thumbnail': 'https://asset-out-cdn.video-cdn.net/private/videos/DvKC3DUpMKvUZ_6fEnfg3u/thumbnails/active',
        }
    }]

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

        movie_metadata = self._download_json(
            'https://rest.arbeitsagentur.de/infosysbub/berufetv/pc/v1/film-metadata',
            video_id, 'Downloading JSON metadata',
            headers={'X-API-Key': '79089773-4892-4386-86e6-e8503669f426'}, fatal=False)

        meta = next(
            item for item in movie_metadata.get('metadaten') if video_id == item.get('miId')

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?web\.arbeitsagentur\.de/berufetv/[^?#]+/film;filmId=(?P<id>[\w-]+)'
```

Code after:
from .common import InfoExtractor
from ..utils import float_or_none, mimetype2ext, traverse_obj


class BerufeTVIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?web\.arbeitsagentur\.de/berufetv/[^?#]+/film;filmId=(?P<id>[\w-]+)'
    _TESTS = [{
        'url': 'https://web.arbeitsagentur.de/berufetv/studienberufe/wirtschaftswissenschaften/wirtschaftswissenschaften-volkswirtschaft/film;filmId=DvKC3DUpMKvUZ_6fEnfg3u',
        'md5': '041b6432ec8e6838f84a5c30f31cc795',
        'info_dict': {
            'id': 'DvKC3DUpMKvUZ_6fEnfg3u',
            'ext': 'mp4',
            'title': 'Volkswirtschaftslehre',
            'description': 'md5:6bd87d0c63163480a6489a37526ee1c1',
            'categories': ['Studien&shy;beruf'],
            'tags': ['Studienfilm'],
            'duration': 602.440,
            'thumbnail': r're:^https://asset-out-cdn\.video-cdn\.net/private/videos/DvKC3DUpMKvUZ_6fEnfg3u/thumbnails/793063\?quality=thumbnail&__token__=[^\s]+$',
        }
    }]

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

        movie_metadata = self._download_json(
            'https://rest.arbeitsagentur.de/infosysbub/berufetv/pc/v1/film-metadata',
            video_id, 'Downloading JSON metadata',
            headers={'X-API-Key': '79089773-4892-4386-86e6-e8503669f426'}, fatal=False)

        meta = traverse_obj(
            movie_metadata, ('metadaten', lambda _, i: video_id == i['miId']),
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/berufetv.py (Python)

Code before:

        formats = []
        subtitles = {}

        for key, source in video_sources.items():
            if key == 'auto':
                m3u8_url = source[0]['source']
                fmts, subs = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id)
                formats += fmts
                subtitles = subs
            else:
                formats.append({
                    'url': source[0]['source'],
                    'ext': mimetype2ext(source[0]['mimeType']),
                    'format_id': key,
                })

        video_tracks = video.get('videoTracks') or []
        for track in video_tracks:
            if track.get('type') != 'SUBTITLES':
                continue
            subtitles[track['language']] = [{
                'url': track['source'],
                'name': track['label'],
                'ext': 'vtt'
            }]

        return {
            'id': video_id,
            'title': meta.get('titel') or traverse_obj(video, ['videoMetaData', 'title']),
            'description': meta.get('beschreibung'),
            'thumbnail': 'https://asset-out-cdn.video-cdn.net/private/videos/%s/thumbnails/active' % (video_id),
            'duration': video.get('duration') / 1000,
            'categories': [meta.get('kategorie')],
            'tags': meta.get('themengebiete'),
            'subtitles': subtitles,
            'formats': formats,
        }


Review comment (suggestion):
```suggestion
        for track in video.get('videoTracks') or []:
            if track.get('type') != 'SUBTITLES':
                continue
            subtitles.setdefault(track['language'], []).append({
                'url': track['source'],
                'name': track.get('label'),
                'ext': 'vtt'
            })
```

Code after:
                formats += fmts
                subtitles = subs
            else:
                formats.append({
                    'url': source[0]['source'],
                    'ext': mimetype2ext(source[0]['mimeType']),
                    'format_id': key,
                })

        for track in video.get('videoTracks') or []:
            if track.get('type') != 'SUBTITLES':
                continue
            subtitles.setdefault(track['language'], []).append({
                'url': track['source'],
                'name': track.get('label'),
                'ext': 'vtt'
            })

        return {
            'id': video_id,
            'title': meta.get('titel') or traverse_obj(video, ('videoMetaData', 'title')),
            'description': meta.get('beschreibung'),
            'thumbnail': meta.get('thumbnail') or f'https://asset-out-cdn.video-cdn.net/private/videos/{video_id}/thumbnails/active',
            'duration': float_or_none(video.get('duration'), scale=1000),
            'categories': [meta['kategorie']] if meta.get('kategorie') else None,
            'tags': meta.get('themengebiete'),
            'subtitles': subtitles,
            'formats': formats,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/berufetv.py (Python)

Code before:
        for key, source in video_sources.items():
            if key == 'auto':
                m3u8_url = source[0]['source']
                fmts, subs = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id)
                formats += fmts
                subtitles = subs
            else:
                formats.append({
                    'url': source[0]['source'],
                    'ext': mimetype2ext(source[0]['mimeType']),
                    'format_id': key,
                })

        video_tracks = video.get('videoTracks') or []
        for track in video_tracks:
            if track.get('type') != 'SUBTITLES':
                continue
            subtitles[track['language']] = [{
                'url': track['source'],
                'name': track['label'],
                'ext': 'vtt'
            }]

        return {
            'id': video_id,
            'title': meta.get('titel') or traverse_obj(video, ['videoMetaData', 'title']),
            'description': meta.get('beschreibung'),
            'thumbnail': 'https://asset-out-cdn.video-cdn.net/private/videos/%s/thumbnails/active' % (video_id),
            'duration': video.get('duration') / 1000,
            'categories': [meta.get('kategorie')],
            'tags': meta.get('themengebiete'),
            'subtitles': subtitles,
            'formats': formats,
        }


Review comment (suggestion):
```suggestion
            'title': meta.get('titel') or traverse_obj(video, ('videoMetaData', 'title')),
```

Code after:
                    'url': source[0]['source'],
                    'ext': mimetype2ext(source[0]['mimeType']),
                    'format_id': key,
                })

        for track in video.get('videoTracks') or []:
            if track.get('type') != 'SUBTITLES':
                continue
            subtitles.setdefault(track['language'], []).append({
                'url': track['source'],
                'name': track.get('label'),
                'ext': 'vtt'
            })

        return {
            'id': video_id,
            'title': meta.get('titel') or traverse_obj(video, ('videoMetaData', 'title')),
            'description': meta.get('beschreibung'),
            'thumbnail': meta.get('thumbnail') or f'https://asset-out-cdn.video-cdn.net/private/videos/{video_id}/thumbnails/active',
            'duration': float_or_none(video.get('duration'), scale=1000),
            'categories': [meta['kategorie']] if meta.get('kategorie') else None,
            'tags': meta.get('themengebiete'),
            'subtitles': subtitles,
            'formats': formats,
        }