]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tvigle.py
Update changelog.
[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 parse_age_limit,
10 )
11
12
13 class TvigleIE(InfoExtractor):
14 IE_NAME = 'tvigle'
15 IE_DESC = 'Интернет-телевидение Tvigle.ru'
16 _VALID_URL = r'https?://(?:www\.)?(?:tvigle\.ru/(?:[^/]+/)+(?P<display_id>[^/]+)/$|cloud\.tvigle\.ru/video/(?P<id>\d+))'
17
18 _TESTS = [
19 {
20 'url': 'http://www.tvigle.ru/video/sokrat/',
21 'md5': '36514aed3657d4f70b4b2cef8eb520cd',
22 'info_dict': {
23 'id': '1848932',
24 'display_id': 'sokrat',
25 'ext': 'flv',
26 'title': 'Сократ',
27 'description': 'md5:a05bd01be310074d5833efc6743be95e',
28 'duration': 6586,
29 'age_limit': 0,
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 'url': 'https://cloud.tvigle.ru/video/5267604/',
45 'only_matching': True,
46 }
47 ]
48
49 def _real_extract(self, url):
50 mobj = re.match(self._VALID_URL, url)
51 video_id = mobj.group('id')
52 display_id = mobj.group('display_id')
53
54 if not video_id:
55 webpage = self._download_webpage(url, display_id)
56 video_id = self._html_search_regex(
57 r'<li class="video-preview current_playing" id="(\d+)">',
58 webpage, 'video id')
59
60 video_data = self._download_json(
61 'http://cloud.tvigle.ru/api/play/video/%s/' % video_id, display_id)
62
63 item = video_data['playlist']['items'][0]
64
65 title = item['title']
66 description = item['description']
67 thumbnail = item['thumbnail']
68 duration = float_or_none(item.get('durationMilliseconds'), 1000)
69 age_limit = parse_age_limit(item.get('ageRestrictions'))
70
71 formats = []
72 for vcodec, fmts in item['videos'].items():
73 for quality, video_url in fmts.items():
74 formats.append({
75 'url': video_url,
76 'format_id': '%s-%s' % (vcodec, quality),
77 'vcodec': vcodec,
78 'height': int(quality[:-1]),
79 'filesize': item['video_files_size'][vcodec][quality],
80 })
81 self._sort_formats(formats)
82
83 return {
84 'id': video_id,
85 'display_id': display_id,
86 'title': title,
87 'description': description,
88 'thumbnail': thumbnail,
89 'duration': duration,
90 'age_limit': age_limit,
91 'formats': formats,
92 }