]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/videomore.py
debian/README.source: Update steps used to create new release.
[youtubedl] / youtube_dl / extractor / videomore.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 int_or_none,
9 xpath_element,
10 xpath_text,
11 )
12
13
14 class VideomoreIE(InfoExtractor):
15 IE_NAME = 'videomore'
16 _VALID_URL = r'videomore:(?P<sid>\d+)$|https?://videomore\.ru/(?:(?:embed|[^/]+/[^/]+)/|[^/]+\?.*\btrack_id=)(?P<id>\d+)(?:[/?#&]|\.(?:xml|json)|$)'
17 _TESTS = [{
18 'url': 'http://videomore.ru/kino_v_detalayah/5_sezon/367617',
19 'md5': '44455a346edc0d509ac5b5a5b531dc35',
20 'info_dict': {
21 'id': '367617',
22 'ext': 'flv',
23 'title': 'Кино в деталях 5 сезон В гостях Алексей Чумаков и Юлия Ковальчук',
24 'series': 'Кино в деталях',
25 'episode': 'В гостях Алексей Чумаков и Юлия Ковальчук',
26 'thumbnail': r're:^https?://.*\.jpg',
27 'duration': 2910,
28 'view_count': int,
29 'comment_count': int,
30 'age_limit': 16,
31 },
32 }, {
33 'url': 'http://videomore.ru/embed/259974',
34 'info_dict': {
35 'id': '259974',
36 'ext': 'flv',
37 'title': 'Молодежка 2 сезон 40 серия',
38 'series': 'Молодежка',
39 'episode': '40 серия',
40 'thumbnail': r're:^https?://.*\.jpg',
41 'duration': 2809,
42 'view_count': int,
43 'comment_count': int,
44 'age_limit': 16,
45 },
46 'params': {
47 'skip_download': True,
48 },
49 }, {
50 'url': 'http://videomore.ru/molodezhka/sezon_promo/341073',
51 'info_dict': {
52 'id': '341073',
53 'ext': 'flv',
54 'title': 'Промо Команда проиграла из-за Бакина?',
55 'episode': 'Команда проиграла из-за Бакина?',
56 'thumbnail': r're:^https?://.*\.jpg',
57 'duration': 29,
58 'age_limit': 16,
59 'view_count': int,
60 },
61 'params': {
62 'skip_download': True,
63 },
64 }, {
65 'url': 'http://videomore.ru/elki_3?track_id=364623',
66 'only_matching': True,
67 }, {
68 'url': 'http://videomore.ru/embed/364623',
69 'only_matching': True,
70 }, {
71 'url': 'http://videomore.ru/video/tracks/364623.xml',
72 'only_matching': True,
73 }, {
74 'url': 'http://videomore.ru/video/tracks/364623.json',
75 'only_matching': True,
76 }, {
77 'url': 'http://videomore.ru/video/tracks/158031/quotes/33248',
78 'only_matching': True,
79 }, {
80 'url': 'videomore:367617',
81 'only_matching': True,
82 }]
83
84 @staticmethod
85 def _extract_url(webpage):
86 mobj = re.search(
87 r'<object[^>]+data=(["\'])https?://videomore\.ru/player\.swf\?.*config=(?P<url>https?://videomore\.ru/(?:[^/]+/)+\d+\.xml).*\1',
88 webpage)
89 if not mobj:
90 mobj = re.search(
91 r'<iframe[^>]+src=([\'"])(?P<url>https?://videomore\.ru/embed/\d+)',
92 webpage)
93
94 if mobj:
95 return mobj.group('url')
96
97 def _real_extract(self, url):
98 mobj = re.match(self._VALID_URL, url)
99 video_id = mobj.group('sid') or mobj.group('id')
100
101 video = self._download_xml(
102 'http://videomore.ru/video/tracks/%s.xml' % video_id,
103 video_id, 'Downloading video XML')
104
105 item = xpath_element(video, './/playlist/item', fatal=True)
106
107 title = xpath_text(
108 item, ('./title', './episode_name'), 'title', fatal=True)
109
110 video_url = xpath_text(item, './video_url', 'video url', fatal=True)
111 formats = self._extract_f4m_formats(video_url, video_id, f4m_id='hds')
112 self._sort_formats(formats)
113
114 thumbnail = xpath_text(item, './thumbnail_url')
115 duration = int_or_none(xpath_text(item, './duration'))
116 view_count = int_or_none(xpath_text(item, './views'))
117 comment_count = int_or_none(xpath_text(item, './count_comments'))
118 age_limit = int_or_none(xpath_text(item, './min_age'))
119
120 series = xpath_text(item, './project_name')
121 episode = xpath_text(item, './episode_name')
122
123 return {
124 'id': video_id,
125 'title': title,
126 'series': series,
127 'episode': episode,
128 'thumbnail': thumbnail,
129 'duration': duration,
130 'view_count': view_count,
131 'comment_count': comment_count,
132 'age_limit': age_limit,
133 'formats': formats,
134 }
135
136
137 class VideomoreVideoIE(InfoExtractor):
138 IE_NAME = 'videomore:video'
139 _VALID_URL = r'https?://videomore\.ru/(?:(?:[^/]+/){2})?(?P<id>[^/?#&]+)[/?#&]*$'
140 _TESTS = [{
141 # single video with og:video:iframe
142 'url': 'http://videomore.ru/elki_3',
143 'info_dict': {
144 'id': '364623',
145 'ext': 'flv',
146 'title': 'Ёлки 3',
147 'description': '',
148 'thumbnail': r're:^https?://.*\.jpg',
149 'duration': 5579,
150 'age_limit': 6,
151 'view_count': int,
152 },
153 'params': {
154 'skip_download': True,
155 },
156 }, {
157 # season single series with og:video:iframe
158 'url': 'http://videomore.ru/poslednii_ment/1_sezon/14_seriya',
159 'only_matching': True,
160 }, {
161 'url': 'http://videomore.ru/sejchas_v_seti/serii_221-240/226_vypusk',
162 'only_matching': True,
163 }, {
164 # single video without og:video:iframe
165 'url': 'http://videomore.ru/marin_i_ego_druzya',
166 'info_dict': {
167 'id': '359073',
168 'ext': 'flv',
169 'title': '1 серия. Здравствуй, Аквавилль!',
170 'description': 'md5:c6003179538b5d353e7bcd5b1372b2d7',
171 'thumbnail': r're:^https?://.*\.jpg',
172 'duration': 754,
173 'age_limit': 6,
174 'view_count': int,
175 },
176 'params': {
177 'skip_download': True,
178 },
179 }]
180
181 @classmethod
182 def suitable(cls, url):
183 return False if VideomoreIE.suitable(url) else super(VideomoreVideoIE, cls).suitable(url)
184
185 def _real_extract(self, url):
186 display_id = self._match_id(url)
187
188 webpage = self._download_webpage(url, display_id)
189
190 video_url = self._og_search_property(
191 'video:iframe', webpage, 'video url', default=None)
192
193 if not video_url:
194 video_id = self._search_regex(
195 (r'config\s*:\s*["\']https?://videomore\.ru/video/tracks/(\d+)\.xml',
196 r'track-id=["\'](\d+)',
197 r'xcnt_product_id\s*=\s*(\d+)'), webpage, 'video id')
198 video_url = 'videomore:%s' % video_id
199
200 return self.url_result(video_url, VideomoreIE.ie_key())
201
202
203 class VideomoreSeasonIE(InfoExtractor):
204 IE_NAME = 'videomore:season'
205 _VALID_URL = r'https?://videomore\.ru/(?!embed)(?P<id>[^/]+/[^/?#&]+)[/?#&]*$'
206 _TESTS = [{
207 'url': 'http://videomore.ru/molodezhka/sezon_promo',
208 'info_dict': {
209 'id': 'molodezhka/sezon_promo',
210 'title': 'Молодежка Промо',
211 },
212 'playlist_mincount': 12,
213 }]
214
215 def _real_extract(self, url):
216 display_id = self._match_id(url)
217
218 webpage = self._download_webpage(url, display_id)
219
220 title = self._og_search_title(webpage)
221
222 entries = [
223 self.url_result(item) for item in re.findall(
224 r'<a[^>]+href="((?:https?:)?//videomore\.ru/%s/[^/]+)"[^>]+class="widget-item-desc"'
225 % display_id, webpage)]
226
227 return self.playlist_result(entries, display_id, title)