]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/lrt.py
[extractor/iq] Increase phantomjs timeout
[yt-dlp.git] / yt_dlp / extractor / lrt.py
1 from .common import InfoExtractor
2 from ..utils import (
3 clean_html,
4 merge_dicts,
5 traverse_obj,
6 url_or_none,
7 )
8
9
10 class LRTBaseIE(InfoExtractor):
11 def _extract_js_var(self, webpage, var_name, default=None):
12 return self._search_regex(
13 fr'{var_name}\s*=\s*(["\'])((?:(?!\1).)+)\1',
14 webpage, var_name.replace('_', ' '), default, group=2)
15
16
17 class LRTStreamIE(LRTBaseIE):
18 _VALID_URL = r'https?://(?:www\.)?lrt\.lt/mediateka/tiesiogiai/(?P<id>[\w-]+)'
19 _TESTS = [{
20 'url': 'https://www.lrt.lt/mediateka/tiesiogiai/lrt-opus',
21 'info_dict': {
22 'id': 'lrt-opus',
23 'live_status': 'is_live',
24 'title': 're:^LRT Opus.+$',
25 'ext': 'mp4'
26 }
27 }]
28
29 def _real_extract(self, url):
30 video_id = self._match_id(url)
31 webpage = self._download_webpage(url, video_id)
32 streams_data = self._download_json(self._extract_js_var(webpage, 'tokenURL'), video_id)
33
34 formats, subtitles = [], {}
35 for stream_url in traverse_obj(streams_data, (
36 'response', 'data', lambda k, _: k.startswith('content')), expected_type=url_or_none):
37 fmts, subs = self._extract_m3u8_formats_and_subtitles(stream_url, video_id, 'mp4', m3u8_id='hls', live=True)
38 formats.extend(fmts)
39 subtitles = self._merge_subtitles(subtitles, subs)
40 self._sort_formats(formats)
41
42 stream_title = self._extract_js_var(webpage, 'video_title', 'LRT')
43 return {
44 'id': video_id,
45 'formats': formats,
46 'subtitles': subtitles,
47 'is_live': True,
48 'title': f'{self._og_search_title(webpage)} - {stream_title}'
49 }
50
51
52 class LRTVODIE(LRTBaseIE):
53 _VALID_URL = r'https?://(?:www\.)?lrt\.lt(?P<path>/mediateka/irasas/(?P<id>[0-9]+))'
54 _TESTS = [{
55 # m3u8 download
56 'url': 'https://www.lrt.lt/mediateka/irasas/2000127261/greita-ir-gardu-sicilijos-ikvepta-klasikiniu-makaronu-su-baklazanais-vakariene',
57 'info_dict': {
58 'id': '2000127261',
59 'ext': 'mp4',
60 'title': 'Greita ir gardu: Sicilijos įkvėpta klasikinių makaronų su baklažanais vakarienė',
61 'description': 'md5:ad7d985f51b0dc1489ba2d76d7ed47fa',
62 'duration': 3035,
63 'timestamp': 1604079000,
64 'upload_date': '20201030',
65 'tags': ['LRT TELEVIZIJA', 'Beatos virtuvė', 'Beata Nicholson', 'Makaronai', 'Baklažanai', 'Vakarienė', 'Receptas'],
66 'thumbnail': 'https://www.lrt.lt/img/2020/10/30/764041-126478-1287x836.jpg'
67 },
68 }, {
69 # direct mp3 download
70 'url': 'http://www.lrt.lt/mediateka/irasas/1013074524/',
71 'md5': '389da8ca3cad0f51d12bed0c844f6a0a',
72 'info_dict': {
73 'id': '1013074524',
74 'ext': 'mp3',
75 'title': 'Kita tema 2016-09-05 15:05',
76 'description': 'md5:1b295a8fc7219ed0d543fc228c931fb5',
77 'duration': 3008,
78 'view_count': int,
79 'like_count': int,
80 },
81 }]
82
83 def _real_extract(self, url):
84 path, video_id = self._match_valid_url(url).groups()
85 webpage = self._download_webpage(url, video_id)
86
87 media_url = self._extract_js_var(webpage, 'main_url', path)
88 media = self._download_json(self._extract_js_var(
89 webpage, 'media_info_url',
90 'https://www.lrt.lt/servisai/stream_url/vod/media_info/'),
91 video_id, query={'url': media_url})
92 jw_data = self._parse_jwplayer_data(
93 media['playlist_item'], video_id, base_url=url)
94
95 json_ld_data = self._search_json_ld(webpage, video_id)
96
97 tags = []
98 for tag in (media.get('tags') or []):
99 tag_name = tag.get('name')
100 if not tag_name:
101 continue
102 tags.append(tag_name)
103
104 clean_info = {
105 'description': clean_html(media.get('content')),
106 'tags': tags,
107 }
108
109 return merge_dicts(clean_info, jw_data, json_ld_data)