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