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

Code before:
            elif protocol == 'hls':
                formats.extend(self._extract_m3u8_formats(
                    source_url, clip_id, 'mp4', 'm3u8_native',
                    m3u8_id=protocol, fatal=False))
            else:
                formats.append({
                    'url': source_url,
                    'format_id': protocol,
                })
        self._sort_formats(formats)

        return {
            'id': clip_id,
            'title': content.get('title'),
            'duration': float_or_none(content.get('duration')),
            'series': content.get('tvShowTitle'),
            'formats': formats,
        }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        json_data = self._parse_json(self._search_regex(
            r'<script id="state" type="text/plain">(.*)</script>',
            webpage, 'json_data'),
            video_id=video_id)

        video_title = json_data['views']['default']['page']['title']
        contentResource = json_data['views']['default']['page']['contentResource']
        content_id = contentResource[0]['id']
        content_ids = [{'id': id, 'subclip_start': content['start'], 'subclip_end': content['end']} for id, content in enumerate(contentResource)]

        time_of_request = datetime.datetime.now()
        not_before = time_of_request - datetime.timedelta(minutes=5)
        expire = time_of_request + datetime.timedelta(minutes=5)
        payload = {
            'content_ids': {
                content_id: content_ids,
            },
            'secure_delivery': True,
            'iat': int(time_of_request.timestamp()),
            'nbf': int(not_before.timestamp()),
            'exp': int(expire.timestamp()),
        }
        jwt_token = jwt_encode_hs256(payload, self._ENCRYPTION_KEY, headers={'kid': self._ACCESS_ID})
        videos = self._download_json(
            'https://vas-v4.p7s1video.net/4.0/getsources',
            content_id, 'Downloading videos JSON', query={
                'token': jwt_token.decode('utf-8')
            })


Review comment (suggestion):
```suggestion
        json_data = self._parse_json(
            self._search_regex(r'<script id="state" type="text/plain">(.*)</script>', webpage, 'json_data'),
            video_id=video_id)
```

Code after:
            elif protocol == 'hls':
                formats.extend(self._extract_m3u8_formats(
                    source_url, clip_id, 'mp4', 'm3u8_native',
                    m3u8_id=protocol, fatal=False))
            else:
                formats.append({
                    'url': source_url,
                    'format_id': protocol,
                })
        self._sort_formats(formats)

        return {
            'id': clip_id,
            'title': content.get('title'),
            'duration': float_or_none(content.get('duration')),
            'series': content.get('tvShowTitle'),
            'formats': formats,
        }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        webpage = self._download_webpage(url, video_id)
        json_data = self._parse_json(
            self._search_regex(r'<script id="state" type="text/plain">(.*)</script>', webpage, 'json_data'),
            video_id=video_id)

        video_title = json_data['views']['default']['page']['title']
        contentResource = json_data['views']['default']['page']['contentResource']
        content_id = contentResource[0]['id']
        content_ids = [{'id': id, 'subclip_start': content['start'], 'subclip_end': content['end']}
                       for id, content in enumerate(contentResource)]

        time_of_request = datetime.datetime.now()
        not_before = time_of_request - datetime.timedelta(minutes=5)
        expire = time_of_request + datetime.timedelta(minutes=5)
        payload = {
            'content_ids': {
                content_id: content_ids,
            },
            'secure_delivery': True,
            'iat': int(time_of_request.timestamp()),
            'nbf': int(not_before.timestamp()),
            'exp': int(expire.timestamp()),
        }
        jwt_token = jwt_encode_hs256(payload, self._ENCRYPTION_KEY, headers={'kid': self._ACCESS_ID})
        videos = self._download_json(
            'https://vas-v4.p7s1video.net/4.0/getsources',
            content_id, 'Downloading videos JSON', query={
                'token': jwt_token.decode('utf-8')
            })