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

Code before:
# coding: utf-8
from .common import InfoExtractor
from ..utils import int_or_none, parse_iso8601


class StreamFFIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?streamff\.com/v/(?P<id>[a-zA-Z0-9]+)'
    _API_URL = 'https://streamff.com/api'

    _TESTS = [{
        'url': 'https://streamff.com/v/55cc94',
        'md5': '8745a67bb5e5c570738efe7983826370',
        'info_dict': {
            'id': '55cc94',
            'ext': 'mp4',
            'title': '55cc94',
            'timestamp': 1634764643,
            'upload_date': '20211020'
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        api_path = f'/videos/{video_id}'

        """"
        {
            'views': 94,

Review comment (refactor):
just a suggestion (it's not needed per say tbh)
But i personally would have kept it same as all other extractors 
```suggestion
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor
from ..utils import int_or_none, parse_iso8601
```

Code after:
# coding: utf-8
from .common import InfoExtractor
from ..utils import int_or_none, parse_iso8601


class StreamFFIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?streamff\.com/v/(?P<id>[a-zA-Z0-9]+)'

    _TESTS = [{
        'url': 'https://streamff.com/v/55cc94',
        'md5': '8745a67bb5e5c570738efe7983826370',
        'info_dict': {
            'id': '55cc94',
            'ext': 'mp4',
            'title': '55cc94',
            'timestamp': 1634764643,
            'upload_date': '20211020',
            'view_count': int,
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        json_data = self._download_json(f'https://streamff.com/api/videos/{video_id}', video_id)
        return {
            'id': video_id,
            'title': json_data.get('name') or video_id,
            'url': 'https://streamff.com/%s' % json_data['videoLink'],
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/streamff.py (Python)

Code before:
        'url': 'https://streamff.com/v/55cc94',
        'md5': '8745a67bb5e5c570738efe7983826370',
        'info_dict': {
            'id': '55cc94',
            'ext': 'mp4',
            'title': '55cc94',
            'timestamp': 1634764643,
            'upload_date': '20211020'
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        api_path = f'/videos/{video_id}'

        """"
        {
            'views': 94,
            'uploaded': True,
            'publicURl': '55cc94',
            'date': '2021-10-20T21:17:23.887Z',
            'name': '55cc94',
            'videoLink': '/uploads/55cc94.mp4'
        }
        """
        json_data = self._download_json(self._API_URL + api_path, video_id)
        video_url = f'https://streamff.com/{json_data["videoLink"]}'
        title = json_data.get('name') or video_id

        return {
            'id': video_id,
            'title': title,
            'url': video_url,
            'view_count': int_or_none(json_data.get('views')),
            'timestamp': parse_iso8601(json_data.get('date'))
        }


Review comment (suggestion):
```suggestion
        json_data = self._download_json(f'https://streamff.com/api/videos/{video_id}', video_id)
```

Code after:
# coding: utf-8
from .common import InfoExtractor
from ..utils import int_or_none, parse_iso8601


class StreamFFIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?streamff\.com/v/(?P<id>[a-zA-Z0-9]+)'

    _TESTS = [{
        'url': 'https://streamff.com/v/55cc94',
        'md5': '8745a67bb5e5c570738efe7983826370',
        'info_dict': {
            'id': '55cc94',
            'ext': 'mp4',
            'title': '55cc94',
            'timestamp': 1634764643,
            'upload_date': '20211020',
            'view_count': int,
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        json_data = self._download_json(f'https://streamff.com/api/videos/{video_id}', video_id)
        return {
            'id': video_id,
            'title': json_data.get('name') or video_id,
            'url': 'https://streamff.com/%s' % json_data['videoLink'],
            'view_count': int_or_none(json_data.get('views')),
            'timestamp': parse_iso8601(json_data.get('date')),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/streamff.py (Python)

Code before:

    def _real_extract(self, url):
        video_id = self._match_id(url)
        api_path = f'/videos/{video_id}'

        """"
        {
            'views': 94,
            'uploaded': True,
            'publicURl': '55cc94',
            'date': '2021-10-20T21:17:23.887Z',
            'name': '55cc94',
            'videoLink': '/uploads/55cc94.mp4'
        }
        """
        json_data = self._download_json(self._API_URL + api_path, video_id)
        video_url = f'https://streamff.com/{json_data["videoLink"]}'
        title = json_data.get('name') or video_id

        return {
            'id': video_id,
            'title': title,
            'url': video_url,
            'view_count': int_or_none(json_data.get('views')),
            'timestamp': parse_iso8601(json_data.get('date'))
        }


Review comment (suggestion):
```suggestion
        return {
            'id': video_id,
            'title': json_data.get('name') or video_id,
            'url': 'https://streamff.com/%s' % json_data['videoLink'],
            'view_count': int_or_none(json_data.get('views')),
            'timestamp': parse_iso8601(json_data.get('date')),
        }
```

Code after:
# coding: utf-8
from .common import InfoExtractor
from ..utils import int_or_none, parse_iso8601


class StreamFFIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?streamff\.com/v/(?P<id>[a-zA-Z0-9]+)'

    _TESTS = [{
        'url': 'https://streamff.com/v/55cc94',
        'md5': '8745a67bb5e5c570738efe7983826370',
        'info_dict': {
            'id': '55cc94',
            'ext': 'mp4',
            'title': '55cc94',
            'timestamp': 1634764643,
            'upload_date': '20211020',
            'view_count': int,
        }
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        json_data = self._download_json(f'https://streamff.com/api/videos/{video_id}', video_id)
        return {
            'id': video_id,
            'title': json_data.get('name') or video_id,
            'url': 'https://streamff.com/%s' % json_data['videoLink'],
            'view_count': int_or_none(json_data.get('views')),
            'timestamp': parse_iso8601(json_data.get('date')),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/cableav.py (Python)

Code before:
# coding: utf-8
from .common import InfoExtractor


class CableAVIE(InfoExtractor):
    _VALID_URL = r'https://cableav\.tv/(?P<id>[a-zA-Z0-9]+)/'
    _TESTS = [{
        'url': 'https://cableav.tv/lS4iR9lWjN8/',
        'md5': '7e3fe5e49d61c4233b7f5b0f69b15e18',
        'info_dict': {
            'id': 'lS4iR9lWjN8',
            'ext': 'mp4',
            'title': '國產麻豆AV 叮叮映畫 DDF001 情欲小說家 - CableAV',
            'description': '國產AV 480p, 720p 国产麻豆AV 叮叮映画 DDF001 情欲小说家',
            'thumbnail': r're:^https?://.*\.jpg$',
        }
    }]

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

        video_url = self._og_search_video_url(webpage, secure=False)

        formats = self._extract_m3u8_formats(video_url, video_id, 'mp4')
        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': self._og_search_title(webpage),
            'description': self._og_search_description(webpage),

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https://cableav\.tv/(?P<id>[a-zA-Z0-9]+)'
```

Code after:
# coding: utf-8
from .common import InfoExtractor


class CableAVIE(InfoExtractor):
    _VALID_URL = r'https://cableav\.tv/(?P<id>[a-zA-Z0-9]+)'
    _TESTS = [{
        'url': 'https://cableav.tv/lS4iR9lWjN8/',
        'md5': '7e3fe5e49d61c4233b7f5b0f69b15e18',
        'info_dict': {
            'id': 'lS4iR9lWjN8',
            'ext': 'mp4',
            'title': '國產麻豆AV 叮叮映畫 DDF001 情欲小說家 - CableAV',
            'description': '國產AV 480p, 720p 国产麻豆AV 叮叮映画 DDF001 情欲小说家',
            'thumbnail': r're:^https?://.*\.jpg$',
        }
    }]

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

        video_url = self._og_search_video_url(webpage, secure=False)

        formats = self._extract_m3u8_formats(video_url, video_id, 'mp4')
        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': self._og_search_title(webpage),
            'description': self._og_search_description(webpage),
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/franceculture.py (Python)

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

import re
from .common import InfoExtractor
from ..utils import (
    determine_ext,
    extract_attributes,
    int_or_none,
    traverse_obj,
)


class FranceCultureIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?franceculture\.fr/emissions/(?:[^/]+/)*(?P<id>[^/?#&]+)'
    _TESTS = [{
        # playlist
        'url': 'https://www.franceculture.fr/emissions/hasta-dente',
        'playlist_count': 12,
        'info_dict': {
            'id': 'hasta-dente',
            'title': 'Hasta Dente !',
            'description': None,
        }
    }, {
        'url': 'https://www.franceculture.fr/emissions/carnet-nomade/rendez-vous-au-pays-des-geeks',
        'info_dict': {
            'id': 'rendez-vous-au-pays-des-geeks',
            'display_id': 'rendez-vous-au-pays-des-geeks',
            'ext': 'mp3',
            'title': 'Rendez-vous au pays des geeks',
            'thumbnail': r're:^https?://.*\.jpg$',
            'upload_date': '20140301',
            'vcodec': 'none',
            'duration': 3569,
            'description': None,
        }
    }, {
        # no thumbnail
        'url': 'https://www.franceculture.fr/emissions/la-recherche-montre-en-main/la-recherche-montre-en-main-du-mercredi-10-octobre-2018',
        'only_matching': True,
    }]


Review comment (suggestion):
Add a test for the entries as well. Like this:
```py
        'url': ...,
        'info_dict': {
            ...
        },
        'playlist': [{
            'md5': ...,
            'info_dict': {
                ...
            },
        }],
        'params': {'playlist_end': 1},
```

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

import re
from .common import InfoExtractor
from ..utils import (
    determine_ext,
    extract_attributes,
    int_or_none,
    traverse_obj,
    unified_strdate,
)


class FranceCultureIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?franceculture\.fr/emissions/(?:[^/]+/)*(?P<id>[^/?#&]+)'
    _TESTS = [{
        # playlist
        'url': 'https://www.franceculture.fr/emissions/serie/hasta-dente',
        'playlist_count': 12,
        'info_dict': {
            'id': 'hasta-dente',
            'title': 'Hasta Dente',
            'description': 'md5:57479af50648d14e9bb649e6b1f8f911',
            'thumbnail': r're:^https?://.*\.jpg$',
            'upload_date': '20201024',
        },
        'playlist': [{
            'info_dict': {
                'id': '3c1c2e55-41a0-11e5-9fe0-005056a87c89',
                'ext': 'mp3',
                'title': 'Jeudi, vous avez dit bizarre ?',
                'description': 'md5:47cf1e00cc21c86b0210279996a812c6',
                'duration': 604,
                'upload_date': '20201024',
                'thumbnail': r're:^https?://.*\.jpg$',
                'timestamp': 1603576680
            },
        },
        ],
    }, {
        'url': 'https://www.franceculture.fr/emissions/carnet-nomade/rendez-vous-au-pays-des-geeks',
        'info_dict': {
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/fujitv.py (Python)

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

from .common import InfoExtractor


class FujiTVFODPlus7IE(InfoExtractor):
    _VALID_URL = r'https?://i\.fod\.fujitv\.co\.jp/title/[0-9a-z]{4}/(?P<id>[0-9a-z]+)'
    _BASE_URL = 'http://i.fod.fujitv.co.jp/'
    _BITRATE_MAP = {
        300: (320, 180),
        800: (640, 360),
        1200: (1280, 720),
        2000: (1280, 720),
    }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        formats = self._extract_m3u8_formats(
            self._BASE_URL + 'abr/pc_html5/%s.m3u8' % video_id, video_id, 'mp4')
        for f in formats:
            wh = self._BITRATE_MAP.get(f.get('tbr'))
            if wh:
                f.update({
                    'width': wh[0],
                    'height': wh[1],
                })
        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': video_id,
            'formats': formats,

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://i\.fod\.fujitv\.co\.jp/plus7/web/[0-9a-z]{4}/(?P<id>[0-9a-z]+)'
```

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

from .common import InfoExtractor


class FujiTVFODPlus7IE(InfoExtractor):
    _VALID_URL = r'https?://i\.fod\.fujitv\.co\.jp/plus7/web/[0-9a-z]{4}/(?P<id>[0-9a-z]+)'
    _BASE_URL = 'http://i.fod.fujitv.co.jp/'
    _BITRATE_MAP = {
        300: (320, 180),
        800: (640, 360),
        1200: (1280, 720),
        2000: (1280, 720),
    }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        formats = self._extract_m3u8_formats(
            self._BASE_URL + 'abr/pc_html5/%s.m3u8' % video_id, video_id, 'mp4')
        for f in formats:
            wh = self._BITRATE_MAP.get(f.get('tbr'))
            if wh:
                f.update({
                    'width': wh[0],
                    'height': wh[1],
                })
        self._sort_formats(formats)

        return {
            'id': video_id,
            'title': video_id,
            'formats': formats,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/megatvcom.py (Python)

Code before:
    @classmethod
    def _extract_urls(cls, webpage):
        for mobj in cls._EMBED_RE.finditer(webpage):
            yield unescapeHTML(mobj.group('url'))

    def _match_canonical_url(self, webpage):
        LINK_RE = r'''(?x)
        <link(?:
            rel=(?P<_q1>["'])(?P<canonical>canonical)(?P=_q1)|
            href=(?P<_q2>["'])(?P<href>(?:(?!(?P=_q2)).)+)(?P=_q2)|
            [^>]*?
        )+>
        '''
        for mobj in re.finditer(LINK_RE, webpage):
            canonical, href = mobj.group('canonical', 'href')
            if canonical and href:
                return unescapeHTML(href)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        player_attrs = self._extract_player_attrs(webpage)
        canonical_url = player_attrs.get('share_url') or self._match_canonical_url(webpage)
        if not canonical_url:
            raise ExtractorError('canonical URL not found')
        video_id = parse_qs(urlparse(canonical_url).query)['p'][0]

        # Resolve the canonical URL, following redirects, and defer to
        # megatvcom, as the metadata extracted from the embeddable page some
        # times are slightly different, for the same video
        canonical_url = self._request_webpage(
            HEADRequest(canonical_url), video_id,
            note='Resolve canonical URL',
            errnote='Could not resolve canonical URL').geturl()
        return self.url_result(canonical_url, MegaTVComIE.ie_key(), video_id)


Review comment (suggestion):
```suggestion
        video_id = parse_qs(canonical_url)['p'][0]
```
import `parse_qs` from utils

Code after:
            yield unescapeHTML(mobj.group('url'))

    def _match_canonical_url(self, webpage):
        LINK_RE = r'''(?x)
        <link(?:
            rel=(?P<_q1>["'])(?P<canonical>canonical)(?P=_q1)|
            href=(?P<_q2>["'])(?P<href>(?:(?!(?P=_q2)).)+)(?P=_q2)|
            [^>]*?
        )+>
        '''
        for mobj in re.finditer(LINK_RE, webpage):
            canonical, href = mobj.group('canonical', 'href')
            if canonical and href:
                return unescapeHTML(href)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        player_attrs = self._extract_player_attrs(webpage)
        canonical_url = player_attrs.get('share_url') or self._match_canonical_url(webpage)
        if not canonical_url:
            raise ExtractorError('canonical URL not found')
        video_id = parse_qs(canonical_url)['p'][0]

        # Defer to megatvcom as the metadata extracted from the embeddable page some
        # times are slightly different, for the same video
        canonical_url = self._request_webpage(
            HEADRequest(canonical_url), video_id,
            note='Resolve canonical URL',
            errnote='Could not resolve canonical URL').geturl()
        return self.url_result(canonical_url, MegaTVComIE.ie_key(), video_id)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/megatvcom.py (Python)

Code before:

    def _match_canonical_url(self, webpage):
        LINK_RE = r'''(?x)
        <link(?:
            rel=(?P<_q1>["'])(?P<canonical>canonical)(?P=_q1)|
            href=(?P<_q2>["'])(?P<href>(?:(?!(?P=_q2)).)+)(?P=_q2)|
            [^>]*?
        )+>
        '''
        for mobj in re.finditer(LINK_RE, webpage):
            canonical, href = mobj.group('canonical', 'href')
            if canonical and href:
                return unescapeHTML(href)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        player_attrs = self._extract_player_attrs(webpage)
        canonical_url = player_attrs.get('share_url') or self._match_canonical_url(webpage)
        if not canonical_url:
            raise ExtractorError('canonical URL not found')
        video_id = parse_qs(urlparse(canonical_url).query)['p'][0]

        # Resolve the canonical URL, following redirects, and defer to
        # megatvcom, as the metadata extracted from the embeddable page some
        # times are slightly different, for the same video
        canonical_url = self._request_webpage(
            HEADRequest(canonical_url), video_id,
            note='Resolve canonical URL',
            errnote='Could not resolve canonical URL').geturl()
        return self.url_result(canonical_url, MegaTVComIE.ie_key(), video_id)


Review comment (refactor):
```suggestion
        # Defer to megatvcom as the metadata extracted from the embeddable page some
        # times are slightly different, for the same video
```
this is the only part that is non-obvious from the code

Code after:
        <link(?:
            rel=(?P<_q1>["'])(?P<canonical>canonical)(?P=_q1)|
            href=(?P<_q2>["'])(?P<href>(?:(?!(?P=_q2)).)+)(?P=_q2)|
            [^>]*?
        )+>
        '''
        for mobj in re.finditer(LINK_RE, webpage):
            canonical, href = mobj.group('canonical', 'href')
            if canonical and href:
                return unescapeHTML(href)

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        player_attrs = self._extract_player_attrs(webpage)
        canonical_url = player_attrs.get('share_url') or self._match_canonical_url(webpage)
        if not canonical_url:
            raise ExtractorError('canonical URL not found')
        video_id = parse_qs(canonical_url)['p'][0]

        # Defer to megatvcom as the metadata extracted from the embeddable page some
        # times are slightly different, for the same video
        canonical_url = self._request_webpage(
            HEADRequest(canonical_url), video_id,
            note='Resolve canonical URL',
            errnote='Could not resolve canonical URL').geturl()
        return self.url_result(canonical_url, MegaTVComIE.ie_key(), video_id)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/megatvcom.py (Python)

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

import re
from urllib.parse import (
    parse_qs,
    urlparse,
)

from .common import InfoExtractor
from ..utils import (
    clean_html,
    determine_ext,
    ExtractorError,
    extract_attributes,
    get_element_by_class,
    get_element_html_by_id,
    HEADRequest,
    unescapeHTML,
    unified_timestamp,
)


class MegaTVComBaseIE(InfoExtractor):
    _PLAYER_DIV_ID = 'player_div_id'

    def _extract_player_attrs(self, webpage):
        player_el = get_element_html_by_id(self._PLAYER_DIV_ID, webpage)
        return {
            re.sub(r'^data-(?:kwik_)?', '', k): v
            for k, v in extract_attributes(player_el).items()
            if k not in ('id',)
        }


class MegaTVComIE(MegaTVComBaseIE):
    IE_NAME = 'megatvcom'
    IE_DESC = 'megatv.com videos'
    _VALID_URL = r'https?://(?:www\.)?megatv\.com/(?:\d{4}/\d{2}/\d{2}|[^/]+/(?P<id>\d+))/(?P<slug>[^/]+)'

    _TESTS = [{

Review comment (security):
```suggestion
    parse_qs,
    unescapeHTML,
```

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

import re

from .common import InfoExtractor
from ..utils import (
    clean_html,
    determine_ext,
    ExtractorError,
    extract_attributes,
    get_element_by_class,
    get_element_html_by_id,
    HEADRequest,
    parse_qs,
    unescapeHTML,
    unified_timestamp,
)


class MegaTVComBaseIE(InfoExtractor):
    _PLAYER_DIV_ID = 'player_div_id'

    def _extract_player_attrs(self, webpage):
        player_el = get_element_html_by_id(self._PLAYER_DIV_ID, webpage)
        return {
            re.sub(r'^data-(?:kwik_)?', '', k): v
            for k, v in extract_attributes(player_el).items()
            if k not in ('id',)
        }


class MegaTVComIE(MegaTVComBaseIE):
    IE_NAME = 'megatvcom'
    IE_DESC = 'megatv.com videos'
    _VALID_URL = r'https?://(?:www\.)?megatv\.com/(?:\d{4}/\d{2}/\d{2}|[^/]+/(?P<id>\d+))/(?P<slug>[^/]+)'

    _TESTS = [{
        'url': 'https://www.megatv.com/2021/10/23/egkainia-gia-ti-nea-skini-omega-tou-dimotikou-theatrou-peiraia/',
        'md5': '6546a1a37fff0dd51c9dce5f490b7d7d',
        'info_dict': {