]>
Commit | Line | Data |
---|---|---|
fb8b8fdd S |
1 | # encoding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
884ae747 S |
8 | float_or_none, |
9 | str_to_int, | |
fb8b8fdd S |
10 | ) |
11 | ||
12 | ||
13 | class TvigleIE(InfoExtractor): | |
14 | IE_NAME = 'tvigle' | |
15 | IE_DESC = 'Интернет-телевидение Tvigle.ru' | |
884ae747 | 16 | _VALID_URL = r'http://(?:www\.)?tvigle\.ru/(?:[^/]+/)+(?P<display_id>[^/]+)/$' |
c7095dad S |
17 | |
18 | _TESTS = [ | |
19 | { | |
a3b6be10 S |
20 | 'url': 'http://www.tvigle.ru/video/brat/', |
21 | 'md5': 'ff4344a4894b0524441fb6f8218dc716', | |
c7095dad | 22 | 'info_dict': { |
a3b6be10 S |
23 | 'id': '5118490', |
24 | 'display_id': 'brat', | |
884ae747 | 25 | 'ext': 'mp4', |
a3b6be10 S |
26 | 'title': 'Брат', |
27 | 'description': 'md5:d16ac7c0b47052ea51fddb92c4e413eb', | |
28 | 'duration': 5722.6, | |
29 | 'age_limit': 16, | |
c7095dad S |
30 | }, |
31 | }, | |
32 | { | |
884ae747 S |
33 | 'url': 'http://www.tvigle.ru/video/vladimir-vysotskii/vedushchii-teleprogrammy-60-minut-ssha-o-vladimire-vysotskom/', |
34 | 'md5': 'd9012d7c7c598fe7a11d7fb46dc1f574', | |
c7095dad | 35 | 'info_dict': { |
884ae747 S |
36 | 'id': '5142516', |
37 | 'ext': 'mp4', | |
c7095dad S |
38 | 'title': 'Ведущий телепрограммы «60 минут» (США) о Владимире Высоцком', |
39 | 'description': 'md5:027f7dc872948f14c96d19b4178428a4', | |
884ae747 S |
40 | 'duration': 186.080, |
41 | 'age_limit': 0, | |
c7095dad S |
42 | }, |
43 | }, | |
44 | ] | |
fb8b8fdd S |
45 | |
46 | def _real_extract(self, url): | |
47 | mobj = re.match(self._VALID_URL, url) | |
884ae747 | 48 | display_id = mobj.group('display_id') |
fb8b8fdd | 49 | |
884ae747 | 50 | webpage = self._download_webpage(url, display_id) |
fb8b8fdd | 51 | |
884ae747 S |
52 | video_id = self._html_search_regex( |
53 | r'<li class="video-preview current_playing" id="(\d+)">', webpage, 'video id') | |
fb8b8fdd | 54 | |
884ae747 S |
55 | video_data = self._download_json( |
56 | 'http://cloud.tvigle.ru/api/play/video/%s/' % video_id, display_id) | |
fb8b8fdd | 57 | |
884ae747 S |
58 | item = video_data['playlist']['items'][0] |
59 | ||
60 | title = item['title'] | |
61 | description = item['description'] | |
62 | thumbnail = item['thumbnail'] | |
63 | duration = float_or_none(item['durationMilliseconds'], 1000) | |
64 | age_limit = str_to_int(item['ageRestrictions']) | |
fb8b8fdd | 65 | |
884ae747 S |
66 | formats = [] |
67 | for vcodec, fmts in item['videos'].items(): | |
68 | for quality, video_url in fmts.items(): | |
69 | formats.append({ | |
70 | 'url': video_url, | |
71 | 'format_id': '%s-%s' % (vcodec, quality), | |
72 | 'vcodec': vcodec, | |
73 | 'height': int(quality[:-1]), | |
e497a7f2 | 74 | 'filesize': item['video_files_size'][vcodec][quality], |
884ae747 | 75 | }) |
fb8b8fdd S |
76 | self._sort_formats(formats) |
77 | ||
78 | return { | |
79 | 'id': video_id, | |
884ae747 | 80 | 'display_id': display_id, |
fb8b8fdd S |
81 | 'title': title, |
82 | 'description': description, | |
83 | 'thumbnail': thumbnail, | |
884ae747 S |
84 | 'duration': duration, |
85 | 'age_limit': age_limit, | |
fb8b8fdd S |
86 | 'formats': formats, |
87 | } |