[cleanup] Make more playlist entries lazy (#11763)
[yt-dlp.git] / yt_dlp / extractor / novaplay.py
blob77d7ce18609ed529cadfe00c89b646e8d98fd987
1 from .common import InfoExtractor
2 from ..utils import int_or_none, parse_duration, parse_iso8601
5 class NovaPlayIE(InfoExtractor):
6 _VALID_URL = r'https?://play\.nova\.bg/video/[^?#]+/(?P<id>\d+)'
7 _TESTS = [
9 'url': 'https://play.nova.bg/video/ochakvaite/season-0/ochakvaite-2022-07-22-sybudi-se-sat/606627',
10 'md5': 'd79dff2d09d196c595a7290f48e33399',
11 'info_dict': {
12 'id': '606627',
13 'ext': 'mp4',
14 'title': 'Събуди се - събота по NOVA (23.07.2022)',
15 'alt_title': 'ochakvaite/season-0/ochakvaite-2022-07-22-sybudi-se-sat',
16 'duration': 29.0,
17 'timestamp': 1658491547,
18 'upload_date': '20220722',
19 'thumbnail': 'https://nbg-img.fite.tv/img/606627_460x260.jpg',
20 'description': '29 сек',
24 'url': 'https://play.nova.bg/video/ochakvaite/season-0/ochakvaite-2022-07-22-cherry-tazi/606609',
25 'md5': 'f3e973e2ed1a5b9b3f498b1ab82d01b3',
26 'info_dict': {
27 'id': '606609',
28 'ext': 'mp4',
29 'title': 'Черешката на тортата - тази вечер по NOVA (22.07.2022)',
30 'alt_title': 'ochakvaite/season-0/ochakvaite-2022-07-22-cherry-tazi',
31 'duration': 29.0,
32 'timestamp': 1658476303,
33 'upload_date': '20220722',
34 'thumbnail': 'https://nbg-img.fite.tv/img/606609_460x260.jpg',
35 'description': '29 сек',
40 _access_token = None
42 def _real_extract(self, url):
43 video_id = self._match_id(url)
44 webpage = self._download_webpage(url, video_id)
45 self._access_token = self._access_token or self._download_json(
46 'https://play.nova.bg/api/client', None, note='Fetching access token')['accessToken']
47 video_props = self._search_nextjs_data(webpage, video_id)['props']['pageProps']['video']
48 m3u8_url = self._download_json(
49 f'https://nbg-api.fite.tv/api/v2/videos/{video_id}/streams',
50 video_id, headers={
51 'x-flipps-user-agent': 'Flipps/75/9.7',
52 'x-flipps-version': '2022-05-17',
53 'Authorization': f'Bearer {self._access_token}',
54 })[0]['links']['play']['href']
55 formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', m3u8_id='hls')
57 return {
58 'id': video_id,
59 'title': video_props['title'],
60 'alt_title': video_props.get('slug'),
61 'thumbnail': self._og_search_thumbnail(webpage),
62 'description': self._og_search_description(webpage),
63 'formats': formats,
64 'duration': parse_duration(video_props['duration']),
65 'timestamp': parse_iso8601(video_props['published_at']),
66 'view_count': int_or_none(video_props['view_count']),