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

Code before:
            'id': 'ABD6213',
            'title': 'Cuties',
        },
        'playlist_mincount': 2,
    }, {
        'url': 'https://motherless.com/GVBCF7622',
        'info_dict': {
            'id': 'BCF7622',
            'title': 'Vintage',
        },
        'playlist_count': 0,
    }, {
        'url': 'https://motherless.com/G035DE2F',
        'info_dict': {
            'id': '035DE2F',
            'title': 'General',
        },
        'playlist_mincount': 420,
    }]

    def _correct_path(self, url, item_id):
        return urllib.parse.urljoin(url, f'/GV{item_id}')


class MotherlessUploaderIE(MotherlessPaginatedIE):
    _VALID_URL = r'https?://(?:www\.)?motherless\.com/u/(?P<id>[a-zA-Z0-9_]+)($|\?t=v)'
    _TESTS = [{
        'url': 'https://motherless.com/u/Mrgo4hrs2023',
        'info_dict': {
            'id': 'Mrgo4hrs2023',
            'title': "Mrgo4hrs2023's Uploads - Videos",
        },
        'playlist_mincount': 32,
    }, {
        'url': 'https://motherless.com/u/Happy_couple?t=v',
        'info_dict': {
            'id': 'Happy_couple',
            'title': "Happy_couple's Uploads - Videos",
        },
        'playlist_mincount': 8,
    }]

    def _real_extract(self, url):
        item_id = self._match_id(url)
        real_url = self._correct_path(url, item_id)
        webpage = self._download_webpage(real_url, item_id, 'Downloading page 1')

        def get_page(idx):
            page = idx + 1
            current_page = webpage if not idx else self._download_webpage(
                real_url, item_id, note=f'Downloading page {page}', query={'page': page, 't': 'v'})

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?motherless\.com/u/(?P<id>\w+)/?(?:$|[?#])'
```

Code after:
        'info_dict': {
            'id': 'ABD6213',
            'title': 'Cuties',
        },
        'playlist_mincount': 2,
    }, {
        'url': 'https://motherless.com/GVBCF7622',
        'info_dict': {
            'id': 'BCF7622',
            'title': 'Vintage',
        },
        'playlist_count': 0,
    }, {
        'url': 'https://motherless.com/G035DE2F',
        'info_dict': {
            'id': '035DE2F',
            'title': 'General',
        },
        'playlist_mincount': 420,
    }]

    def _correct_path(self, url, item_id):
        return urllib.parse.urljoin(url, f'/GV{item_id}')


class MotherlessUploaderIE(MotherlessPaginatedIE):
    _VALID_URL = r'https?://(?:www\.)?motherless\.com/u/(?P<id>\w+)/?(?:$|[?#])'
    _TESTS = [{
        'url': 'https://motherless.com/u/Mrgo4hrs2023',
        'info_dict': {
            'id': 'Mrgo4hrs2023',
            'title': "Mrgo4hrs2023's Uploads - Videos",
        },
        'playlist_mincount': 32,
    }, {
        'url': 'https://motherless.com/u/Happy_couple?t=v',
        'info_dict': {
            'id': 'Happy_couple',
            'title': "Happy_couple's Uploads - Videos",
        },
        'playlist_mincount': 8,
    }]

    _EXTRA_QUERY = {'t': 'v'}

    def _correct_path(self, url, item_id):
        return urllib.parse.urljoin(url, f'/u/{item_id}?t=v')
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/ilpost.py (Python)

Code before:
import functools

from .common import InfoExtractor
from ..utils import ExtractorError, float_or_none, int_or_none, url_or_none, urlencode_postdata
from ..utils.traversal import traverse_obj


class IlPostExtractorIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?ilpost\.it/episodes/(?P<id>[^/?]+).*'
    _TESTS = [{
        'url': 'https://www.ilpost.it/episodes/1-avis-akvasas-ka/',
        'md5': '43649f002d85e1c2f319bb478d479c40',
        'info_dict': {
            'id': '2972047',
            'ext': 'mp3',
            'display_id': '1-avis-akvasas-ka',
            'title': '1. Avis akvasas ka',
            'url': 'https://www.ilpost.it/wp-content/uploads/2023/12/28/1703781217-l-invasione-pt1-v6.mp3',
            'timestamp': 1703835014,
            'upload_date': '20231229',
            'duration': 2495.0,
            'availability': 'public',
            'series_id': '235598',
            'description': '',
        }
    }]

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

Review comment (refactor):
```suggestion
import functools

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    float_or_none,
    int_or_none,
    url_or_none,
    urlencode_postdata,
)
from ..utils.traversal import traverse_obj
```

Code after:
import functools

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    float_or_none,
    int_or_none,
    url_or_none,
    urlencode_postdata,
)
from ..utils.traversal import traverse_obj


class IlPostIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?ilpost\.it/episodes/(?P<id>[^/?#]+)'
    _TESTS = [{
        'url': 'https://www.ilpost.it/episodes/1-avis-akvasas-ka/',
        'md5': '43649f002d85e1c2f319bb478d479c40',
        'info_dict': {
            'id': '2972047',
            'ext': 'mp3',
            'display_id': '1-avis-akvasas-ka',
            'title': '1. Avis akvasas ka',
            'url': 'https://www.ilpost.it/wp-content/uploads/2023/12/28/1703781217-l-invasione-pt1-v6.mp3',
            'timestamp': 1703835014,
            'upload_date': '20231229',
            'duration': 2495.0,
            'availability': 'public',
            'series_id': '235598',
            'description': '',
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/ilpost.py (Python)

Code before:
import functools

from .common import InfoExtractor
from ..utils import ExtractorError, float_or_none, int_or_none, url_or_none, urlencode_postdata
from ..utils.traversal import traverse_obj


class IlPostExtractorIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?ilpost\.it/episodes/(?P<id>[^/?]+).*'
    _TESTS = [{
        'url': 'https://www.ilpost.it/episodes/1-avis-akvasas-ka/',
        'md5': '43649f002d85e1c2f319bb478d479c40',
        'info_dict': {
            'id': '2972047',
            'ext': 'mp3',
            'display_id': '1-avis-akvasas-ka',
            'title': '1. Avis akvasas ka',
            'url': 'https://www.ilpost.it/wp-content/uploads/2023/12/28/1703781217-l-invasione-pt1-v6.mp3',
            'timestamp': 1703835014,
            'upload_date': '20231229',
            'duration': 2495.0,
            'availability': 'public',
            'series_id': '235598',
            'description': '',
        }
    }]

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

        endpoint_metadata = self._search_json(
            r'var\s+ilpostpodcast\s*=', webpage, 'metadata', podcast_display_id)
        episode_id = endpoint_metadata['post_id']

Review comment (suggestion):
```suggestion
    _VALID_URL = r'https?://(?:www\.)?ilpost\.it/episodes/(?P<id>[^/?#]+)'
```

Code after:
import functools

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    float_or_none,
    int_or_none,
    url_or_none,
    urlencode_postdata,
)
from ..utils.traversal import traverse_obj


class IlPostIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?ilpost\.it/episodes/(?P<id>[^/?#]+)'
    _TESTS = [{
        'url': 'https://www.ilpost.it/episodes/1-avis-akvasas-ka/',
        'md5': '43649f002d85e1c2f319bb478d479c40',
        'info_dict': {
            'id': '2972047',
            'ext': 'mp3',
            'display_id': '1-avis-akvasas-ka',
            'title': '1. Avis akvasas ka',
            'url': 'https://www.ilpost.it/wp-content/uploads/2023/12/28/1703781217-l-invasione-pt1-v6.mp3',
            'timestamp': 1703835014,
            'upload_date': '20231229',
            'duration': 2495.0,
            'availability': 'public',
            'series_id': '235598',
            'description': '',
        }
    }]

    def _real_extract(self, url):
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/_extractors.py (Python)

Code before:
from .huya import HuyaLiveIE
from .huffpost import HuffPostIE
from .hungama import (
    HungamaIE,
    HungamaSongIE,
    HungamaAlbumPlaylistIE,
)
from .hypem import HypemIE
from .hypergryph import MonsterSirenHypergryphMusicIE
from .hytale import HytaleIE
from .icareus import IcareusIE
from .ichinanalive import (
    IchinanaLiveIE,
    IchinanaLiveClipIE,
)
from .idolplus import IdolPlusIE
from .ign import (
    IGNIE,
    IGNVideoIE,
    IGNArticleIE,
)
from .iheart import (
    IHeartRadioIE,
    IHeartRadioPodcastIE,
)
from .ilpost import IlPostExtractorIE
from .iltalehti import IltalehtiIE
from .imdb import (
    ImdbIE,
    ImdbListIE
)
from .imgur import (
    ImgurIE,
    ImgurAlbumIE,
    ImgurGalleryIE,
)
from .ina import InaIE
from .inc import IncIE
from .indavideo import IndavideoEmbedIE
from .infoq import InfoQIE
from .instagram import (
    InstagramIE,
    InstagramIOSIE,
    InstagramUserIE,
    InstagramTagIE,
    InstagramStoryIE,
)
from .internazionale import InternazionaleIE
from .internetvideoarchive import InternetVideoArchiveIE
from .iprima import (
    IPrimaIE,

Review comment (refactor):
`Extractor` is redundant
```suggestion
from .ilpost import IlPostIE
```

Code after:
from .huya import HuyaLiveIE
from .huffpost import HuffPostIE
from .hungama import (
    HungamaIE,
    HungamaSongIE,
    HungamaAlbumPlaylistIE,
)
from .hypem import HypemIE
from .hypergryph import MonsterSirenHypergryphMusicIE
from .hytale import HytaleIE
from .icareus import IcareusIE
from .ichinanalive import (
    IchinanaLiveIE,
    IchinanaLiveClipIE,
)
from .idolplus import IdolPlusIE
from .ign import (
    IGNIE,
    IGNVideoIE,
    IGNArticleIE,
)
from .iheart import (
    IHeartRadioIE,
    IHeartRadioPodcastIE,
)
from .ilpost import IlPostIE
from .iltalehti import IltalehtiIE
from .imdb import (
    ImdbIE,
    ImdbListIE
)
from .imgur import (
    ImgurIE,
    ImgurAlbumIE,
    ImgurGalleryIE,
)
from .ina import InaIE
from .inc import IncIE
from .indavideo import IndavideoEmbedIE
from .infoq import InfoQIE
from .instagram import (
    InstagramIE,
    InstagramIOSIE,
    InstagramUserIE,
    InstagramTagIE,
    InstagramStoryIE,
)
from .internazionale import InternazionaleIE
from .internetvideoarchive import InternetVideoArchiveIE
from .iprima import (
    IPrimaIE,
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/ilpost.py (Python)

Code before:
import functools

from .common import InfoExtractor
from ..utils import ExtractorError, float_or_none, int_or_none, url_or_none, urlencode_postdata
from ..utils.traversal import traverse_obj


class IlPostExtractorIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?ilpost\.it/episodes/(?P<id>[^/?]+).*'
    _TESTS = [{
        'url': 'https://www.ilpost.it/episodes/1-avis-akvasas-ka/',
        'md5': '43649f002d85e1c2f319bb478d479c40',
        'info_dict': {
            'id': '2972047',
            'ext': 'mp3',
            'display_id': '1-avis-akvasas-ka',
            'title': '1. Avis akvasas ka',
            'url': 'https://www.ilpost.it/wp-content/uploads/2023/12/28/1703781217-l-invasione-pt1-v6.mp3',
            'timestamp': 1703835014,
            'upload_date': '20231229',
            'duration': 2495.0,
            'availability': 'public',
            'series_id': '235598',
            'description': '',
        }
    }]

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

        endpoint_metadata = self._search_json(
            r'var\s+ilpostpodcast\s*=', webpage, 'metadata', podcast_display_id)

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

Code after:
import functools

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    float_or_none,
    int_or_none,
    url_or_none,
    urlencode_postdata,
)
from ..utils.traversal import traverse_obj


class IlPostIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?ilpost\.it/episodes/(?P<id>[^/?#]+)'
    _TESTS = [{
        'url': 'https://www.ilpost.it/episodes/1-avis-akvasas-ka/',
        'md5': '43649f002d85e1c2f319bb478d479c40',
        'info_dict': {
            'id': '2972047',
            'ext': 'mp3',
            'display_id': '1-avis-akvasas-ka',
            'title': '1. Avis akvasas ka',
            'url': 'https://www.ilpost.it/wp-content/uploads/2023/12/28/1703781217-l-invasione-pt1-v6.mp3',
            'timestamp': 1703835014,
            'upload_date': '20231229',
            'duration': 2495.0,
            'availability': 'public',
            'series_id': '235598',
            'description': '',
        }
    }]
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/eporner.py (Python)

Code before:
import re
from .common import InfoExtractor
from ..utils import (
    encode_base_n,
    ExtractorError,
    int_or_none,
    merge_dicts,
    parse_duration,
    str_to_int,
    url_or_none,
    get_elements_by_class,
    join_nonempty
)


class EpornerIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?eporner\.com/(?:(?:hd-porn|embed)/|video-)(?P<id>\w+)(?:/(?P<display_id>[\w-]+))?'
    _TESTS = [{
        'url': 'http://www.eporner.com/hd-porn/95008/Infamous-Tiffany-Teen-Strip-Tease-Video/',
        'md5': '39d486f046212d8e1b911c52ab4691f8',
        'info_dict': {
            'id': 'qlDUmNsj6VS',
            'display_id': 'Infamous-Tiffany-Teen-Strip-Tease-Video',
            'ext': 'mp4',
            'title': 'Infamous Tiffany Teen Strip Tease Video',
            'description': 'md5:764f39abf932daafa37485eb46efa152',
            'timestamp': 1232520922,

Review comment (refactor):
won't be needing it if my other suggestion is applied
```suggestion
from .common import InfoExtractor
```

Code after:
from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    encode_base_n,
    get_elements_by_class,
    int_or_none,
    join_nonempty,
    merge_dicts,
    parse_duration,
    str_to_int,
    url_or_none,
)


class EpornerIE(InfoExtractor):
    _VALID_URL = r'https?://(?:www\.)?eporner\.com/(?:(?:hd-porn|embed)/|video-)(?P<id>\w+)(?:/(?P<display_id>[\w-]+))?'
    _TESTS = [{
        'url': 'http://www.eporner.com/hd-porn/95008/Infamous-Tiffany-Teen-Strip-Tease-Video/',
        'md5': '39d486f046212d8e1b911c52ab4691f8',
        'info_dict': {
            'id': 'qlDUmNsj6VS',
            'display_id': 'Infamous-Tiffany-Teen-Strip-Tease-Video',
            'ext': 'mp4',
            'title': 'Infamous Tiffany Teen Strip Tease Video',
            'description': 'md5:764f39abf932daafa37485eb46efa152',
            'timestamp': 1232520922,
            'upload_date': '20090121',
Repository: yt-dlp/yt-dlp
File: test/test_networking.py (Python)

Code before:

        def mock_read(*args, **kwargs):
            raise raised()
        monkeypatch.setattr(res.fp, 'read', mock_read)

        with pytest.raises(expected, match=match) as exc_info:
            res.read()

        assert exc_info.type is expected

    def test_close(self, handler, monkeypatch):
        rh = handler()
        session = rh._get_instance(cookiejar=rh.cookiejar)
        called = False
        original_close = session.close

        def mock_close(*args, **kwargs):
            nonlocal called
            called = True
            return original_close(*args, **kwargs)

        monkeypatch.setattr(session, 'close', mock_close)

        rh.close()

        assert called


def run_validation(handler, error, req, **handler_kwargs):
    with handler(**handler_kwargs) as rh:
        if error:
            with pytest.raises(error):
                rh.validate(req)
        else:
            rh.validate(req)


class TestRequestHandlerValidation:

    class ValidationRH(RequestHandler):
        def _send(self, request):
            raise RequestError('test')

    class NoCheckRH(ValidationRH):
        _SUPPORTED_FEATURES = None
        _SUPPORTED_PROXY_SCHEMES = None
        _SUPPORTED_URL_SCHEMES = None

        def _check_extensions(self, extensions):
            extensions.clear()


Review comment (suggestion):
formatting between this and the other one is inconsistent, but i would prefer
```suggestion
        monkeypatch.setattr(session, 'close', mock_close)
        rh.close()
        assert called
```

Code after:

        def mock_read(*args, **kwargs):
            raise raised()
        monkeypatch.setattr(res.fp, 'read', mock_read)

        with pytest.raises(expected, match=match) as exc_info:
            res.read()

        assert exc_info.type is expected

    def test_close(self, handler, monkeypatch):
        rh = handler()
        session = rh._get_instance(cookiejar=rh.cookiejar)
        called = False
        original_close = session.close

        def mock_close(*args, **kwargs):
            nonlocal called
            called = True
            return original_close(*args, **kwargs)

        monkeypatch.setattr(session, 'close', mock_close)
        rh.close()
        assert called


def run_validation(handler, error, req, **handler_kwargs):
    with handler(**handler_kwargs) as rh:
        if error:
            with pytest.raises(error):
                rh.validate(req)
        else:
            rh.validate(req)


class TestRequestHandlerValidation:

    class ValidationRH(RequestHandler):
        def _send(self, request):
            raise RequestError('test')

    class NoCheckRH(ValidationRH):
        _SUPPORTED_FEATURES = None
        _SUPPORTED_PROXY_SCHEMES = None
        _SUPPORTED_URL_SCHEMES = None

        def _check_extensions(self, extensions):
            extensions.clear()

    class HTTPSupportedRH(ValidationRH):
        _SUPPORTED_URL_SCHEMES = ('http',)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/newgrounds.py (Python)

Code before:
        'url': 'https://burn7.newgrounds.com/movies',
        'info_dict': {
            'id': 'burn7',
        },
        'playlist_mincount': 2,
    }, {
        'url': 'https://brian-beaton.newgrounds.com/movies',
        'info_dict': {
            'id': 'brian-beaton',
        },
        'playlist_mincount': 10,
    }]
    _PAGE_SIZE = 30

    def _fetch_page(self, channel_id, url, page):
        page += 1
        posts_info = self._download_json(
            f'{url}?page={page}', channel_id,
            note=f'Downloading page {page}', headers={
                'Accept': 'application/json, text/javascript, */*; q = 0.01',
                'X-Requested-With': 'XMLHttpRequest',
            })
        items = posts_info.get('items', [])
        for year in items:
            posts = items.get(str(year))
            for post in posts:
                path, media_id = self._search_regex(
                    r'<a[^>]+\bhref=["\'][^"\']+((?:portal/view|audio/listen)/(\d+))[^>]+>',
                    post, 'url', group=(1, 2))
                yield self.url_result(f'https://www.newgrounds.com/{path}', NewgroundsIE.ie_key(), media_id)

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

        entries = OnDemandPagedList(functools.partial(
            self._fetch_page, channel_id, url), self._PAGE_SIZE)

        return self.playlist_result(entries, channel_id)


Review comment (suggestion):
could we do this?
```suggestion
        for post in traverse_obj(posts_info, ('items', ..., ..., {str})):
```

Code after:
    }, {
        'url': 'https://burn7.newgrounds.com/movies',
        'info_dict': {
            'id': 'burn7',
        },
        'playlist_mincount': 2,
    }, {
        'url': 'https://brian-beaton.newgrounds.com/movies',
        'info_dict': {
            'id': 'brian-beaton',
        },
        'playlist_mincount': 10,
    }]
    _PAGE_SIZE = 30

    def _fetch_page(self, channel_id, url, page):
        page += 1
        posts_info = self._download_json(
            f'{url}?page={page}', channel_id,
            note=f'Downloading page {page}', headers={
                'Accept': 'application/json, text/javascript, */*; q = 0.01',
                'X-Requested-With': 'XMLHttpRequest',
            })
        for post in traverse_obj(posts_info, ('items', ..., ..., {str})):
            path, media_id = self._search_regex(
                r'<a[^>]+\bhref=["\'][^"\']+((?:portal/view|audio/listen)/(\d+))[^>]+>',
                post, 'url', group=(1, 2))
            yield self.url_result(f'https://www.newgrounds.com/{path}', NewgroundsIE.ie_key(), media_id)

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

        entries = OnDemandPagedList(functools.partial(
            self._fetch_page, channel_id, url), self._PAGE_SIZE)

        return self.playlist_result(entries, channel_id)
Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/linkedin.py (Python)

Code before:
from itertools import zip_longest
import re

from .common import InfoExtractor
from ..utils import (
    extract_attributes,
    ExtractorError,
    float_or_none,
    int_or_none,
    srt_subtitles_timecode,
    mimetype2ext,
    traverse_obj,
    try_get,
    url_or_none,
    urlencode_postdata,
    urljoin,
)


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

    def _perform_login(self, username, password):
        if self._logged_in:
            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'))

Review comment (refactor):
this is not your doing, but while we're touching the imports let's fix it
```suggestion
    ExtractorError,
    extract_attributes,
```

Code after:
from itertools import zip_longest
import re

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    extract_attributes,
    float_or_none,
    int_or_none,
    srt_subtitles_timecode,
    mimetype2ext,
    traverse_obj,
    try_get,
    url_or_none,
    urlencode_postdata,
    urljoin,
)


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

    def _perform_login(self, username, password):
        if self._logged_in:
            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'))