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