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