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

Code before:

    _TESTS = [{
        'url': 'https://www.la7.it/propagandalive/podcast',
        'info_dict': {
            'id': 'propagandalive',
            'title': "Propaganda Live",
        },
        'playlist_count': 10,
    }]

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

        title = (self._html_search_regex(
            r'<h1.*?>(.+?)</h1>', webpage, 'title', fatal=False, default=None)
            or self._og_search_title(webpage))
        ppn = self._search_regex(
            r'window\.ppN\s*=\s*([\'"])(?P<ppn>.+?)\1',
            webpage, 'ppn', group='ppn', default=None)

        entries = []
        for episode in re.finditer(
                r'<div class="container-podcast-property">([\s\S]+?)(?:</div>\s*){3}',
                webpage):
            entries.append(self._extract_infos(episode.group(1), ppn=ppn))

        return self.playlist_result(entries, playlist_id, title)


Review comment (refactor):
```suggestion
            entries.append(self._extract_info(episode.group(1), ppn=ppn))
```

Code after:
    _VALID_URL = r'(https?://)?(www\.)?la7\.it/(?P<id>[^/]+)/podcast/?(?:$|[#?])'

    _TESTS = [{
        'url': 'https://www.la7.it/propagandalive/podcast',
        'info_dict': {
            'id': 'propagandalive',
            'title': "Propaganda Live",
        },
        'playlist_count': 10,
    }]

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

        title = (
            self._html_search_regex(
                r'<h1.*?>(.+?)</h1>', webpage, 'title', fatal=False, default=None)
            or self._og_search_title(webpage))
        ppn = self._search_regex(
            r'window\.ppN\s*=\s*([\'"])(?P<ppn>.+?)\1',
            webpage, 'ppn', group='ppn', default=None)

        entries = []
        for episode in re.finditer(
                r'<div class="container-podcast-property">([\s\S]+?)(?:</div>\s*){3}',
                webpage):
            entries.append(self._extract_info(episode.group(1), ppn=ppn))

        return self.playlist_result(entries, playlist_id, title)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/discoveryplusindia.py (Python)

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

import json
import re

from ..compat import compat_str
from .common import InfoExtractor
from .dplay import DPlayIE
from ..utils import try_get


class DiscoveryPlusIndiaIE(DPlayIE):
    _VALID_URL = r'https?://(?:www\.)?discoveryplus\.in/videos?' + DPlayIE._PATH_REGEX
    _TESTS = [{
        'url': 'https://www.discoveryplus.in/videos/how-do-they-do-it/fugu-and-more?seasonId=8&type=EPISODE',
        'info_dict': {
            'id': '27104',
            'ext': 'mp4',
            'display_id': 'how-do-they-do-it/fugu-and-more',
            'title': 'Fugu and More',
            'description': 'The Japanese catch, prepare and eat the deadliest fish on the planet.',
            'duration': 1319,
            'timestamp': 1582309800,
            'upload_date': '20200221',
            'series': 'How Do They Do It?',
            'season_number': 8,
            'episode_number': 2,
            'creator': 'Discovery Channel',
        },
        'params': {
            'format': 'bestvideo',
            'skip_download': True,
        },
        'skip': 'Cookies (not necessarily logged in) are needed'

Review comment (refactor):
```suggestion
from ..compat import compat_str
from ..utils import try_get
from .common import InfoExtractor
from .dplay import DPlayIE
```

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

import json
import re

from ..compat import compat_str
from ..utils import try_get
from .common import InfoExtractor
from .dplay import DPlayIE


class DiscoveryPlusIndiaIE(DPlayIE):
    _VALID_URL = r'https?://(?:www\.)?discoveryplus\.in/videos?' + DPlayIE._PATH_REGEX
    _TESTS = [{
        'url': 'https://www.discoveryplus.in/videos/how-do-they-do-it/fugu-and-more?seasonId=8&type=EPISODE',
        'info_dict': {
            'id': '27104',
            'ext': 'mp4',
            'display_id': 'how-do-they-do-it/fugu-and-more',
            'title': 'Fugu and More',
            'description': 'The Japanese catch, prepare and eat the deadliest fish on the planet.',
            'duration': 1319,
            'timestamp': 1582309800,
            'upload_date': '20200221',
            'series': 'How Do They Do It?',
            'season_number': 8,
            'episode_number': 2,
            'creator': 'Discovery Channel',
        },
        'params': {
            'format': 'bestvideo',
            'skip_download': True,
        },
        'skip': 'Cookies (not necessarily logged in) are needed'
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/tubitv.py (Python)

Code before:

class TubiTvShowIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?tubitv\.com/series/[0-9]+/(?P<show_name>\S*)(?:\?\S*)'
    _TESTS = [{
        'url': 'https://tubitv.com/series/3936/the-joy-of-painting-with-bob-ross?start=true',
        'playlist_mincount': 390,
        'info_dict': {
            'id': 'the-joy-of-painting-with-bob-ross',
        }
    }
    ]

    def _entries(self, show_url, show_name):
        show_webpage = self._download_webpage(show_url, show_name).replace('undefined', '\"undefined\"')
        show_json = self._parse_json(self._search_regex(
            r"window\.__data\s*=\s*({.+?});\s*</script>",
            show_webpage, 'data'), show_name)['video']
        for episode_id in show_json['fullContentById'].keys():
            yield self.url_result(
                'tubi:%s' % episode_id,
                ie=TubiTvIE.ie_key(), video_id=episode_id)

    def _real_extract(self, url):
        show_name = re.match(self._VALID_URL, url).group('show_name')
        show_url = url
        return self.playlist_result(self._entries(show_url, show_name), playlist_id=show_name)


Review comment (suggestion):
```suggestion
        return self.playlist_result(self._entries(url, show_name), playlist_id=show_name)
```

Code after:


class TubiTvShowIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?tubitv\.com/series/[0-9]+/(?P<show_name>[^/?#]+)'
    _TESTS = [{
        'url': 'https://tubitv.com/series/3936/the-joy-of-painting-with-bob-ross?start=true',
        'playlist_mincount': 390,
        'info_dict': {
            'id': 'the-joy-of-painting-with-bob-ross',
        }
    }]

    def _entries(self, show_url, show_name):
        show_webpage = self._download_webpage(show_url, show_name)
        show_json = self._parse_json(self._search_regex(
            r"window\.__data\s*=\s*({.+?});\s*</script>",
            show_webpage, 'data',), show_name, transform_source=js_to_json)['video']
        for episode_id in show_json['fullContentById'].keys():
            yield self.url_result(
                'tubitv:%s' % episode_id,
                ie=TubiTvIE.ie_key(), video_id=episode_id)

    def _real_extract(self, url):
        show_name = re.match(self._VALID_URL, url).group('show_name')
        return self.playlist_result(self._entries(url, show_name), playlist_id=show_name)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/tubitv.py (Python)

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

import re

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    int_or_none,
    sanitized_Request,
    urlencode_postdata,
    js_to_json
)


class TubiTvIE(InfoExtractor):
    _VALID_URL = r'''(?x)
                    (?:
                        tubitv:|
                        https?://(?:www\.)?tubitv\.com/(?:video|movies|tv-shows)/
                    )
                    (?P<id>[0-9]+)'''
    _LOGIN_URL = 'http://tubitv.com/login'
    _NETRC_MACHINE = 'tubitv'
    _GEO_COUNTRIES = ['US']
    _TESTS = [{
        'url': 'http://tubitv.com/video/283829/the_comedian_at_the_friday',
        'md5': '43ac06be9326f41912dc64ccf7a80320',
        'info_dict': {
            'id': '283829',
            'ext': 'mp4',
            'title': 'The Comedian at The Friday',
            'description': 'A stand up comedian is forced to look at the decisions in his life while on a one week trip to the west coast.',
            'uploader_id': 'bc168bee0d18dd1cb3b86c68706ab434',
        },
    }, {
        'url': 'http://tubitv.com/tv-shows/321886/s01_e01_on_nom_stories',

Review comment (security):
```suggestion
    int_or_none,
    js_to_json,
    sanitized_Request,
    urlencode_postdata,
```

Imports are done in alphabetical order for consistency

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

import re

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    int_or_none,
    js_to_json,
    sanitized_Request,
    urlencode_postdata,
)


class TubiTvIE(InfoExtractor):
    _VALID_URL = r'''(?x)
                    (?:
                        tubitv:|
                        https?://(?:www\.)?tubitv\.com/(?:video|movies|tv-shows)/
                    )
                    (?P<id>[0-9]+)'''
    _LOGIN_URL = 'http://tubitv.com/login'
    _NETRC_MACHINE = 'tubitv'
    _GEO_COUNTRIES = ['US']
    _TESTS = [{
        'url': 'http://tubitv.com/video/283829/the_comedian_at_the_friday',
        'md5': '43ac06be9326f41912dc64ccf7a80320',
        'info_dict': {
            'id': '283829',
            'ext': 'mp4',
            'title': 'The Comedian at The Friday',
            'description': 'A stand up comedian is forced to look at the decisions in his life while on a one week trip to the west coast.',
            'uploader_id': 'bc168bee0d18dd1cb3b86c68706ab434',
        },
    }, {
        'url': 'http://tubitv.com/tv-shows/321886/s01_e01_on_nom_stories',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mxplayer.py (Python)

Code before:
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from ..compat import compat_str
from ..utils import (
    ExtractorError,
    js_to_json,
    qualities,
    try_get,
    url_or_none,
    urljoin,
)


class MxplayerIE(InfoExtractor):
    _VALID_URL = r'(?:https?://)(?:www\.)?mxplayer\.in/(?:show/[-\w]+/[-\w]+|movie)/(?P<display_id>[-\w]+)-(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://www.mxplayer.in/movie/watch-knock-knock-hindi-dubbed-movie-online-b9fa28df3bfb8758874735bbd7d2655a?watch=true',
        'info_dict': {
            'id': 'b9fa28df3bfb8758874735bbd7d2655a',
            'ext': 'mp4',
            'title': 'Knock Knock (Hindi Dubbed)',
            'description': 'md5:b195ba93ff1987309cfa58e2839d2a5b'
        },
        'params': {
            'skip_download': True,
            'format': 'bestvideo'
        }
    }, {
        'url': 'https://www.mxplayer.in/show/watch-shaitaan/season-1/the-infamous-taxi-gang-of-meerut-online-45055d5bcff169ad48f2ad7552a83d6c',
        'info_dict': {
            'id': '45055d5bcff169ad48f2ad7552a83d6c',
            'ext': 'm3u8',
            'title': 'The infamous taxi gang of Meerut',
            'description': 'md5:033a0a7e3fd147be4fb7e07a01a3dc28',
            'season': 'Season 1',
            'series': 'Shaitaan'
        },
        'params': {
            'skip_download': True,
        }

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?mxplayer\.in/(?:movie|show/[-\w]+/[-\w]+)/(?P<display_id>[-\w]+)-(?P<id>\w+)'
```
may be easier to read. Or even better, split it into multiple lines using `(?x)`

Code after:
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from ..compat import compat_str
from ..utils import (
    ExtractorError,
    js_to_json,
    qualities,
    try_get,
    url_or_none,
    urljoin,
)


class MxplayerIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?mxplayer\.in/(?:movie|show/[-\w]+/[-\w]+)/(?P<display_id>[-\w]+)-(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://www.mxplayer.in/movie/watch-knock-knock-hindi-dubbed-movie-online-b9fa28df3bfb8758874735bbd7d2655a?watch=true',
        'info_dict': {
            'id': 'b9fa28df3bfb8758874735bbd7d2655a',
            'ext': 'mp4',
            'title': 'Knock Knock (Hindi Dubbed)',
            'description': 'md5:b195ba93ff1987309cfa58e2839d2a5b'
        },
        'params': {
            'skip_download': True,
            'format': 'bestvideo'
        }
    }, {
        'url': 'https://www.mxplayer.in/show/watch-shaitaan/season-1/the-infamous-taxi-gang-of-meerut-online-45055d5bcff169ad48f2ad7552a83d6c',
        'info_dict': {
            'id': '45055d5bcff169ad48f2ad7552a83d6c',
            'ext': 'm3u8',
            'title': 'The infamous taxi gang of Meerut',
            'description': 'md5:033a0a7e3fd147be4fb7e07a01a3dc28',
            'season': 'Season 1',
            'series': 'Shaitaan'
        },
        'params': {
            'skip_download': True,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/whowatch.py (Python)

Code before:
                    'height': try_get(hls_fmts, lambda x: x[0]['height'], int),
                })

        self._sort_formats(formats)

        uploader_url = try_get(metadata, lambda x: x['live']['user']['user_path'], compat_str)
        if uploader_url:
            uploader_url = 'https://whowatch.tv/profile/%s' % uploader_url
        uploader_id = compat_str(try_get(metadata, lambda x: x['live']['user']['id'], int))
        uploader = try_get(metadata, lambda x: x['live']['user']['name'], compat_str)
        thumbnail = try_get(metadata, lambda x: x['live']['latest_thumbnail_url'], compat_str)
        upload_date = try_get(metadata, lambda x: x['live']['started_at'], int)
        if upload_date is not None:
            upload_date = datetime.datetime.fromtimestamp(upload_date / 1000).strftime('%Y%m%d')
        view_count = try_get(metadata, lambda x: x['live']['total_view_count'], int)
        comment_count = try_get(metadata, lambda x: x['live']['comment_count'], int)

        return {
            'id': video_id,
            'title': title,
            'uploader_id': uploader_id,
            'uploader_url': uploader_url,
            'uploader': uploader,
            'formats': formats,
            'thumbnail': thumbnail,
            'upload_date': upload_date,
            'view_count': view_count,
            'comment_count': comment_count,
            'is_live': True,
        }


Review comment (suggestion):
`upload_date` will be automatically calculated from `timestamp`

```suggestion
            'timestamp': timestamp,
```


Code after:

        # This contains the same formats as the above manifests and is used only as a fallback
        formats.extend(self._extract_m3u8_formats(
            hls_url, video_id, ext='mp4', entry_protocol='m3u8',
            m3u8_id='hls'))
        self._remove_duplicate_formats(formats)
        self._sort_formats(formats)

        uploader_url = try_get(metadata, lambda x: x['live']['user']['user_path'], compat_str)
        if uploader_url:
            uploader_url = 'https://whowatch.tv/profile/%s' % uploader_url
        uploader_id = compat_str(try_get(metadata, lambda x: x['live']['user']['id'], int))
        uploader = try_get(metadata, lambda x: x['live']['user']['name'], compat_str)
        thumbnail = try_get(metadata, lambda x: x['live']['latest_thumbnail_url'], compat_str)
        timestamp = int_or_none(try_get(metadata, lambda x: x['live']['started_at'], int), scale=1000)
        view_count = try_get(metadata, lambda x: x['live']['total_view_count'], int)
        comment_count = try_get(metadata, lambda x: x['live']['comment_count'], int)

        return {
            'id': video_id,
            'title': title,
            'uploader_id': uploader_id,
            'uploader_url': uploader_url,
            'uploader': uploader,
            'formats': formats,
            'thumbnail': thumbnail,
            'timestamp': timestamp,
            'view_count': view_count,
            'comment_count': comment_count,
            'is_live': True,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/tenplay.py (Python)

Code before:
# coding: utf-8
from __future__ import unicode_literals
from datetime import datetime
import base64
from .common import InfoExtractor
from ..utils import (
    HEADRequest,
    parse_age_limit,
    urlencode_postdata,
)


class TenPlayIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
    _NETRC_MACHINE = '10play'
    _TESTS = [{
        'url': 'https://10play.com.au/todd-sampsons-body-hack/episodes/season-4/episode-7/tpv200921kvngh',
        'info_dict': {
            'id': 'tpv200928zskgi',
            'ext': 'mp4',
            'title': "Todd Sampson's Body Hack - S4 Ep. 2",
            'description': 'md5:a73ea55671034c6367784405423ef5a0',
            'age_limit': 15,
            'timestamp': 1601379660,
            'upload_date': '20200909',
            'uploader_id': 'Channel 10',
        },
        'params': {
            'skip_download': True,
        }

Review comment (suggestion):
```suggestion

from datetime import datetime
import base64

```

seperate into groups

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

from datetime import datetime
import base64

from .common import InfoExtractor
from ..utils import (
    HEADRequest,
    urlencode_postdata,
)


class TenPlayIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?10play\.com\.au/(?:[^/]+/)+(?P<id>tpv\d{6}[a-z]{5})'
    _NETRC_MACHINE = '10play'
    _TESTS = [{
        'url': 'https://10play.com.au/todd-sampsons-body-hack/episodes/season-4/episode-7/tpv200921kvngh',
        'info_dict': {
            'id': '6192880312001',
            'ext': 'mp4',
            'title': "Todd Sampson's Body Hack - S4 Ep. 2",
            'description': 'md5:fa278820ad90f08ea187f9458316ac74',
            'age_limit': 15,
            'timestamp': 1600770600,
            'upload_date': '20200922',
            'uploader': 'Channel 10',
            'uploader_id': '2199827728001'
        },
        'params': {
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/tenplay.py (Python)

Code before:
        content_id = self._match_id(url)
        _token = self._get_bearer_token(content_id)
        data = self._download_json(
            'https://10play.com.au/api/v1/videos/' + content_id, content_id)
        _video_url = self._download_json(
            data.get('playbackApiEndpoint'), content_id, 'Downloading video JSON',
            headers={'Authorization': _token}).get('source')
        m3u8_url = self._request_webpage(HEADRequest(
            _video_url), content_id).geturl()
        if '10play-not-in-oz' in m3u8_url:
            self.raise_geo_restricted(countries=['AU'])
        formats = self._extract_m3u8_formats(m3u8_url, content_id, 'mp4')
        self._sort_formats(formats)

        return {
            'formats': formats,
            'id': content_id,
            'title': data.get('title'),
            'description': data.get('description'),
            'age_limit': parse_age_limit(data.get('classification')),
            'series': data.get('showName'),
            'season': data.get('showContentSeason'),
            'timestamp': data.get('published'),
            'thumbnail': data.get('imageUrl'),
            'uploader': 'Channel 10',
            'uploaer_id': '2199827728001',
        }


Review comment (suggestion):
```suggestion
            'uploader_id': '2199827728001',
```
typo

Code after:
            'X-Network-Ten-Auth': _auth_header,
        }, data=urlencode_postdata({
            'email': username,
            'password': password,
        }))
        return "Bearer " + data['jwt']['accessToken']

    def _real_extract(self, url):
        content_id = self._match_id(url)
        _token = self._get_bearer_token(content_id)
        data = self._download_json(
            'https://10play.com.au/api/v1/videos/' + content_id, content_id)
        _video_url = self._download_json(
            data.get('playbackApiEndpoint'), content_id, 'Downloading video JSON',
            headers={'Authorization': _token}).get('source')
        m3u8_url = self._request_webpage(HEADRequest(
            _video_url), content_id).geturl()
        if '10play-not-in-oz' in m3u8_url:
            self.raise_geo_restricted(countries=['AU'])
        formats = self._extract_m3u8_formats(m3u8_url, content_id, 'mp4')
        self._sort_formats(formats)

        return {
            'formats': formats,
            'id': data.get('altId') or content_id,
            'title': data.get('title'),
            'description': data.get('description'),
            'age_limit': self._AUS_AGES[data.get('classification')],
            'series': data.get('showName'),
            'season': data.get('showContentSeason'),
            'timestamp': data.get('published'),
            'thumbnail': data.get('imageUrl'),
            'uploader': 'Channel 10',
            'uploader_id': '2199827728001',
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/audius.py (Python)

Code before:

class AudiusProfileIE(AudiusPlaylistIE):
    _VALID_URL = r'https://audius.co/(?P<id>[\w\d-]+)'
    _BASE = 'https://discovery-a.mainnet.audius.radar.tech/v1/full/'
    _TEST = {
        'url': 'https://audius.co/pzl/',
        'info_dict': {
            'id': 'ezRo7',
            'description': 'TAMALE\n\nContact: officialpzl@gmail.com',
            'title': 'pzl',
        },
        'playlist_count': 24,
    }

    def _real_extract(self, url):
        self._select_api_base()
        profile_id = self._match_id(url)
        try:
            _profile_data = self._api_request('/full/users/handle/' + profile_id, profile_id)
            _id = _profile_data[0].get('id')
            _description = _profile_data[0].get('bio')
        except ExtractorError as e:
            raise ExtractorError('Could not download profile info, ' + str(e))

        _api_call = self._api_request('/full/users/handle/%s/tracks?sort=date&limit=99999999' % profile_id, profile_id)
        return(self.playlist_result(self._build_playlist(_api_call), _id, profile_id, _description))


Review comment (suggestion):
```suggestion
        return self.playlist_result(self._build_playlist(_api_call), _id, profile_id, _description)
```

Code after:

class AudiusProfileIE(AudiusPlaylistIE):
    IE_NAME = 'audius:artist'
    IE_DESC = 'Audius.co profile/artist pages'
    _VALID_URL = r'https?://(?:www)?audius\.co/(?P<id>[^\/]+)/?(?:[?#]|$)'
    _TEST = {
        'url': 'https://audius.co/pzl/',
        'info_dict': {
            'id': 'ezRo7',
            'description': 'TAMALE\n\nContact: officialpzl@gmail.com',
            'title': 'pzl',
        },
        'playlist_count': 24,
    }

    def _real_extract(self, url):
        self._select_api_base()
        profile_id = self._match_id(url)
        try:
            _profile_data = self._api_request('/full/users/handle/' + profile_id, profile_id)
        except ExtractorError as e:
            raise ExtractorError('Could not download profile info; ' + str(e))
        profile_audius_id = _profile_data[0]['id']
        profile_bio = _profile_data[0].get('bio')

        api_call = self._api_request('/full/users/handle/%s/tracks' % profile_id, profile_id)
        return self.playlist_result(self._build_playlist(api_call), profile_audius_id, profile_id, profile_bio)