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