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

Code before:
            'title': '2024年5月16日（木） 「今日は誰に恋をする？」公演 小栗有以 生誕祭',
            'description': 'md5:2110bdcf947f28bd7d06ec420e51b619',
            'duration': 8559.0,
            'tags': list,
            'thumbnail': 're:^https?://media.livr.jp/vod/img/.*$',
        },
        'skip': 'Premium channel subscribers only',
    }, {
        # Accessible only in the VR SQUARE app
        'url': 'https://livr.jp/contents/P126481458',
        'only_matching': True,
    }]

    def _real_initialize(self):
        VRSQUAREIE._HEADERS = {
            'cookie': try_get(self._get_cookies(self._BASE_URL), lambda x: f'uh={x["uh"].value}') or '',
        }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        status = self._download_json(
            f'{self._BASE_URL}/webApi/contentsStatus/{video_id}',
            video_id, 'Checking contents status', headers=self._HEADERS)
        if isinstance(status, dict):
            self.raise_login_required('Unable to access this video')

        try:
            webApi = self._download_json(
                f'{self._BASE_URL}/webApi/play/url/{video_id}', video_id, headers=self._HEADERS)
        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(webApi, (
                '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 VRSQUAREPlaylistIE(VRSQUAREIE):
    IE_NAME = 'vrsquare:playlist'


Review comment (suggestion):
I was thinking if we could just skip checking the status here and instead throw a more generic error message below. If we want to keep the status check, we should make it non-fatal, and also make the error raising more specific:
```suggestion
        status = self._download_json(
            f'{self._BASE_URL}/webApi/contentsStatus/{video_id}',
            video_id, 'Checking contents status', fatal=False)
        if traverse_obj(status, 'result_code') == '40407':
            self.raise_login_required('Unable to access this video')
```

Code after:
            'duration': 8559.0,
            'tags': list,
            'thumbnail': r're:https?://media\.livr\.jp/vod/img/.+\.jpg',
        },
        'skip': 'Premium channel subscribers only',
    }, {
        # Accessible only in the VR SQUARE app
        'url': 'https://livr.jp/contents/P126481458',
        'only_matching': True,
    }]

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        status = self._download_json(
            f'{self._BASE_URL}/webApi/contentsStatus/{video_id}',
            video_id, 'Checking contents status', fatal=False)
        if traverse_obj(status, 'result_code') == '40407':
            self.raise_login_required('Unable to access this video')

        try:
            web_api = self._download_json(
                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(