]>
Commit | Line | Data |
---|---|---|
bfd14b1b | 1 | # encoding: utf-8 |
1547c8cc | 2 | from __future__ import unicode_literals |
3 | ||
bfd14b1b | 4 | import re |
1547c8cc | 5 | import itertools |
bfd14b1b JMF |
6 | |
7 | from .common import InfoExtractor | |
1cc79574 | 8 | from ..compat import ( |
bfd14b1b | 9 | compat_str, |
1cc79574 PH |
10 | ) |
11 | from ..utils import ( | |
bfd14b1b | 12 | ExtractorError, |
1cc79574 | 13 | unified_strdate, |
bfd14b1b JMF |
14 | ) |
15 | ||
16 | ||
17 | class RutubeIE(InfoExtractor): | |
1547c8cc | 18 | IE_NAME = 'rutube' |
37e3b90d | 19 | IE_DESC = 'Rutube videos' |
e3a9f32f | 20 | _VALID_URL = r'https?://rutube\.ru/video/(?P<id>[\da-z]{32})' |
bfd14b1b JMF |
21 | |
22 | _TEST = { | |
1547c8cc | 23 | 'url': 'http://rutube.ru/video/3eac3b4561676c17df9132a9a1e62e3e/', |
1547c8cc | 24 | 'info_dict': { |
c72477bd S |
25 | 'id': '3eac3b4561676c17df9132a9a1e62e3e', |
26 | 'ext': 'mp4', | |
1547c8cc | 27 | 'title': 'Раненный кенгуру забежал в аптеку', |
00ff8f92 | 28 | 'description': 'http://www.ntdtv.ru ', |
29 | 'duration': 80, | |
1547c8cc | 30 | 'uploader': 'NTDRussian', |
31 | 'uploader_id': '29790', | |
00ff8f92 | 32 | 'upload_date': '20131016', |
bfd14b1b | 33 | }, |
1547c8cc | 34 | 'params': { |
bfd14b1b | 35 | # It requires ffmpeg (m3u8 download) |
1547c8cc | 36 | 'skip_download': True, |
bfd14b1b JMF |
37 | }, |
38 | } | |
39 | ||
bfd14b1b | 40 | def _real_extract(self, url): |
1cc79574 | 41 | video_id = self._match_id(url) |
18c95c1a | 42 | video = self._download_json( |
c72477bd S |
43 | 'http://rutube.ru/api/video/%s/?format=json' % video_id, |
44 | video_id, 'Downloading video JSON') | |
18c95c1a | 45 | |
bfd14b1b | 46 | # Some videos don't have the author field |
d7f1e7c8 S |
47 | author = video.get('author') or {} |
48 | ||
49 | options = self._download_json( | |
68905742 | 50 | 'http://rutube.ru/api/play/options/%s/?format=json' % video_id, |
d7f1e7c8 S |
51 | video_id, 'Downloading options JSON') |
52 | ||
53 | m3u8_url = options['video_balancer'].get('m3u8') | |
bfd14b1b | 54 | if m3u8_url is None: |
1547c8cc | 55 | raise ExtractorError('Couldn\'t find m3u8 manifest url') |
05177b34 | 56 | formats = self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4') |
bfd14b1b JMF |
57 | |
58 | return { | |
a2fb2a21 | 59 | 'id': video['id'], |
60 | 'title': video['title'], | |
61 | 'description': video['description'], | |
62 | 'duration': video['duration'], | |
63 | 'view_count': video['hits'], | |
05177b34 | 64 | 'formats': formats, |
a2fb2a21 | 65 | 'thumbnail': video['thumbnail_url'], |
bfd14b1b JMF |
66 | 'uploader': author.get('name'), |
67 | 'uploader_id': compat_str(author['id']) if author else None, | |
a2fb2a21 | 68 | 'upload_date': unified_strdate(video['created_ts']), |
69 | 'age_limit': 18 if video['is_adult'] else 0, | |
bfd14b1b | 70 | } |
1547c8cc | 71 | |
72 | ||
7a1818c9 PH |
73 | class RutubeEmbedIE(InfoExtractor): |
74 | IE_NAME = 'rutube:embed' | |
75 | IE_DESC = 'Rutube embedded videos' | |
76 | _VALID_URL = 'https?://rutube\.ru/video/embed/(?P<id>[0-9]+)' | |
77 | ||
78 | _TEST = { | |
79 | 'url': 'http://rutube.ru/video/embed/6722881?vk_puid37=&vk_puid38=', | |
80 | 'info_dict': { | |
81 | 'id': 'a10e53b86e8f349080f718582ce4c661', | |
82 | 'ext': 'mp4', | |
83 | 'upload_date': '20131223', | |
84 | 'uploader_id': '297833', | |
85 | 'description': 'Видео группы ★http://vk.com/foxkidsreset★ музей Fox Kids и Jetix<br/><br/> восстановлено и сделано в шикоформате subziro89 http://vk.com/subziro89', | |
86 | 'uploader': 'subziro89 ILya', | |
87 | 'title': 'Мистический городок Эйри в Индиан 5 серия озвучка subziro89', | |
88 | }, | |
89 | 'params': { | |
90 | 'skip_download': 'Requires ffmpeg', | |
91 | }, | |
92 | } | |
93 | ||
94 | def _real_extract(self, url): | |
95 | embed_id = self._match_id(url) | |
96 | webpage = self._download_webpage(url, embed_id) | |
97 | ||
98 | canonical_url = self._html_search_regex( | |
99 | r'<link\s+rel="canonical"\s+href="([^"]+?)"', webpage, | |
100 | 'Canonical URL') | |
101 | return self.url_result(canonical_url, 'Rutube') | |
102 | ||
103 | ||
1547c8cc | 104 | class RutubeChannelIE(InfoExtractor): |
105 | IE_NAME = 'rutube:channel' | |
37e3b90d | 106 | IE_DESC = 'Rutube channels' |
1547c8cc | 107 | _VALID_URL = r'http://rutube\.ru/tags/video/(?P<id>\d+)' |
22a6f150 PH |
108 | _TESTS = [{ |
109 | 'url': 'http://rutube.ru/tags/video/1800/', | |
110 | 'info_dict': { | |
111 | 'id': '1800', | |
112 | }, | |
113 | 'playlist_mincount': 68, | |
114 | }] | |
1547c8cc | 115 | |
116 | _PAGE_TEMPLATE = 'http://rutube.ru/api/tags/video/%s/?page=%s&format=json' | |
117 | ||
118 | def _extract_videos(self, channel_id, channel_title=None): | |
119 | entries = [] | |
120 | for pagenum in itertools.count(1): | |
18c95c1a | 121 | page = self._download_json( |
37e3b90d PH |
122 | self._PAGE_TEMPLATE % (channel_id, pagenum), |
123 | channel_id, 'Downloading page %s' % pagenum) | |
1547c8cc | 124 | results = page['results'] |
37e3b90d PH |
125 | if not results: |
126 | break | |
a2fb2a21 | 127 | entries.extend(self.url_result(result['video_url'], 'Rutube') for result in results) |
37e3b90d PH |
128 | if not page['has_next']: |
129 | break | |
1547c8cc | 130 | return self.playlist_result(entries, channel_id, channel_title) |
131 | ||
132 | def _real_extract(self, url): | |
133 | mobj = re.match(self._VALID_URL, url) | |
134 | channel_id = mobj.group('id') | |
135 | return self._extract_videos(channel_id) | |
136 | ||
137 | ||
138 | class RutubeMovieIE(RutubeChannelIE): | |
139 | IE_NAME = 'rutube:movie' | |
37e3b90d | 140 | IE_DESC = 'Rutube movies' |
1547c8cc | 141 | _VALID_URL = r'http://rutube\.ru/metainfo/tv/(?P<id>\d+)' |
22a6f150 | 142 | _TESTS = [] |
1547c8cc | 143 | |
144 | _MOVIE_TEMPLATE = 'http://rutube.ru/api/metainfo/tv/%s/?format=json' | |
145 | _PAGE_TEMPLATE = 'http://rutube.ru/api/metainfo/tv/%s/video?page=%s&format=json' | |
146 | ||
147 | def _real_extract(self, url): | |
1cc79574 | 148 | movie_id = self._match_id(url) |
18c95c1a | 149 | movie = self._download_json( |
37e3b90d PH |
150 | self._MOVIE_TEMPLATE % movie_id, movie_id, |
151 | 'Downloading movie JSON') | |
1547c8cc | 152 | movie_name = movie['name'] |
e3a9f32f | 153 | return self._extract_videos(movie_id, movie_name) |
154 | ||
155 | ||
156 | class RutubePersonIE(RutubeChannelIE): | |
157 | IE_NAME = 'rutube:person' | |
158 | IE_DESC = 'Rutube person videos' | |
159 | _VALID_URL = r'http://rutube\.ru/video/person/(?P<id>\d+)' | |
22a6f150 PH |
160 | _TESTS = [{ |
161 | 'url': 'http://rutube.ru/video/person/313878/', | |
162 | 'info_dict': { | |
163 | 'id': '313878', | |
164 | }, | |
165 | 'playlist_mincount': 37, | |
166 | }] | |
e3a9f32f | 167 | |
37e3b90d | 168 | _PAGE_TEMPLATE = 'http://rutube.ru/api/video/person/%s/?page=%s&format=json' |