]>
Commit | Line | Data |
---|---|---|
4dc19c09 NJ |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
2512b174 | 4 | |
4dc19c09 NJ |
5 | from .common import InfoExtractor |
6 | from ..utils import ( | |
8bdd16b4 | 7 | clean_html, |
8 | merge_dicts, | |
4dc19c09 NJ |
9 | ) |
10 | ||
11 | ||
12 | class LRTIE(InfoExtractor): | |
13 | IE_NAME = 'lrt.lt' | |
8bdd16b4 | 14 | _VALID_URL = r'https?://(?:www\.)?lrt\.lt(?P<path>/mediateka/irasas/(?P<id>[0-9]+))' |
2512b174 S |
15 | _TESTS = [{ |
16 | # m3u8 download | |
8bdd16b4 | 17 | 'url': 'https://www.lrt.lt/mediateka/irasas/2000127261/greita-ir-gardu-sicilijos-ikvepta-klasikiniu-makaronu-su-baklazanais-vakariene', |
18 | 'md5': '85cb2bb530f31d91a9c65b479516ade4', | |
4dc19c09 | 19 | 'info_dict': { |
8bdd16b4 | 20 | 'id': '2000127261', |
4dc19c09 | 21 | 'ext': 'mp4', |
8bdd16b4 | 22 | 'title': 'Greita ir gardu: Sicilijos įkvėpta klasikinių makaronų su baklažanais vakarienė', |
23 | 'description': 'md5:ad7d985f51b0dc1489ba2d76d7ed47fa', | |
24 | 'duration': 3035, | |
25 | 'timestamp': 1604079000, | |
26 | 'upload_date': '20201030', | |
4dc19c09 | 27 | }, |
2512b174 S |
28 | }, { |
29 | # direct mp3 download | |
30 | 'url': 'http://www.lrt.lt/mediateka/irasas/1013074524/', | |
31 | 'md5': '389da8ca3cad0f51d12bed0c844f6a0a', | |
32 | 'info_dict': { | |
33 | 'id': '1013074524', | |
34 | 'ext': 'mp3', | |
35 | 'title': 'Kita tema 2016-09-05 15:05', | |
36 | 'description': 'md5:1b295a8fc7219ed0d543fc228c931fb5', | |
37 | 'duration': 3008, | |
38 | 'view_count': int, | |
39 | 'like_count': int, | |
4dc19c09 | 40 | }, |
2512b174 | 41 | }] |
4dc19c09 | 42 | |
8bdd16b4 | 43 | def _extract_js_var(self, webpage, var_name, default): |
44 | return self._search_regex( | |
45 | r'%s\s*=\s*(["\'])((?:(?!\1).)+)\1' % var_name, | |
46 | webpage, var_name.replace('_', ' '), default, group=2) | |
47 | ||
4dc19c09 | 48 | def _real_extract(self, url): |
5ad28e7f | 49 | path, video_id = self._match_valid_url(url).groups() |
4dc19c09 NJ |
50 | webpage = self._download_webpage(url, video_id) |
51 | ||
8bdd16b4 | 52 | media_url = self._extract_js_var(webpage, 'main_url', path) |
53 | media = self._download_json(self._extract_js_var( | |
54 | webpage, 'media_info_url', | |
55 | 'https://www.lrt.lt/servisai/stream_url/vod/media_info/'), | |
56 | video_id, query={'url': media_url}) | |
57 | jw_data = self._parse_jwplayer_data( | |
58 | media['playlist_item'], video_id, base_url=url) | |
f7e1d82d | 59 | |
8bdd16b4 | 60 | json_ld_data = self._search_json_ld(webpage, video_id) |
4dc19c09 | 61 | |
8bdd16b4 | 62 | tags = [] |
63 | for tag in (media.get('tags') or []): | |
64 | tag_name = tag.get('name') | |
65 | if not tag_name: | |
66 | continue | |
67 | tags.append(tag_name) | |
15aad84d | 68 | |
8bdd16b4 | 69 | clean_info = { |
70 | 'description': clean_html(media.get('content')), | |
71 | 'tags': tags, | |
4dc19c09 | 72 | } |
8bdd16b4 | 73 | |
74 | return merge_dicts(clean_info, jw_data, json_ld_data) |