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

Code before:
    UserNotLive,
    traverse_obj,
    try_call,
    unified_timestamp,
)


class EplusIbIE(InfoExtractor):
    IE_NAME = 'eplus:inbound'
    IE_DESC = 'e+ (イープラス) overseas'
    _VALID_URL = r'https?://live\.eplus\.jp/ex/player\?ib=(?P<id>([A-Za-z\d]|%2B|%2F){86}(%3D){2})'
    _TESTS = [{
        # simple fake url
        'url': 'https://live.eplus.jp/ex/player?ib=00000000000000000000000000000000000000000000000000000000000000000000000000000000000000%3D%3D',
        'only_matching': True,
    }, {
        # complex fake url
        'url': 'https://live.eplus.jp/ex/player?ib=YA4Z%2Fz2rpI5cDl3V%2Bx9PI%2FXTGOX0j8IBzPthgx7%2BieWeff6iLcdsdsds1926zosZU9AbB3gdL3wG%2BNa1afQdIf%3D%3D',
        'only_matching': True,
    }]

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

        data_json = self._search_json(r'<script>\s*var app = ', webpage, 'data_json', video_id)

        delivery_status = traverse_obj(data_json, 'delivery_status')
        archive_mode = traverse_obj(data_json, 'archive_mode')

        self.write_debug(f'delivery_status = {delivery_status}, archive_mode = {archive_mode}')

        if delivery_status == 'PREPARING':
            raise UserNotLive('This event has not started yet')
        elif delivery_status == 'STARTED':
            # FIXME: HTTP request headers need to be updated to continue download
            self.report_warning(
                'Due to technical limitations, the download will be interrupted after one hour')
            live_status = 'is_live'
        elif delivery_status == 'STOPPED':
            if archive_mode == 'ON':
                raise UserNotLive(
                    'This event has ended, but the archive has not been generated yet')
            raise ExtractorError(
                'This event has ended and there is no archive for this event', expected=True)
        elif delivery_status == 'WAIT_CONFIRM_ARCHIVED':
            raise UserNotLive(
                'This event has ended, and the archive will be available shortly')
        elif delivery_status == 'CONFIRMED_ARCHIVE':
            # FIXME: HTTP request headers need to be updated to continue download
            self.report_warning(

Review comment (suggestion):
```suggestion
        data_json = self._search_json(r'<script>\s*var app\s*=', webpage, 'data json', video_id)
```

Code after:
    try_call,
    unified_timestamp,
)


class EplusIbIE(InfoExtractor):
    IE_NAME = 'eplus:inbound'
    IE_DESC = 'e+ (イープラス) overseas'
    _VALID_URL = r'https?://live\.eplus\.jp/ex/player\?ib=(?P<id>(?:\w|%2B|%2F){86}%3D%3D)'
    _TESTS = [{
        'url': 'https://live.eplus.jp/ex/player?ib=YEFxb3Vyc2Dombnjg7blkrLlrablnJLjgrnjgq%2Fjg7zjg6vjgqLjgqTjg4njg6vlkIzlpb3kvJpgTGllbGxhIQ%3D%3D',
        'info_dict': {
            'id': '354502-0001-002',
            'title': 'LoveLive!Series Presents COUNTDOWN LoveLive! 2021→2022～LIVE with a smile!～【Streaming+(配信)】',
            'live_status': 'was_live',
            'release_date': '20211231',
            'release_timestamp': 1640952000,
            'description': str,
        },
        'params': {
            'skip_download': True,
            'ignore_no_formats_error': True,
        },
        'expected_warnings': [
            'Could not find the playlist URL. This event may not be accessible',
            'No video formats found!',
            'Requested format is not available',
        ],
    }]

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

        data_json = self._search_json(r'<script>\s*var app\s*=', webpage, 'data json', video_id)

        delivery_status = data_json.get('delivery_status')
        archive_mode = data_json.get('archive_mode')
        release_timestamp = try_call(lambda: unified_timestamp(data_json['event_datetime']) - 32400)
        release_timestamp_str = data_json.get('event_datetime_text')  # JST

        self.write_debug(f'delivery_status = {delivery_status}, archive_mode = {archive_mode}')

        if delivery_status == 'PREPARING':
            live_status = 'is_upcoming'
        elif delivery_status == 'STARTED':
            live_status = 'is_live'
        elif delivery_status == 'STOPPED':
            if archive_mode != 'ON':
                raise ExtractorError(
                    'This event has ended and there is no archive for this event', expected=True)