]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/videomore.py
[videomore] Fix extraction (Closes #10592)
[yt-dlp.git] / 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': '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': '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': '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 mobj:
90 return mobj.group('url')
91
92 def _real_extract(self, url):
93 mobj = re.match(self._VALID_URL, url)
94 video_id = mobj.group('sid') or mobj.group('id')
95
96 video = self._download_xml(
97 'http://videomore.ru/video/tracks/%s.xml' % video_id,
98 video_id, 'Downloading video XML')
99
100 item = xpath_element(video, './/playlist/item', fatal=True)
101
102 title = xpath_text(
103 item, ('./title', './episode_name'), 'title', fatal=True)
104
105 video_url = xpath_text(item, './video_url', 'video url', fatal=True)
106 formats = self._extract_f4m_formats(video_url, video_id, f4m_id='hds')
107 self._sort_formats(formats)
108
109 thumbnail = xpath_text(item, './thumbnail_url')
110 duration = int_or_none(xpath_text(item, './duration'))
111 view_count = int_or_none(xpath_text(item, './views'))
112 comment_count = int_or_none(xpath_text(item, './count_comments'))
113 age_limit = int_or_none(xpath_text(item, './min_age'))
114
115 series = xpath_text(item, './project_name')
116 episode = xpath_text(item, './episode_name')
117
118 return {
119 'id': video_id,
120 'title': title,
121 'series': series,
122 'episode': episode,
123 'thumbnail': thumbnail,
124 'duration': duration,
125 'view_count': view_count,
126 'comment_count': comment_count,
127 'age_limit': age_limit,
128 'formats': formats,
129 }
130
131
132 class VideomoreVideoIE(InfoExtractor):
133 IE_NAME = 'videomore:video'
134 _VALID_URL = r'https?://videomore\.ru/(?:(?:[^/]+/){2})?(?P<id>[^/?#&]+)[/?#&]*$'
135 _TESTS = [{
136 # single video with og:video:iframe
137 'url': 'http://videomore.ru/elki_3',
138 'info_dict': {
139 'id': '364623',
140 'ext': 'flv',
141 'title': 'Ёлки 3',
142 'description': '',
143 'thumbnail': 're:^https?://.*\.jpg',
144 'duration': 5579,
145 'age_limit': 6,
146 'view_count': int,
147 },
148 'params': {
149 'skip_download': True,
150 },
151 }, {
152 # season single series with og:video:iframe
153 'url': 'http://videomore.ru/poslednii_ment/1_sezon/14_seriya',
154 'only_matching': True,
155 }, {
156 'url': 'http://videomore.ru/sejchas_v_seti/serii_221-240/226_vypusk',
157 'only_matching': True,
158 }, {
159 # single video without og:video:iframe
160 'url': 'http://videomore.ru/marin_i_ego_druzya',
161 'info_dict': {
162 'id': '359073',
163 'ext': 'flv',
164 'title': '1 серия. Здравствуй, Аквавилль!',
165 'description': 'md5:c6003179538b5d353e7bcd5b1372b2d7',
166 'thumbnail': 're:^https?://.*\.jpg',
167 'duration': 754,
168 'age_limit': 6,
169 'view_count': int,
170 },
171 'params': {
172 'skip_download': True,
173 },
174 }]
175
176 @classmethod
177 def suitable(cls, url):
178 return False if VideomoreIE.suitable(url) else super(VideomoreVideoIE, cls).suitable(url)
179
180 def _real_extract(self, url):
181 display_id = self._match_id(url)
182
183 webpage = self._download_webpage(url, display_id)
184
185 video_url = self._og_search_property(
186 'video:iframe', webpage, 'video url', default=None)
187
188 if not video_url:
189 video_id = self._search_regex(
190 (r'config\s*:\s*["\']https?://videomore\.ru/video/tracks/(\d+)\.xml',
191 r'track-id=["\'](\d+)',
192 r'xcnt_product_id\s*=\s*(\d+)'), webpage, 'video id')
193 video_url = 'videomore:%s' % video_id
194
195 return self.url_result(video_url, VideomoreIE.ie_key())
196
197
198 class VideomoreSeasonIE(InfoExtractor):
199 IE_NAME = 'videomore:season'
200 _VALID_URL = r'https?://videomore\.ru/(?!embed)(?P<id>[^/]+/[^/?#&]+)[/?#&]*$'
201 _TESTS = [{
202 'url': 'http://videomore.ru/molodezhka/sezon_promo',
203 'info_dict': {
204 'id': 'molodezhka/sezon_promo',
205 'title': 'Молодежка Промо',
206 },
207 'playlist_mincount': 12,
208 }]
209
210 def _real_extract(self, url):
211 display_id = self._match_id(url)
212
213 webpage = self._download_webpage(url, display_id)
214
215 title = self._og_search_title(webpage)
216
217 entries = [
218 self.url_result(item) for item in re.findall(
219 r'<a[^>]+href="((?:https?:)?//videomore\.ru/%s/[^/]+)"[^>]+class="widget-item-desc"'
220 % display_id, webpage)]
221
222 return self.playlist_result(entries, display_id, title)