]>
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 | |
8 | from ..utils import ( | |
bfd14b1b | 9 | compat_str, |
a2fb2a21 | 10 | unified_strdate, |
bfd14b1b JMF |
11 | ExtractorError, |
12 | ) | |
13 | ||
14 | ||
15 | class RutubeIE(InfoExtractor): | |
1547c8cc | 16 | IE_NAME = 'rutube' |
37e3b90d | 17 | IE_DESC = 'Rutube videos' |
e3a9f32f | 18 | _VALID_URL = r'https?://rutube\.ru/video/(?P<id>[\da-z]{32})' |
bfd14b1b JMF |
19 | |
20 | _TEST = { | |
1547c8cc | 21 | 'url': 'http://rutube.ru/video/3eac3b4561676c17df9132a9a1e62e3e/', |
1547c8cc | 22 | 'info_dict': { |
c72477bd S |
23 | 'id': '3eac3b4561676c17df9132a9a1e62e3e', |
24 | 'ext': 'mp4', | |
1547c8cc | 25 | 'title': 'Раненный кенгуру забежал в аптеку', |
00ff8f92 | 26 | 'description': 'http://www.ntdtv.ru ', |
27 | 'duration': 80, | |
1547c8cc | 28 | 'uploader': 'NTDRussian', |
29 | 'uploader_id': '29790', | |
00ff8f92 | 30 | 'upload_date': '20131016', |
bfd14b1b | 31 | }, |
1547c8cc | 32 | 'params': { |
bfd14b1b | 33 | # It requires ffmpeg (m3u8 download) |
1547c8cc | 34 | 'skip_download': True, |
bfd14b1b JMF |
35 | }, |
36 | } | |
37 | ||
bfd14b1b JMF |
38 | def _real_extract(self, url): |
39 | mobj = re.match(self._VALID_URL, url) | |
e3a9f32f | 40 | video_id = mobj.group('id') |
18c95c1a JMF |
41 | |
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') |
bfd14b1b JMF |
56 | |
57 | return { | |
a2fb2a21 | 58 | 'id': video['id'], |
59 | 'title': video['title'], | |
60 | 'description': video['description'], | |
61 | 'duration': video['duration'], | |
62 | 'view_count': video['hits'], | |
bfd14b1b JMF |
63 | 'url': m3u8_url, |
64 | 'ext': 'mp4', | |
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 | ||
73 | class RutubeChannelIE(InfoExtractor): | |
74 | IE_NAME = 'rutube:channel' | |
37e3b90d | 75 | IE_DESC = 'Rutube channels' |
1547c8cc | 76 | _VALID_URL = r'http://rutube\.ru/tags/video/(?P<id>\d+)' |
22a6f150 PH |
77 | _TESTS = [{ |
78 | 'url': 'http://rutube.ru/tags/video/1800/', | |
79 | 'info_dict': { | |
80 | 'id': '1800', | |
81 | }, | |
82 | 'playlist_mincount': 68, | |
83 | }] | |
1547c8cc | 84 | |
85 | _PAGE_TEMPLATE = 'http://rutube.ru/api/tags/video/%s/?page=%s&format=json' | |
86 | ||
87 | def _extract_videos(self, channel_id, channel_title=None): | |
88 | entries = [] | |
89 | for pagenum in itertools.count(1): | |
18c95c1a | 90 | page = self._download_json( |
37e3b90d PH |
91 | self._PAGE_TEMPLATE % (channel_id, pagenum), |
92 | channel_id, 'Downloading page %s' % pagenum) | |
1547c8cc | 93 | results = page['results'] |
37e3b90d PH |
94 | if not results: |
95 | break | |
a2fb2a21 | 96 | entries.extend(self.url_result(result['video_url'], 'Rutube') for result in results) |
37e3b90d PH |
97 | if not page['has_next']: |
98 | break | |
1547c8cc | 99 | return self.playlist_result(entries, channel_id, channel_title) |
100 | ||
101 | def _real_extract(self, url): | |
102 | mobj = re.match(self._VALID_URL, url) | |
103 | channel_id = mobj.group('id') | |
104 | return self._extract_videos(channel_id) | |
105 | ||
106 | ||
107 | class RutubeMovieIE(RutubeChannelIE): | |
108 | IE_NAME = 'rutube:movie' | |
37e3b90d | 109 | IE_DESC = 'Rutube movies' |
1547c8cc | 110 | _VALID_URL = r'http://rutube\.ru/metainfo/tv/(?P<id>\d+)' |
22a6f150 | 111 | _TESTS = [] |
1547c8cc | 112 | |
113 | _MOVIE_TEMPLATE = 'http://rutube.ru/api/metainfo/tv/%s/?format=json' | |
114 | _PAGE_TEMPLATE = 'http://rutube.ru/api/metainfo/tv/%s/video?page=%s&format=json' | |
115 | ||
116 | def _real_extract(self, url): | |
117 | mobj = re.match(self._VALID_URL, url) | |
118 | movie_id = mobj.group('id') | |
18c95c1a | 119 | movie = self._download_json( |
37e3b90d PH |
120 | self._MOVIE_TEMPLATE % movie_id, movie_id, |
121 | 'Downloading movie JSON') | |
1547c8cc | 122 | movie_name = movie['name'] |
e3a9f32f | 123 | return self._extract_videos(movie_id, movie_name) |
124 | ||
125 | ||
126 | class RutubePersonIE(RutubeChannelIE): | |
127 | IE_NAME = 'rutube:person' | |
128 | IE_DESC = 'Rutube person videos' | |
129 | _VALID_URL = r'http://rutube\.ru/video/person/(?P<id>\d+)' | |
22a6f150 PH |
130 | _TESTS = [{ |
131 | 'url': 'http://rutube.ru/video/person/313878/', | |
132 | 'info_dict': { | |
133 | 'id': '313878', | |
134 | }, | |
135 | 'playlist_mincount': 37, | |
136 | }] | |
e3a9f32f | 137 | |
37e3b90d | 138 | _PAGE_TEMPLATE = 'http://rutube.ru/api/video/person/%s/?page=%s&format=json' |