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