]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/tvigle.py
cc1d35dc239b29872e941addd5cdbc2e9c749d02
[yt-dlp.git] / yt_dlp / extractor / tvigle.py
1 from .common import InfoExtractor
2 from ..utils import (
3 ExtractorError,
4 float_or_none,
5 int_or_none,
6 parse_age_limit,
7 try_get,
8 url_or_none,
9 )
10
11
12 class TvigleIE(InfoExtractor):
13 IE_NAME = 'tvigle'
14 IE_DESC = 'Интернет-телевидение Tvigle.ru'
15 _VALID_URL = r'https?://(?:www\.)?(?:tvigle\.ru/(?:[^/]+/)+(?P<display_id>[^/]+)/$|cloud\.tvigle\.ru/video/(?P<id>\d+))'
16
17 _GEO_BYPASS = False
18 _GEO_COUNTRIES = ['RU']
19
20 _TESTS = [
21 {
22 'url': 'http://www.tvigle.ru/video/sokrat/',
23 'info_dict': {
24 'id': '1848932',
25 'display_id': 'sokrat',
26 'ext': 'mp4',
27 'title': 'Сократ',
28 'description': 'md5:d6b92ffb7217b4b8ebad2e7665253c17',
29 'duration': 6586,
30 'age_limit': 12,
31 },
32 'skip': 'georestricted',
33 },
34 {
35 'url': 'http://www.tvigle.ru/video/vladimir-vysotskii/vedushchii-teleprogrammy-60-minut-ssha-o-vladimire-vysotskom/',
36 'info_dict': {
37 'id': '5142516',
38 'ext': 'flv',
39 'title': 'Ведущий телепрограммы «60 минут» (США) о Владимире Высоцком',
40 'description': 'md5:027f7dc872948f14c96d19b4178428a4',
41 'duration': 186.080,
42 'age_limit': 0,
43 },
44 'skip': 'georestricted',
45 }, {
46 'url': 'https://cloud.tvigle.ru/video/5267604/',
47 'only_matching': True,
48 }
49 ]
50
51 def _real_extract(self, url):
52 mobj = self._match_valid_url(url)
53 video_id = mobj.group('id')
54 display_id = mobj.group('display_id')
55
56 if not video_id:
57 webpage = self._download_webpage(url, display_id)
58 video_id = self._html_search_regex(
59 (r'<div[^>]+class=["\']player["\'][^>]+id=["\'](\d+)',
60 r'cloudId\s*=\s*["\'](\d+)',
61 r'class="video-preview current_playing" id="(\d+)"'),
62 webpage, 'video id')
63
64 video_data = self._download_json(
65 'http://cloud.tvigle.ru/api/play/video/%s/' % video_id, display_id)
66
67 item = video_data['playlist']['items'][0]
68
69 videos = item.get('videos')
70
71 error_message = item.get('errorMessage')
72 if not videos and error_message:
73 if item.get('isGeoBlocked') is True:
74 self.raise_geo_restricted(
75 msg=error_message, countries=self._GEO_COUNTRIES)
76 else:
77 raise ExtractorError(
78 '%s returned error: %s' % (self.IE_NAME, error_message),
79 expected=True)
80
81 title = item['title']
82 description = item.get('description')
83 thumbnail = item.get('thumbnail')
84 duration = float_or_none(item.get('durationMilliseconds'), 1000)
85 age_limit = parse_age_limit(item.get('ageRestrictions'))
86
87 formats = []
88 for vcodec, url_or_fmts in item['videos'].items():
89 if vcodec == 'hls':
90 m3u8_url = url_or_none(url_or_fmts)
91 if not m3u8_url:
92 continue
93 formats.extend(self._extract_m3u8_formats(
94 m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
95 m3u8_id='hls', fatal=False))
96 elif vcodec == 'dash':
97 mpd_url = url_or_none(url_or_fmts)
98 if not mpd_url:
99 continue
100 formats.extend(self._extract_mpd_formats(
101 mpd_url, video_id, mpd_id='dash', fatal=False))
102 else:
103 if not isinstance(url_or_fmts, dict):
104 continue
105 for format_id, video_url in url_or_fmts.items():
106 if format_id == 'm3u8':
107 continue
108 video_url = url_or_none(video_url)
109 if not video_url:
110 continue
111 height = self._search_regex(
112 r'^(\d+)[pP]$', format_id, 'height', default=None)
113 filesize = int_or_none(try_get(
114 item, lambda x: x['video_files_size'][vcodec][format_id]))
115 formats.append({
116 'url': video_url,
117 'format_id': '%s-%s' % (vcodec, format_id),
118 'vcodec': vcodec,
119 'height': int_or_none(height),
120 'filesize': filesize,
121 })
122 self._sort_formats(formats)
123
124 return {
125 'id': video_id,
126 'display_id': display_id,
127 'title': title,
128 'description': description,
129 'thumbnail': thumbnail,
130 'duration': duration,
131 'age_limit': age_limit,
132 'formats': formats,
133 }