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

Code before:
        }
    }

    def _call_api(self, podcast_id, display_id):
        return self._download_json(
            f'https://player.radiozet.pl/api/podcasts/getPodcast/(node)/{podcast_id}/(station)/radiozet',
            display_id)

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        podcast_id = self._html_search_regex(r'<div id="player".*? data-id="(.+?)".*?>',
                                             webpage, 'podcast id')
        data = self._call_api(podcast_id, display_id).get('data')[0]

        return {
            'id': podcast_id,
            'display_id': display_id,
            'title': strip_or_none(data.get('title')),
            'description': strip_or_none(traverse_obj(data, ('program', 'desc'))),
            'release_timestamp': data.get('published_date'),
            'url': traverse_obj(data, ('player', 'stream')),
            'thumbnail': traverse_obj(data, ('program', 'image', 'original')),
            'duration': traverse_obj(data, ('player', 'duration')),
            'series': strip_or_none(traverse_obj(data, ('program', 'title'))),
            'creator': strip_or_none(data.get('presenter')[0].get('title')),
        }


Review comment (suggestion):
```suggestion
            'creator': strip_or_none(traverse_obj(data, ('presenter', 0, 'title'))),
```

Code after:
            'creator': 'Katarzyna Pakosińska',
        }
    }

    def _call_api(self, podcast_id, display_id):
        return self._download_json(
            f'https://player.radiozet.pl/api/podcasts/getPodcast/(node)/{podcast_id}/(station)/radiozet',
            display_id)

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        podcast_id = self._html_search_regex(r'<div.*?\sid="player".*?\sdata-id=[\'"]([^\'"]+)[\'"]',
                                             webpage, 'podcast id')
        data = self._call_api(podcast_id, display_id)['data'][0]

        return {
            'id': podcast_id,
            'display_id': display_id,
            'title': strip_or_none(data.get('title')),
            'description': strip_or_none(traverse_obj(data, ('program', 'desc'))),
            'release_timestamp': data.get('published_date'),
            'url': traverse_obj(data, ('player', 'stream')),
            'thumbnail': traverse_obj(data, ('program', 'image', 'original')),
            'duration': traverse_obj(data, ('player', 'duration')),
            'series': strip_or_none(traverse_obj(data, ('program', 'title'))),
            'creator': strip_or_none(traverse_obj(data, ('presenter', 0, 'title'))),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/linkedin.py (Python)

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

from itertools import zip_longest
import re

from .common import InfoExtractor
from ..utils import (
    clean_html,
    extract_attributes,
    ExtractorError,
    float_or_none,
    get_element_by_class,
    int_or_none,
    srt_subtitles_timecode,
    strip_or_none,
    mimetype2ext,
    try_get,
    urlencode_postdata,
    urljoin,
)


class LinkedInBase(InfoExtractor):
    _NETRC_MACHINE = 'linkedin'
    _logged_in = False

    def _real_initialize(self):
        if self._logged_in:
            return
        email, password = self._get_login_info()
        if email is None:
            return

        login_page = self._download_webpage(
            self._LOGIN_URL, None, 'Downloading login page')
        action_url = urljoin(self._LOGIN_URL, self._search_regex(
            r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page, 'post url',
            default='https://www.linkedin.com/uas/login-submit', group='url'))
        data = self._hidden_inputs(login_page)
        data.update({
            'session_key': email,
            'session_password': password,
        })
        login_submit_page = self._download_webpage(
            action_url, None, 'Logging in',
            data=urlencode_postdata(data))
        error = self._search_regex(
            r'<span[^>]+class="error"[^>]*>\s*(.+?)\s*</span>',

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

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

from itertools import zip_longest
import re

from .common import InfoExtractor
from ..utils import (
    clean_html,
    extract_attributes,
    ExtractorError,
    float_or_none,
    get_element_by_class,
    int_or_none,
    srt_subtitles_timecode,
    strip_or_none,
    mimetype2ext,
    try_get,
    urlencode_postdata,
    urljoin,
)


class LinkedInBaseIE(InfoExtractor):
    _NETRC_MACHINE = 'linkedin'
    _logged_in = False

    def _real_initialize(self):
        if self._logged_in:
            return
        email, password = self._get_login_info()
        if email is None:
            return

        login_page = self._download_webpage(
            self._LOGIN_URL, None, 'Downloading login page')
        action_url = urljoin(self._LOGIN_URL, self._search_regex(
            r'<form[^>]+action=(["\'])(?P<url>.+?)\1', login_page, 'post url',
            default='https://www.linkedin.com/uas/login-submit', group='url'))
        data = self._hidden_inputs(login_page)
        data.update({
            'session_key': email,
            'session_password': password,
        })
        login_submit_page = self._download_webpage(
            action_url, None, 'Logging in',
            data=urlencode_postdata(data))
        error = self._search_regex(
            r'<span[^>]+class="error"[^>]*>\s*(.+?)\s*</span>',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/rtrfm.py (Python)

Code before:
from __future__ import unicode_literals

from .common import InfoExtractor


class RTRFMIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?rtrfm\.com\.au/(?:shows|show-episode)/(?P<id>[^/?\#&]+)'
    _PLAY_SHOW = r"\.playShow\('(?P<show>[^']+)', *'(?P<date>[0-9]{4}-[0-9]{2}-[0-9]{2})', *'(?P<title>[^']+)'\)"
    _PLAY_SHOW_FROM = r"\.playShowFrom\('(?P<show>[^']+)', *'(?P<date>[0-9]{4}-[0-9]{2}-[0-9]{2})', *'?P<title>([^']+)', \d+\)"
    _RESTREAMS_URL = 'https://restreams.rtrfm.com.au/rzz'
    _TESTS = [
        {
            'url': 'https://rtrfm.com.au/shows/breakfast/',
            # the downloaded file changes daily so the md5 is not checkable
            'info_dict': {
                'id': r're:^breakfast-\d{4}-\d{2}-\d{2}$',
                'ext': 'mp3',
                'series': 'Breakfast with Taylah',
                'title': r're:^Breakfast with Taylah \d{4}-\d{2}-\d{2}$',
                'description': 'md5:0979c3ab1febfbec3f1ccb743633c611',
            },
            'skip': 'tests with re in the id expect the re in the filename '
                    'instead of the id, but the id depends on the date.',
        },
        {
            'url': 'https://rtrfm.com.au/show-episode/breakfast-2021-11-11/',
            'md5': '396bedf1e40f96c62b30d4999202a790',
            'info_dict': {
                'id': 'breakfast-2021-11-11',
                'ext': 'mp3',
                'series': 'Breakfast with Taylah',
                'title': 'Breakfast with Taylah 2021-11-11',
                'description': 'md5:0979c3ab1febfbec3f1ccb743633c611',
            },

Review comment (refactor):
can be combined into `playShow(?:From)?` since the 2 regex are otherwise same. Also, move this directly to L57

Code after:
from __future__ import unicode_literals

from .common import InfoExtractor


class RTRFMIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?rtrfm\.com\.au/(?:shows|show-episode)/(?P<id>[^/?\#&]+)'
    _TESTS = [
        {
            'url': 'https://rtrfm.com.au/shows/breakfast/',
            'md5': '46168394d3a5ce237cf47e85d0745413',
            'info_dict': {
                'id': 'breakfast-2021-11-16',
                'ext': 'mp3',
                'series': 'Breakfast with Taylah',
                'title': r're:^Breakfast with Taylah \d{4}-\d{2}-\d{2}$',
                'description': 'md5:0979c3ab1febfbec3f1ccb743633c611',
            },
            'skip': 'ID and md5 changes daily',
        },
        {
            'url': 'https://rtrfm.com.au/show-episode/breakfast-2021-11-11/',
            'md5': '396bedf1e40f96c62b30d4999202a790',
            'info_dict': {
                'id': 'breakfast-2021-11-11',
                'ext': 'mp3',
                'series': 'Breakfast with Taylah',
                'title': 'Breakfast with Taylah 2021-11-11',
                'description': 'md5:0979c3ab1febfbec3f1ccb743633c611',
            },
        },
        {
            'url': 'https://rtrfm.com.au/show-episode/breakfast-2020-06-01/',
            'md5': '594027f513ec36a24b15d65007a24dff',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/rtrfm.py (Python)

Code before:
        },
        {
            'url': 'https://rtrfm.com.au/show-episode/breakfast-2020-06-01/',
            'md5': '594027f513ec36a24b15d65007a24dff',
            'info_dict': {
                'id': 'breakfast-2020-06-01',
                'ext': 'mp3',
                'series': 'Breakfast with Taylah',
                'title': 'Breakfast with Taylah 2020-06-01',
                'description': r're:^Breakfast with Taylah ',
            },
            'params': {
                # This audio has expired
                'skip_download': True,
            },
        },
    ]

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        show, date, title = self._search_regex(
            [self._PLAY_SHOW, self._PLAY_SHOW_FROM],
            webpage, 'details', group=('show', 'date', 'title'))
        url = self._download_json(
            self._RESTREAMS_URL, show, 'Downloading MP3 URL', query={'n': show, 'd': date})['u']
        return {
            'id': '%s-%s' % (show, date),
            'title': '%s %s' % (title, date),
            'series': title,
            'url': url,
            'release_date': date,
            'description': self._og_search_description(webpage),
        }


Review comment (suggestion):
```suggestion
            'https://restreams.rtrfm.com.au/rzz',
            show, 'Downloading MP3 URL', query={'n': show, 'd': date})['u']
```

Code after:
            'info_dict': {
                'id': 'breakfast-2020-06-01',
                'ext': 'mp3',
                'series': 'Breakfast with Taylah',
                'title': 'Breakfast with Taylah 2020-06-01',
                'description': r're:^Breakfast with Taylah ',
            },
            'skip': 'This audio has expired',
        },
    ]

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage(url, display_id)
        show, date, title = self._search_regex(
            r'''\.playShow(?:From)?\(['"](?P<show>[^'"]+)['"],\s*['"](?P<date>[0-9]{4}-[0-9]{2}-[0-9]{2})['"],\s*['"](?P<title>[^'"]+)['"]''',
            webpage, 'details', group=('show', 'date', 'title'))
        url = self._download_json(
            'https://restreams.rtrfm.com.au/rzz',
            show, 'Downloading MP3 URL', query={'n': show, 'd': date})['u']
        # This is the only indicator of an error until trying to download the URL and
        # downloads of mp4 URLs always fail (403 for current episodes, 404 for missing).
        if '.mp4' in url:
            url = None
            self.raise_no_formats('Expired or no episode on this date', expected=True)
        return {
            'id': '%s-%s' % (show, date),
            'title': '%s %s' % (title, date),
            'series': title,
            'url': url,
            'release_date': date,
            'description': self._og_search_description(webpage),
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/blogger.py (Python)

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

import re

from ..utils import mimetype2ext, parse_duration, parse_qs, str_or_none, traverse_obj
from .common import InfoExtractor


class BloggerIE(InfoExtractor):
    IE_NAME = 'blogger.com'
    _VALID_URL = r'https?://(?:www\.)?blogger\.com/video\.g\?token=(?P<id>.+)'
    _VALID_EMBED = r'''<iframe[^>]+src=["']((?:https?:)?//(?:www\.)?blogger\.com/video\.g\?token=[^"']+)["']'''
    _TESTS = [{
        'url': 'https://www.blogger.com/video.g?token=AD6v5dzEe9hfcARr5Hlq1WTkYy6t-fXH3BBahVhGvVHe5szdEUBEloSEDSTA8-b111089KbfWuBvTN7fnbxMtymsHhXAXwVvyzHH4Qch2cfLQdGxKQrrEuFpC1amSl_9GuLWODjPgw',
        'md5': 'f1bc19b6ea1b0fd1d81e84ca9ec467ac',
        'info_dict': {
            'id': 'BLOGGER-video-3c740e3a49197e16-796',
            'title': 'BLOGGER-video-3c740e3a49197e16-796',
            'ext': 'mp4',
            'thumbnail': r're:^https?://.*',
        }
    }]

    @staticmethod
    def _extract_urls(webpage):
        return re.findall(BloggerIE._VALID_EMBED, webpage)

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

Review comment (suggestion):
```suggestion
from ..utils import (
    mimetype2ext,
    parse_duration,
    parse_qs,
    str_or_none,
    traverse_obj,
)
```

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

import re

from ..utils import (
    mimetype2ext,
    parse_duration,
    parse_qs,
    str_or_none,
    traverse_obj,
)
from .common import InfoExtractor


class BloggerIE(InfoExtractor):
    IE_NAME = 'blogger.com'
    _VALID_URL = r'https?://(?:www\.)?blogger\.com/video\.g\?token=(?P<id>.+)'
    _VALID_EMBED = r'''<iframe[^>]+src=["']((?:https?:)?//(?:www\.)?blogger\.com/video\.g\?token=[^"']+)["']'''
    _TESTS = [{
        'url': 'https://www.blogger.com/video.g?token=AD6v5dzEe9hfcARr5Hlq1WTkYy6t-fXH3BBahVhGvVHe5szdEUBEloSEDSTA8-b111089KbfWuBvTN7fnbxMtymsHhXAXwVvyzHH4Qch2cfLQdGxKQrrEuFpC1amSl_9GuLWODjPgw',
        'md5': 'f1bc19b6ea1b0fd1d81e84ca9ec467ac',
        'info_dict': {
            'id': 'BLOGGER-video-3c740e3a49197e16-796',
            'title': 'BLOGGER-video-3c740e3a49197e16-796',
            'ext': 'mp4',
            'thumbnail': r're:^https?://.*',
            'duration': 76.068,
        }
    }]
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/redgifs.py (Python)

Code before:
# coding: utf-8

from __future__ import unicode_literals

from .common import InfoExtractor

from ..utils import (
    ExtractorError,
    int_or_none,
    qualities,
)


class RedGifsIE(InfoExtractor):
    _VALID_URL = r'https?://(?:(?:www|thumbs2?)\.)?redgifs\.com/(?:watch/)?(?P<id>[^-/?#\.]+)'
    _TESTS = [{
        'url': 'https://www.redgifs.com/watch/squeakyhelplesswisent',
        'info_dict': {
            'id': 'squeakyhelplesswisent',
            'ext': 'mp4',
            'title': 'Hotwife Legs Thick',
            'timestamp': 1636287915,
            'upload_date': '20211107',
            'uploader': 'ignored52',
            'duration': 16,
            'view_count': int,
            'like_count': int,
            'categories': list,
            'age_limit': 18,
        }
    }, {
        'url': 'https://thumbs2.redgifs.com/SqueakyHelplessWisent-mobile.mp4#t=0',
        'info_dict': {
            'id': 'squeakyhelplesswisent',
            'ext': 'mp4',
            'title': 'Hotwife Legs Thick',
            'timestamp': 1636287915,

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

Code after:
# coding: utf-8

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


class RedGifsIE(InfoExtractor):
    _VALID_URL = r'https?://(?:(?:www|thumbs2?)\.)?redgifs\.com/(?:watch/)?(?P<id>[^-/?#\.]+)'
    _FORMATS = {
        'gif': 250,
        'sd': 480,
        'hd': None,
    }
    _TESTS = [{
        'url': 'https://www.redgifs.com/watch/squeakyhelplesswisent',
        'info_dict': {
            'id': 'squeakyhelplesswisent',
            'ext': 'mp4',
            'title': 'Hotwife Legs Thick',
            'timestamp': 1636287915,
            'upload_date': '20211107',
            'uploader': 'ignored52',
            'duration': 16,
            'view_count': int,
            'like_count': int,
            'categories': list,
            'age_limit': 18,
        }
    }, {
        'url': 'https://thumbs2.redgifs.com/SqueakyHelplessWisent-mobile.mp4#t=0',
        'info_dict': {
            'id': 'squeakyhelplesswisent',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/reddit.py (Python)

Code before:
        # Check if media is hosted on reddit:
        reddit_video = try_get(data, lambda x: x['media']['reddit_video'])
        if reddit_video:
            playlist_urls = [
                try_get(reddit_video, lambda x: unescapeHTML(x[y])) for y in ('dash_url', 'hls_url')
            ]

            dash_playlist_url = playlist_urls[0] or f'https://v.redd.it/{video_id}/DASHPlaylist.mpd'
            hls_playlist_url = playlist_urls[1] or f'https://v.redd.it/{video_id}/HLSPlaylist.m3u8'

            formats = self._extract_m3u8_formats(
                hls_playlist_url, video_id, 'mp4',
                entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
            formats.extend(self._extract_mpd_formats(
                dash_playlist_url, video_id, mpd_id='dash', fatal=False))
            self._sort_formats(formats)

            info.update({
                'formats': formats,
                'duration': int_or_none(reddit_video.get('duration')),
            })

        else:  # Not hosted on reddit, must continue extraction
            info['_type'] = 'url_transparent'

        return info


Review comment (suggestion):
something like this is more readable imo

```suggestion
            return {
                **info,
                'formats': formats,
                'duration': int_or_none(reddit_video.get('duration')),
            })

        return {
            **info,
            '_type': 'url_transparent',
            'url': video_url,
        }
```

Code after:
        reddit_video = traverse_obj(data, (('media', 'secure_media'), 'reddit_video'), get_all=False)
        if reddit_video:
            playlist_urls = [
                try_get(reddit_video, lambda x: unescapeHTML(x[y]))
                for y in ('dash_url', 'hls_url')
            ]

            # Update video_id
            display_id = video_id
            video_id = self._search_regex(
                r'https?://v\.redd\.it/(?P<id>[^/?#&]+)', reddit_video['fallback_url'],
                'video_id', default=display_id)

            dash_playlist_url = playlist_urls[0] or f'https://v.redd.it/{video_id}/DASHPlaylist.mpd'
            hls_playlist_url = playlist_urls[1] or f'https://v.redd.it/{video_id}/HLSPlaylist.m3u8'

            formats = self._extract_m3u8_formats(
                hls_playlist_url, display_id, 'mp4',
                entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
            formats.extend(self._extract_mpd_formats(
                dash_playlist_url, display_id, mpd_id='dash', fatal=False))
            self._sort_formats(formats)

            return {
                **info,
                'id': video_id,
                'display_id': display_id,
                'formats': formats,
                'duration': int_or_none(reddit_video.get('duration')),
            }

        # Not hosted on reddit, must continue extraction
        return {
            **info,
            'display_id': video_id,
            '_type': 'url_transparent',
            'url': video_url,
        }
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/reddit.py (Python)

Code before:
            video_id = self._search_regex(
                r'https?://v\.redd\.it/(?P<id>[^/?#&]+)', reddit_video['fallback_url'],
                'video_id', default=display_id)

            dash_playlist_url = playlist_urls[0] or f'https://v.redd.it/{video_id}/DASHPlaylist.mpd'
            hls_playlist_url = playlist_urls[1] or f'https://v.redd.it/{video_id}/HLSPlaylist.m3u8'

            formats = self._extract_m3u8_formats(
                hls_playlist_url, video_id, 'mp4',
                entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
            formats.extend(self._extract_mpd_formats(
                dash_playlist_url, video_id, mpd_id='dash', fatal=False))
            self._sort_formats(formats)

            return {
                **info,
                'id': video_id,
                'display_id': display_id,
                'formats': formats,
                'duration': int_or_none(reddit_video.get('duration')),
            }

        # Not hosted on reddit, must continue extraction
        return {
            **info,
            'id': video_id,
            '_type': 'url_transparent',
            'url': video_url,
        }


Review comment (suggestion):
```suggestion
            'display_id': video_id,
```
I forgot about this. `url_transparent`/`url` should return `id` only when it's known to be same as the final id. Hence why the original code wasnt returning id

Code after:
            video_id = self._search_regex(
                r'https?://v\.redd\.it/(?P<id>[^/?#&]+)', reddit_video['fallback_url'],
                'video_id', default=display_id)

            dash_playlist_url = playlist_urls[0] or f'https://v.redd.it/{video_id}/DASHPlaylist.mpd'
            hls_playlist_url = playlist_urls[1] or f'https://v.redd.it/{video_id}/HLSPlaylist.m3u8'

            formats = self._extract_m3u8_formats(
                hls_playlist_url, display_id, 'mp4',
                entry_protocol='m3u8_native', m3u8_id='hls', fatal=False)
            formats.extend(self._extract_mpd_formats(
                dash_playlist_url, display_id, mpd_id='dash', fatal=False))
            self._sort_formats(formats)

            return {
                **info,
                'id': video_id,
                'display_id': display_id,
                'formats': formats,
                'duration': int_or_none(reddit_video.get('duration')),
            }

        # Not hosted on reddit, must continue extraction
        return {
            **info,
            'display_id': video_id,
            '_type': 'url_transparent',
            'url': video_url,
        }