]>
Commit | Line | Data |
---|---|---|
fb8b8fdd S |
1 | from .common import InfoExtractor |
2 | from ..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 | ||
12 | class 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+))' |
c7095dad | 16 | |
b3aec476 S |
17 | _GEO_BYPASS = False |
18 | _GEO_COUNTRIES = ['RU'] | |
19 | ||
c7095dad S |
20 | _TESTS = [ |
21 | { | |
819039ee | 22 | 'url': 'http://www.tvigle.ru/video/sokrat/', |
c7095dad | 23 | 'info_dict': { |
819039ee S |
24 | 'id': '1848932', |
25 | 'display_id': 'sokrat', | |
be306d6a | 26 | 'ext': 'mp4', |
819039ee | 27 | 'title': 'Сократ', |
eb47569f | 28 | 'description': 'md5:d6b92ffb7217b4b8ebad2e7665253c17', |
819039ee | 29 | 'duration': 6586, |
eb47569f | 30 | 'age_limit': 12, |
c7095dad | 31 | }, |
3153a2c9 | 32 | 'skip': 'georestricted', |
c7095dad S |
33 | }, |
34 | { | |
884ae747 | 35 | 'url': 'http://www.tvigle.ru/video/vladimir-vysotskii/vedushchii-teleprogrammy-60-minut-ssha-o-vladimire-vysotskom/', |
c7095dad | 36 | 'info_dict': { |
884ae747 | 37 | 'id': '5142516', |
eb47569f | 38 | 'ext': 'flv', |
c7095dad S |
39 | 'title': 'Ведущий телепрограммы «60 минут» (США) о Владимире Высоцком', |
40 | 'description': 'md5:027f7dc872948f14c96d19b4178428a4', | |
884ae747 S |
41 | 'duration': 186.080, |
42 | 'age_limit': 0, | |
c7095dad | 43 | }, |
3153a2c9 | 44 | 'skip': 'georestricted', |
7f2a9f1b S |
45 | }, { |
46 | 'url': 'https://cloud.tvigle.ru/video/5267604/', | |
47 | 'only_matching': True, | |
48 | } | |
c7095dad | 49 | ] |
fb8b8fdd S |
50 | |
51 | def _real_extract(self, url): | |
5ad28e7f | 52 | mobj = self._match_valid_url(url) |
7f2a9f1b S |
53 | video_id = mobj.group('id') |
54 | display_id = mobj.group('display_id') | |
fb8b8fdd | 55 | |
7f2a9f1b S |
56 | if not video_id: |
57 | webpage = self._download_webpage(url, display_id) | |
58 | video_id = self._html_search_regex( | |
12a51345 | 59 | (r'<div[^>]+class=["\']player["\'][^>]+id=["\'](\d+)', |
be306d6a | 60 | r'cloudId\s*=\s*["\'](\d+)', |
12a51345 | 61 | r'class="video-preview current_playing" id="(\d+)"'), |
7f2a9f1b | 62 | webpage, 'video id') |
fb8b8fdd | 63 | |
884ae747 S |
64 | video_data = self._download_json( |
65 | 'http://cloud.tvigle.ru/api/play/video/%s/' % video_id, display_id) | |
fb8b8fdd | 66 | |
884ae747 S |
67 | item = video_data['playlist']['items'][0] |
68 | ||
15b74b94 S |
69 | videos = item.get('videos') |
70 | ||
71 | error_message = item.get('errorMessage') | |
72 | if not videos and error_message: | |
b3aec476 S |
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) | |
15b74b94 | 80 | |
884ae747 | 81 | title = item['title'] |
7584e38c S |
82 | description = item.get('description') |
83 | thumbnail = item.get('thumbnail') | |
819039ee S |
84 | duration = float_or_none(item.get('durationMilliseconds'), 1000) |
85 | age_limit = parse_age_limit(item.get('ageRestrictions')) | |
fb8b8fdd | 86 | |
884ae747 | 87 | formats = [] |
be306d6a | 88 | for vcodec, url_or_fmts in item['videos'].items(): |
1988647d | 89 | if vcodec == 'hls': |
be306d6a S |
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): | |
eb47569f | 104 | continue |
be306d6a S |
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 | }) | |
fb8b8fdd S |
122 | self._sort_formats(formats) |
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 | } |