]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/videomore.py
Fix "invalid escape sequences" error on Python 3.6
[yt-dlp.git] / youtube_dl / extractor / videomore.py
CommitLineData
030dfb04
S
1# coding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
7from ..utils import (
8 int_or_none,
010d034f 9 xpath_element,
030dfb04
S
10 xpath_text,
11)
12
13
14class VideomoreIE(InfoExtractor):
69759a59 15 IE_NAME = 'videomore'
030dfb04
S
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',
010d034f 19 'md5': '44455a346edc0d509ac5b5a5b531dc35',
030dfb04
S
20 'info_dict': {
21 'id': '367617',
22 'ext': 'flv',
010d034f 23 'title': 'Кино в деталях 5 сезон В гостях Алексей Чумаков и Юлия Ковальчук',
7a0b07c7
S
24 'series': 'Кино в деталях',
25 'episode': 'В гостях Алексей Чумаков и Юлия Ковальчук',
ec85ded8 26 'thumbnail': r're:^https?://.*\.jpg',
030dfb04 27 'duration': 2910,
030dfb04 28 'view_count': int,
010d034f
S
29 'comment_count': int,
30 'age_limit': 16,
030dfb04 31 },
7a0b07c7
S
32 }, {
33 'url': 'http://videomore.ru/embed/259974',
34 'info_dict': {
35 'id': '259974',
36 'ext': 'flv',
010d034f 37 'title': 'Молодежка 2 сезон 40 серия',
7a0b07c7 38 'series': 'Молодежка',
010d034f 39 'episode': '40 серия',
ec85ded8 40 'thumbnail': r're:^https?://.*\.jpg',
7a0b07c7 41 'duration': 2809,
7a0b07c7 42 'view_count': int,
010d034f
S
43 'comment_count': int,
44 'age_limit': 16,
7a0b07c7
S
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',
010d034f 54 'title': 'Промо Команда проиграла из-за Бакина?',
7a0b07c7 55 'episode': 'Команда проиграла из-за Бакина?',
ec85ded8 56 'thumbnail': r're:^https?://.*\.jpg',
7a0b07c7
S
57 'duration': 29,
58 'age_limit': 16,
59 'view_count': int,
60 },
61 'params': {
62 'skip_download': True,
63 },
030dfb04
S
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(
12f211d0 87 r'<object[^>]+data=(["\'])https?://videomore\.ru/player\.swf\?.*config=(?P<url>https?://videomore\.ru/(?:[^/]+/)+\d+\.xml).*\1',
030dfb04 88 webpage)
146969e0
YCH
89 if not mobj:
90 mobj = re.search(
91 r'<iframe[^>]+src=([\'"])(?P<url>https?://videomore\.ru/embed/\d+)',
92 webpage)
93
030dfb04
S
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
010d034f
S
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)
030dfb04 111 formats = self._extract_f4m_formats(video_url, video_id, f4m_id='hds')
19dbaeec 112 self._sort_formats(formats)
030dfb04 113
010d034f
S
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'))
030dfb04 119
010d034f
S
120 series = xpath_text(item, './project_name')
121 episode = xpath_text(item, './episode_name')
7a0b07c7 122
030dfb04
S
123 return {
124 'id': video_id,
125 'title': title,
7a0b07c7
S
126 'series': series,
127 'episode': episode,
010d034f 128 'thumbnail': thumbnail,
030dfb04
S
129 'duration': duration,
130 'view_count': view_count,
010d034f 131 'comment_count': comment_count,
030dfb04
S
132 'age_limit': age_limit,
133 'formats': formats,
134 }
135
136
137class 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': '',
ec85ded8 148 'thumbnail': r're:^https?://.*\.jpg',
030dfb04
S
149 'duration': 5579,
150 'age_limit': 6,
151 'view_count': int,
152 },
153 'params': {
154 'skip_download': True,
155 },
156 }, {
dfb1b146 157 # season single series with og:video:iframe
030dfb04
S
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',
ec85ded8 171 'thumbnail': r're:^https?://.*\.jpg',
030dfb04
S
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
203class 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)