Repository: yt-dlp/yt-dlp
File: yt_dlp/extractor/mtv.py (Python)

Code before:
            'id': '4deeb5d8-f272-490c-bde2-ff8d261c6dd1',
            'title': 'Mario - Una Serie Di Maccio Capatonda - Stagione 2',
        },
        'playlist_count': 34,
        'params': {
            'skip_download': True,
        },
    }, {
        # playlist page + redirect
        'url': 'http://www.mtv.it/playlist/sexy-videos/ilctal',
        'info_dict': {
            'id': 'dee8f9ee-756d-493b-bf37-16d1d2783359',
            'title': 'Sexy Videos',
        },
        'playlist_mincount': 145,
        'params': {
            'skip_download': True,
        },
    }]
    _GEO_COUNTRIES = ['IT']
    _FEED_URL = 'http://www.mtv.it/feeds/triforce/manifest/v8'

    def _get_entries(self, title, url):
        while True:
            pg = re.search(r'/(\d+)$', url)
            pg = pg.group(1) if pg else '1'
            entries = self._download_json(url, title, 'page %s' % pg)
            url = try_get(
                entries, lambda x: x['result']['nextPageURL'], compat_str)
            entries = try_get(
                entries, (
                    lambda x: x['result']['data']['items'],
                    lambda x: x['result']['data']['seasons']),
                list)
            for entry in entries or []:
                if entry.get('canonicalURL'):
                    yield self.url_result(entry['canonicalURL'])
            if not url:
                break

    def _real_extract(self, url):
        query = {'url': url}
        info_url = update_url_query(self._FEED_URL, query)
        video_id = self._match_id(url)
        info = self._download_json(info_url, video_id).get('manifest')

        redirect = try_get(
            info, lambda x: x['newLocation']['url'], compat_str)
        if redirect:
            return self.url_result(redirect)


Review comment (suggestion):
1. Is this URL always guaranteed to end with the page number and not have any queries `?something=value` at the end? Otherwise regex needs to account for it
2. It's probably better to use `self._search_regex`

Code after:
            'id': '4deeb5d8-f272-490c-bde2-ff8d261c6dd1',
            'title': 'Mario - Una Serie Di Maccio Capatonda - Stagione 2',
        },
        'playlist_count': 34,
        'params': {
            'skip_download': True,
        },
    }, {
        # playlist page + redirect
        'url': 'http://www.mtv.it/playlist/sexy-videos/ilctal',
        'info_dict': {
            'id': 'dee8f9ee-756d-493b-bf37-16d1d2783359',
            'title': 'Sexy Videos',
        },
        'playlist_mincount': 145,
        'params': {
            'skip_download': True,
        },
    }]
    _GEO_COUNTRIES = ['IT']
    _FEED_URL = 'http://www.mtv.it/feeds/triforce/manifest/v8'

    def _get_entries(self, title, url):
        while True:
            pg = self._search_regex(r'/(\d+)$', url, 'entries', '1')
            entries = self._download_json(url, title, 'page %s' % pg)
            url = try_get(
                entries, lambda x: x['result']['nextPageURL'], compat_str)
            entries = try_get(
                entries, (
                    lambda x: x['result']['data']['items'],
                    lambda x: x['result']['data']['seasons']),
                list)
            for entry in entries or []:
                if entry.get('canonicalURL'):
                    yield self.url_result(entry['canonicalURL'])
            if not url:
                break

    def _real_extract(self, url):
        query = {'url': url}
        info_url = update_url_query(self._FEED_URL, query)
        video_id = self._match_id(url)
        info = self._download_json(info_url, video_id).get('manifest')

        redirect = try_get(
            info, lambda x: x['newLocation']['url'], compat_str)
        if redirect:
            return self.url_result(redirect)

        title = info.get('title')