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

Code before:
                f'{self._BASE_URL}/webApi/play/url/{video_id}', video_id)
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 500:
                raise ExtractorError('VR SQUARE app-only videos are not supported', expected=True)

        return {
            'id': video_id,
            'title': self._html_search_meta(['og:title', 'twitter:title'], webpage),
            'description': self._html_search_meta('description', webpage),
            'formats': self._extract_m3u8_formats(traverse_obj(web_api, (
                'urls', ..., 'url', any)), video_id, 'mp4', fatal=False),
            'thumbnail': self._html_search_meta('og:image', webpage),
            **traverse_obj(webpage, {
                'duration': ({find_element(cls='layout-product-data-time')}, {parse_duration}),
                'tags': ({find_elements(cls='search-tag')}, ..., {clean_html}),
            }),
        }


class VrSquarePlaylistBaseIE(VrSquareIE):
    def _fetch_vids(self, source, keys=()):
        return [self.url_result(
            f'{self._BASE_URL}/contents/{x.removeprefix("/contents/")}', VrSquareIE)
            for x in traverse_obj(source, (
                *keys, {find_elements(cls='video', html=True)},
                ..., {extract_attributes}, 'data-url'))
        ]


class VrSquareChannelIE(VrSquarePlaylistBaseIE):
    IE_NAME = 'vrsquare:channel'

    _VALID_URL = r'https?://livr\.jp/channel/(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://livr.jp/channel/H372648599',
        'info_dict': {
            'id': 'H372648599',
            'title': 'AKB48＋チャンネル',
        },
        'playlist_mincount': 502,
    }]

    def _entries(self, playlist_id):
        for page in itertools.count(1):
            ajax = self._download_json(
                f'{self._BASE_URL}/ajax/channel/{playlist_id}',
                playlist_id, query={'p': page},
            )
            yield from self._fetch_vids(ajax, ('contents_render_list', ...))
            if not ajax['hasNext']:
                break

Review comment (refactor):
```suggestion
                ..., {extract_attributes}, 'data-url', {str}, filter))
```

Code after:
                f'{self._BASE_URL}/webApi/play/url/{video_id}', video_id)
        except ExtractorError as e:
            if isinstance(e.cause, HTTPError) and e.cause.status == 500:
                raise ExtractorError('VR SQUARE app-only videos are not supported', expected=True)
            raise

        return {
            'id': video_id,
            'title': self._html_search_meta(['og:title', 'twitter:title'], webpage),
            'description': self._html_search_meta('description', webpage),
            'formats': self._extract_m3u8_formats(traverse_obj(web_api, (
                'urls', ..., 'url', any)), video_id, 'mp4', fatal=False),
            'thumbnail': self._html_search_meta('og:image', webpage),
            **traverse_obj(webpage, {
                'duration': ({find_element(cls='layout-product-data-time')}, {parse_duration}),
                'tags': ({find_elements(cls='search-tag')}, ..., {clean_html}),
            }),
        }


class VrSquarePlaylistBaseIE(InfoExtractor):
    _BASE_URL = 'https://livr.jp'

    def _fetch_vids(self, source, keys=()):
        for url_path in traverse_obj(source, (
            *keys, {find_elements(cls='video', html=True)}, ...,
            {extract_attributes}, 'data-url', {str}, filter),
        ):
            yield self.url_result(
                f'{self._BASE_URL}/contents/{url_path.removeprefix("/contents/")}', VrSquareIE)

    def _entries(self, path, display_id, query=None):
        for page in itertools.count(1):
            ajax = self._download_json(
                f'{self._BASE_URL}{path}', display_id,
                f'Downloading playlist JSON page {page}',
                query={'p': page, **(query or {})})
            yield from self._fetch_vids(ajax, ('contents_render_list', ...))
            if not traverse_obj(ajax, (('has_next', 'hasNext'), {bool}, any)):
                break


class VrSquareChannelIE(VrSquarePlaylistBaseIE):
    IE_NAME = 'vrsquare:channel'

    _VALID_URL = r'https?://livr\.jp/channel/(?P<id>\w+)'
    _TESTS = [{
        'url': 'https://livr.jp/channel/H372648599',
        'info_dict': {
            'id': 'H372648599',
            'title': 'AKB48＋チャンネル',