]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/tvc.py
d/rules: Run offline tests.
[youtubedl] / youtube_dl / extractor / tvc.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 clean_html,
9 int_or_none,
10 )
11
12
13 class TVCIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?tvc\.ru/video/iframe/id/(?P<id>\d+)'
15 _TEST = {
16 'url': 'http://www.tvc.ru/video/iframe/id/74622/isPlay/false/id_stat/channel/?acc_video_id=/channel/brand/id/17/show/episodes/episode_id/39702',
17 'md5': 'bbc5ff531d1e90e856f60fc4b3afd708',
18 'info_dict': {
19 'id': '74622',
20 'ext': 'mp4',
21 'title': 'События. "События". Эфир от 22.05.2015 14:30',
22 'thumbnail': r're:^https?://.*\.jpg$',
23 'duration': 1122,
24 },
25 }
26
27 @classmethod
28 def _extract_url(cls, webpage):
29 mobj = re.search(
30 r'<iframe[^>]+?src=(["\'])(?P<url>(?:http:)?//(?:www\.)?tvc\.ru/video/iframe/id/[^"]+)\1', webpage)
31 if mobj:
32 return mobj.group('url')
33
34 def _real_extract(self, url):
35 video_id = self._match_id(url)
36
37 video = self._download_json(
38 'http://www.tvc.ru/video/json/id/%s' % video_id, video_id)
39
40 formats = []
41 for info in video.get('path', {}).get('quality', []):
42 video_url = info.get('url')
43 if not video_url:
44 continue
45 format_id = self._search_regex(
46 r'cdnvideo/([^/]+?)(?:-[^/]+?)?/', video_url,
47 'format id', default=None)
48 formats.append({
49 'url': video_url,
50 'format_id': format_id,
51 'width': int_or_none(info.get('width')),
52 'height': int_or_none(info.get('height')),
53 'tbr': int_or_none(info.get('bitrate')),
54 })
55 self._sort_formats(formats)
56
57 return {
58 'id': video_id,
59 'title': video['title'],
60 'thumbnail': video.get('picture'),
61 'duration': int_or_none(video.get('duration')),
62 'formats': formats,
63 }
64
65
66 class TVCArticleIE(InfoExtractor):
67 _VALID_URL = r'https?://(?:www\.)?tvc\.ru/(?!video/iframe/id/)(?P<id>[^?#]+)'
68 _TESTS = [{
69 'url': 'http://www.tvc.ru/channel/brand/id/29/show/episodes/episode_id/39702/',
70 'info_dict': {
71 'id': '74622',
72 'ext': 'mp4',
73 'title': 'События. "События". Эфир от 22.05.2015 14:30',
74 'description': 'md5:ad7aa7db22903f983e687b8a3e98c6dd',
75 'thumbnail': r're:^https?://.*\.jpg$',
76 'duration': 1122,
77 },
78 }, {
79 'url': 'http://www.tvc.ru/news/show/id/69944',
80 'info_dict': {
81 'id': '75399',
82 'ext': 'mp4',
83 'title': 'Эксперты: в столице встал вопрос о максимально безопасных остановках',
84 'description': 'md5:f2098f71e21f309e89f69b525fd9846e',
85 'thumbnail': r're:^https?://.*\.jpg$',
86 'duration': 278,
87 },
88 }, {
89 'url': 'http://www.tvc.ru/channel/brand/id/47/show/episodes#',
90 'info_dict': {
91 'id': '2185',
92 'ext': 'mp4',
93 'title': 'Ещё не поздно. Эфир от 03.08.2013',
94 'description': 'md5:51fae9f3f8cfe67abce014e428e5b027',
95 'thumbnail': r're:^https?://.*\.jpg$',
96 'duration': 3316,
97 },
98 }]
99
100 def _real_extract(self, url):
101 webpage = self._download_webpage(url, self._match_id(url))
102 return {
103 '_type': 'url_transparent',
104 'ie_key': 'TVC',
105 'url': self._og_search_video_url(webpage),
106 'title': clean_html(self._og_search_title(webpage)),
107 'description': clean_html(self._og_search_description(webpage)),
108 'thumbnail': self._og_search_thumbnail(webpage),
109 }