]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/lrt.py
[youtube] Extend _VALID_URL (Closes #7694)
[yt-dlp.git] / youtube_dl / extractor / lrt.py
CommitLineData
4dc19c09
NJ
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
4dc19c09
NJ
5
6from .common import InfoExtractor
7from ..utils import (
8 determine_ext,
9 js_to_json,
10 parse_duration,
11 remove_end,
12)
13
14
15class LRTIE(InfoExtractor):
16 IE_NAME = 'lrt.lt'
17 _VALID_URL = r'https?://(?:www\.)?lrt\.lt/mediateka/irasas/(?P<id>[0-9]+)'
18 _TEST = {
19 'url': 'http://www.lrt.lt/mediateka/irasas/54391/',
20 'info_dict': {
21 'id': '54391',
22 'ext': 'mp4',
23 'title': 'Septynios Kauno dienos',
9a76f416 24 'description': 'md5:24d84534c7dc76581e59f5689462411a',
4dc19c09
NJ
25 'duration': 1783,
26 },
27 'params': {
28 'skip_download': True, # HLS download
29 },
4dc19c09
NJ
30 }
31
32 def _real_extract(self, url):
8112d4b2 33 video_id = self._match_id(url)
4dc19c09
NJ
34 webpage = self._download_webpage(url, video_id)
35
36 title = remove_end(self._og_search_title(webpage), ' - LRT')
37 thumbnail = self._og_search_thumbnail(webpage)
38 description = self._og_search_description(webpage)
39 duration = parse_duration(self._search_regex(
40 r"'duration':\s*'([^']+)',", webpage,
41 'duration', fatal=False, default=None))
42
43 formats = []
44 for js in re.findall(r'(?s)config:\s*(\{.*?\})', webpage):
adf3c58a
NJ
45 data = self._parse_json(js, video_id, transform_source=js_to_json)
46 if 'provider' not in data:
47 continue
4dc19c09
NJ
48 if data['provider'] == 'rtmp':
49 formats.append({
50 'format_id': 'rtmp',
51 'ext': determine_ext(data['file']),
52 'url': data['streamer'],
53 'play_path': 'mp4:%s' % data['file'],
54 'preference': -1,
dc570c49 55 'rtmp_real_time': True,
4dc19c09
NJ
56 })
57 else:
58 formats.extend(
59 self._extract_m3u8_formats(data['file'], video_id, 'mp4'))
60
61 return {
62 'id': video_id,
63 'title': title,
64 'formats': formats,
65 'thumbnail': thumbnail,
66 'description': description,
67 'duration': duration,
68 }