]>
Commit | Line | Data |
---|---|---|
0138968a S |
1 | from __future__ import unicode_literals |
2 | ||
b7b36506 S |
3 | import itertools |
4 | ||
482aa3fe | 5 | from .common import InfoExtractor |
f31fd069 S |
6 | from ..compat import ( |
7 | compat_HTTPError, | |
8 | compat_str, | |
9 | ) | |
0138968a | 10 | from ..utils import ( |
482aa3fe | 11 | ExtractorError, |
0138968a S |
12 | int_or_none, |
13 | float_or_none, | |
d9c19db3 | 14 | parse_iso8601, |
0138968a S |
15 | ) |
16 | ||
17 | ||
18 | class VidmeIE(InfoExtractor): | |
d97b0e32 | 19 | IE_NAME = 'vidme' |
b7b36506 | 20 | _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]{,5})(?:[^\da-zA-Z]|$)' |
23dd1fc7 | 21 | _TESTS = [{ |
0138968a | 22 | 'url': 'https://vid.me/QNB', |
d65889bb | 23 | 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82', |
0138968a S |
24 | 'info_dict': { |
25 | 'id': 'QNB', | |
26 | 'ext': 'mp4', | |
27 | 'title': 'Fishing for piranha - the easy way', | |
28 | 'description': 'source: https://www.facebook.com/photo.php?v=312276045600871', | |
ec85ded8 | 29 | 'thumbnail': r're:^https?://.*\.jpg', |
0138968a S |
30 | 'timestamp': 1406313244, |
31 | 'upload_date': '20140725', | |
482aa3fe S |
32 | 'age_limit': 0, |
33 | 'duration': 119.92, | |
3b58d94f S |
34 | 'view_count': int, |
35 | 'like_count': int, | |
d9c19db3 LL |
36 | 'comment_count': int, |
37 | }, | |
38 | }, { | |
39 | 'url': 'https://vid.me/Gc6M', | |
40 | 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82', | |
41 | 'info_dict': { | |
42 | 'id': 'Gc6M', | |
43 | 'ext': 'mp4', | |
44 | 'title': 'O Mere Dil ke chain - Arnav and Khushi VM', | |
ec85ded8 | 45 | 'thumbnail': r're:^https?://.*\.jpg', |
d9c19db3 LL |
46 | 'timestamp': 1441211642, |
47 | 'upload_date': '20150902', | |
482aa3fe S |
48 | 'uploader': 'SunshineM', |
49 | 'uploader_id': '3552827', | |
50 | 'age_limit': 0, | |
51 | 'duration': 223.72, | |
d9c19db3 LL |
52 | 'view_count': int, |
53 | 'like_count': int, | |
54 | 'comment_count': int, | |
d9c19db3 LL |
55 | }, |
56 | 'params': { | |
57 | 'skip_download': True, | |
3b58d94f S |
58 | }, |
59 | }, { | |
60 | # tests uploader field | |
61 | 'url': 'https://vid.me/4Iib', | |
62 | 'info_dict': { | |
63 | 'id': '4Iib', | |
64 | 'ext': 'mp4', | |
65 | 'title': 'The Carver', | |
66 | 'description': 'md5:e9c24870018ae8113be936645b93ba3c', | |
ec85ded8 | 67 | 'thumbnail': r're:^https?://.*\.jpg', |
3b58d94f S |
68 | 'timestamp': 1433203629, |
69 | 'upload_date': '20150602', | |
70 | 'uploader': 'Thomas', | |
482aa3fe S |
71 | 'uploader_id': '109747', |
72 | 'age_limit': 0, | |
73 | 'duration': 97.859999999999999, | |
3b58d94f S |
74 | 'view_count': int, |
75 | 'like_count': int, | |
d9c19db3 | 76 | 'comment_count': int, |
3b58d94f S |
77 | }, |
78 | 'params': { | |
79 | 'skip_download': True, | |
0138968a | 80 | }, |
23dd1fc7 | 81 | }, { |
482aa3fe | 82 | # nsfw test from http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching |
23dd1fc7 | 83 | 'url': 'https://vid.me/e/Wmur', |
482aa3fe S |
84 | 'info_dict': { |
85 | 'id': 'Wmur', | |
86 | 'ext': 'mp4', | |
87 | 'title': 'naked smoking & stretching', | |
ec85ded8 | 88 | 'thumbnail': r're:^https?://.*\.jpg', |
482aa3fe S |
89 | 'timestamp': 1430931613, |
90 | 'upload_date': '20150506', | |
91 | 'uploader': 'naked-yogi', | |
92 | 'uploader_id': '1638622', | |
93 | 'age_limit': 18, | |
94 | 'duration': 653.26999999999998, | |
95 | 'view_count': int, | |
96 | 'like_count': int, | |
97 | 'comment_count': int, | |
98 | }, | |
99 | 'params': { | |
100 | 'skip_download': True, | |
101 | }, | |
9eb31b26 S |
102 | }, { |
103 | # nsfw, user-disabled | |
104 | 'url': 'https://vid.me/dzGJ', | |
105 | 'only_matching': True, | |
0be30baf LL |
106 | }, { |
107 | # suspended | |
108 | 'url': 'https://vid.me/Ox3G', | |
109 | 'only_matching': True, | |
5f9f87c0 LL |
110 | }, { |
111 | # deleted | |
112 | 'url': 'https://vid.me/KTPm', | |
113 | 'only_matching': True, | |
0be30baf LL |
114 | }, { |
115 | # no formats in the API response | |
116 | 'url': 'https://vid.me/e5g', | |
117 | 'info_dict': { | |
118 | 'id': 'e5g', | |
119 | 'ext': 'mp4', | |
4a896377 | 120 | 'title': 'Video upload (e5g)', |
ec85ded8 | 121 | 'thumbnail': r're:^https?://.*\.jpg', |
0be30baf LL |
122 | 'timestamp': 1401480195, |
123 | 'upload_date': '20140530', | |
124 | 'uploader': None, | |
125 | 'uploader_id': None, | |
126 | 'age_limit': 0, | |
127 | 'duration': 483, | |
128 | 'view_count': int, | |
129 | 'like_count': int, | |
130 | 'comment_count': int, | |
131 | }, | |
132 | 'params': { | |
133 | 'skip_download': True, | |
134 | }, | |
23dd1fc7 | 135 | }] |
0138968a S |
136 | |
137 | def _real_extract(self, url): | |
9609f02e | 138 | video_id = self._match_id(url) |
d9c19db3 | 139 | |
482aa3fe S |
140 | try: |
141 | response = self._download_json( | |
142 | 'https://api.vid.me/videoByUrl/%s' % video_id, video_id) | |
143 | except ExtractorError as e: | |
144 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400: | |
145 | response = self._parse_json(e.cause.read(), video_id) | |
146 | else: | |
147 | raise | |
d9c19db3 | 148 | |
482aa3fe S |
149 | error = response.get('error') |
150 | if error: | |
151 | raise ExtractorError( | |
152 | '%s returned error: %s' % (self.IE_NAME, error), expected=True) | |
0138968a | 153 | |
482aa3fe | 154 | video = response['video'] |
0138968a | 155 | |
5f9f87c0 LL |
156 | if video.get('state') == 'deleted': |
157 | raise ExtractorError( | |
158 | 'Vidme said: Sorry, this video has been deleted.', | |
159 | expected=True) | |
160 | ||
0be30baf | 161 | if video.get('state') in ('user-disabled', 'suspended'): |
59fe4824 LL |
162 | raise ExtractorError( |
163 | 'Vidme said: This video has been suspended either due to a copyright claim, ' | |
164 | 'or for violating the terms of use.', | |
165 | expected=True) | |
166 | ||
f31fd069 S |
167 | formats = [] |
168 | for f in video.get('formats', []): | |
169 | format_url = f.get('uri') | |
170 | if not format_url or not isinstance(format_url, compat_str): | |
171 | continue | |
172 | format_type = f.get('type') | |
173 | if format_type == 'dash': | |
174 | formats.extend(self._extract_mpd_formats( | |
175 | format_url, video_id, mpd_id='dash', fatal=False)) | |
176 | elif format_type == 'hls': | |
177 | formats.extend(self._extract_m3u8_formats( | |
178 | format_url, video_id, 'mp4', entry_protocol='m3u8_native', | |
179 | m3u8_id='hls', fatal=False)) | |
180 | else: | |
181 | formats.append({ | |
182 | 'format_id': f.get('type'), | |
183 | 'url': format_url, | |
184 | 'width': int_or_none(f.get('width')), | |
185 | 'height': int_or_none(f.get('height')), | |
186 | 'preference': 0 if f.get('type', '').endswith( | |
187 | 'clip') else 1, | |
188 | }) | |
0be30baf LL |
189 | |
190 | if not formats and video.get('complete_url'): | |
191 | formats.append({ | |
192 | 'url': video.get('complete_url'), | |
193 | 'width': int_or_none(video.get('width')), | |
194 | 'height': int_or_none(video.get('height')), | |
195 | }) | |
196 | ||
d9c19db3 | 197 | self._sort_formats(formats) |
0138968a | 198 | |
482aa3fe S |
199 | title = video['title'] |
200 | description = video.get('description') | |
201 | thumbnail = video.get('thumbnail_url') | |
202 | timestamp = parse_iso8601(video.get('date_created'), ' ') | |
203 | uploader = video.get('user', {}).get('username') | |
204 | uploader_id = video.get('user', {}).get('user_id') | |
205 | age_limit = 18 if video.get('nsfw') is True else 0 | |
206 | duration = float_or_none(video.get('duration')) | |
207 | view_count = int_or_none(video.get('view_count')) | |
208 | like_count = int_or_none(video.get('likes_count')) | |
209 | comment_count = int_or_none(video.get('comment_count')) | |
210 | ||
0138968a S |
211 | return { |
212 | 'id': video_id, | |
4a896377 | 213 | 'title': title or 'Video upload (%s)' % video_id, |
0138968a S |
214 | 'description': description, |
215 | 'thumbnail': thumbnail, | |
482aa3fe S |
216 | 'uploader': uploader, |
217 | 'uploader_id': uploader_id, | |
218 | 'age_limit': age_limit, | |
0138968a | 219 | 'timestamp': timestamp, |
0138968a S |
220 | 'duration': duration, |
221 | 'view_count': view_count, | |
222 | 'like_count': like_count, | |
d9c19db3 | 223 | 'comment_count': comment_count, |
d9c19db3 | 224 | 'formats': formats, |
0138968a | 225 | } |
b7b36506 S |
226 | |
227 | ||
eb2533ec | 228 | class VidmeListBaseIE(InfoExtractor): |
b7b36506 S |
229 | # Max possible limit according to https://docs.vid.me/#api-Videos-List |
230 | _LIMIT = 100 | |
231 | ||
232 | def _entries(self, user_id, user_name): | |
233 | for page_num in itertools.count(1): | |
234 | page = self._download_json( | |
eb2533ec S |
235 | 'https://api.vid.me/videos/%s?user=%s&limit=%d&offset=%d' |
236 | % (self._API_ITEM, user_id, self._LIMIT, (page_num - 1) * self._LIMIT), | |
237 | user_name, 'Downloading user %s page %d' % (self._API_ITEM, page_num)) | |
b7b36506 S |
238 | |
239 | videos = page.get('videos', []) | |
240 | if not videos: | |
241 | break | |
242 | ||
243 | for video in videos: | |
244 | video_url = video.get('full_url') or video.get('embed_url') | |
245 | if video_url: | |
246 | yield self.url_result(video_url, VidmeIE.ie_key()) | |
247 | ||
248 | total = int_or_none(page.get('page', {}).get('total')) | |
249 | if total and self._LIMIT * page_num >= total: | |
250 | break | |
251 | ||
252 | def _real_extract(self, url): | |
253 | user_name = self._match_id(url) | |
254 | ||
255 | user_id = self._download_json( | |
256 | 'https://api.vid.me/userByUsername?username=%s' % user_name, | |
257 | user_name)['user']['user_id'] | |
258 | ||
eb2533ec S |
259 | return self.playlist_result( |
260 | self._entries(user_id, user_name), user_id, | |
261 | '%s - %s' % (user_name, self._TITLE)) | |
262 | ||
263 | ||
264 | class VidmeUserIE(VidmeListBaseIE): | |
d97b0e32 | 265 | IE_NAME = 'vidme:user' |
eb2533ec S |
266 | _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]{6,})(?!/likes)(?:[^\da-zA-Z]|$)' |
267 | _API_ITEM = 'list' | |
268 | _TITLE = 'Videos' | |
269 | _TEST = { | |
270 | 'url': 'https://vid.me/EFARCHIVE', | |
271 | 'info_dict': { | |
272 | 'id': '3834632', | |
273 | 'title': 'EFARCHIVE - %s' % _TITLE, | |
274 | }, | |
275 | 'playlist_mincount': 238, | |
276 | } | |
277 | ||
278 | ||
279 | class VidmeUserLikesIE(VidmeListBaseIE): | |
d97b0e32 | 280 | IE_NAME = 'vidme:user:likes' |
eb2533ec S |
281 | _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]{6,})/likes' |
282 | _API_ITEM = 'likes' | |
283 | _TITLE = 'Likes' | |
284 | _TEST = { | |
285 | 'url': 'https://vid.me/ErinAlexis/likes', | |
286 | 'info_dict': { | |
287 | 'id': '6483530', | |
288 | 'title': 'ErinAlexis - %s' % _TITLE, | |
289 | }, | |
290 | 'playlist_mincount': 415, | |
291 | } |