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

Code before:
        'url': 'https://tarangplus.in/tarang-serials/bada-bohu/episodes',
        'info_dict': {
            'id': 'bada-bohu',
            'title': 'Bada Bohu',
        },
        'playlist_mincount': 236,
    }, {
        'url': 'https://tarangplus.in/shows/dr-nonsense/episodes',
        'info_dict': {
            'id': 'dr-nonsense',
            'title': 'Dr. Nonsense',
        },
        'playlist_mincount': 15,
    }]
    _PAGE_SIZE = 20

    def _entries(self, playlist_url, playlist_id, page):
        data = self._download_json(playlist_url, f'{playlist_id}-{page + 1}',
                                   'Downloading JSON', 'Unable to download JSON', query={'page_no': page})
        for item in data['items']:
            url = urljoin(self._BASE_URL, item.split('$')[3])
            yield self.url_result(url, TarangPlusVideoIE)

    def _real_extract(self, url):
        display_id = self._match_id(url)
        webpage = self._download_webpage('/'.join(url.split('/')[:-1]), display_id)
        title = self._hidden_inputs(webpage).get('title')
        return self.playlist_result(
            OnDemandPagedList(functools.partial(self._entries, url, display_id), self._PAGE_SIZE),
            display_id, title)


class TarangPlusSecondaryPlaylistIE(TarangPlusBaseIE):
    IE_NAME = 'tarangplus:secondaryplaylist'
    _VALID_URL = r'https?://(?:www\.)?tarangplus\.in/(?P<id>[^#?/]+)/all$'
    _TESTS = [{
        'url': 'https://tarangplus.in/chhota-jaga/all',
        'info_dict': {
            'id': 'chhota-jaga',
            'title': 'Chhota Jaga',
        },
        'playlist_mincount': 34,
    }, {
        'url': 'https://tarangplus.in/kids-yali-show/all',
        'info_dict': {
            'id': 'kids-yali-show',
            'title': 'Yali',
        },
        'playlist_mincount': 10,
    }, {
        'url': 'https://tarangplus.in/trailer/all',

Review comment (suggestion):
Let's reconstruct the URL using matches instead of doing the string manipulation
```suggestion
        url_type, display_id = self._match_valid_url(url).group('type', 'id')
        series_url = f'{self._BASE_URL}/{url_type}/{display_id}'
        webpage = self._download_webpage('series_url, display_id)
```

Code after:
            }),
            'formats': self._extract_m3u8_formats(m3u8_url, display_id),
        }


class TarangPlusEpisodesIE(TarangPlusBaseIE):
    IE_NAME = 'tarangplus:episodes'
    _VALID_URL = r'https?://(?:www\.)?tarangplus\.in/(?P<type>[^#?/]+)/(?P<id>[^#?/]+)/episodes/?(?:$|[?#])'
    _TESTS = [{
        'url': 'https://tarangplus.in/tarangaplus-originals/balijatra/episodes',
        'info_dict': {
            'id': 'balijatra',
            'title': 'Balijatra',
        },
        'playlist_mincount': 7,
    }, {
        'url': 'https://tarangplus.in/tarang-serials/bada-bohu/episodes',
        'info_dict': {
            'id': 'bada-bohu',
            'title': 'Bada Bohu',
        },
        'playlist_mincount': 236,
    }, {
        'url': 'https://tarangplus.in/shows/dr-nonsense/episodes',
        'info_dict': {
            'id': 'dr-nonsense',
            'title': 'Dr. Nonsense',
        },
        'playlist_mincount': 15,
    }]
    _PAGE_SIZE = 20

    def _entries(self, playlist_url, playlist_id, page):
        data = self._download_json(
            playlist_url, playlist_id, f'Downloading playlist JSON page {page + 1}',
            query={'page_no': page})
        for item in traverse_obj(data, ('items', ..., {str})):
            yield self.url_result(
                urljoin(self._BASE_URL, item.split('$')[3]), TarangPlusVideoIE)

    def _real_extract(self, url):
        url_type, display_id = self._match_valid_url(url).group('type', 'id')
        series_url = f'{self._BASE_URL}/{url_type}/{display_id}'
        webpage = self._download_webpage(series_url, display_id)

        entries = OnDemandPagedList(
            functools.partial(self._entries, f'{series_url}/episodes', display_id),
            self._PAGE_SIZE)
        return self.playlist_result(
            entries, display_id, self._hidden_inputs(webpage).get('title'))