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