]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tvigle.py
27962b5fe146dd16e85f46e341725b4e30bf24e1
[youtubedl] / youtube_dl / extractor / tvigle.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 float_or_none,
9 str_to_int,
10 )
11
12
13 class TvigleIE(InfoExtractor):
14 IE_NAME = 'tvigle'
15 IE_DESC = 'Интернет-телевидение Tvigle.ru'
16 _VALID_URL = r'http://(?:www\.)?tvigle\.ru/(?:[^/]+/)+(?P<display_id>[^/]+)/$'
17
18 _TESTS = [
19 {
20 'url': 'http://www.tvigle.ru/video/brat/',
21 'md5': 'ff4344a4894b0524441fb6f8218dc716',
22 'info_dict': {
23 'id': '5118490',
24 'display_id': 'brat',
25 'ext': 'mp4',
26 'title': 'Брат',
27 'description': 'md5:d16ac7c0b47052ea51fddb92c4e413eb',
28 'duration': 5722.6,
29 'age_limit': 16,
30 },
31 },
32 {
33 'url': 'http://www.tvigle.ru/video/vladimir-vysotskii/vedushchii-teleprogrammy-60-minut-ssha-o-vladimire-vysotskom/',
34 'md5': 'd9012d7c7c598fe7a11d7fb46dc1f574',
35 'info_dict': {
36 'id': '5142516',
37 'ext': 'mp4',
38 'title': 'Ведущий телепрограммы «60 минут» (США) о Владимире Высоцком',
39 'description': 'md5:027f7dc872948f14c96d19b4178428a4',
40 'duration': 186.080,
41 'age_limit': 0,
42 },
43 },
44 ]
45
46 def _real_extract(self, url):
47 mobj = re.match(self._VALID_URL, url)
48 display_id = mobj.group('display_id')
49
50 webpage = self._download_webpage(url, display_id)
51
52 video_id = self._html_search_regex(
53 r'<li class="video-preview current_playing" id="(\d+)">', webpage, 'video id')
54
55 video_data = self._download_json(
56 'http://cloud.tvigle.ru/api/play/video/%s/' % video_id, display_id)
57
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'])
65
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]),
74 'filesize': item['video_files_size'][vcodec][quality],
75 })
76 self._sort_formats(formats)
77
78 return {
79 'id': video_id,
80 'display_id': display_id,
81 'title': title,
82 'description': description,
83 'thumbnail': thumbnail,
84 'duration': duration,
85 'age_limit': age_limit,
86 'formats': formats,
87 }