1 from __future__ import unicode_literals
5 from .common import InfoExtractor
18 class VidmeIE(InfoExtractor):
20 _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]{,5})(?:[^\da-zA-Z]|$)'
22 'url': 'https://vid.me/QNB',
23 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82',
27 'title': 'Fishing for piranha - the easy way',
28 'description': 'source: https://www.facebook.com/photo.php?v=312276045600871',
29 'thumbnail': r're:^https?://.*\.jpg',
30 'timestamp': 1406313244,
31 'upload_date': '20140725',
39 'url': 'https://vid.me/Gc6M',
40 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82',
44 'title': 'O Mere Dil ke chain - Arnav and Khushi VM',
45 'thumbnail': r're:^https?://.*\.jpg',
46 'timestamp': 1441211642,
47 'upload_date': '20150902',
48 'uploader': 'SunshineM',
49 'uploader_id': '3552827',
57 'skip_download': True,
60 # tests uploader field
61 'url': 'https://vid.me/4Iib',
65 'title': 'The Carver',
66 'description': 'md5:e9c24870018ae8113be936645b93ba3c',
67 'thumbnail': r're:^https?://.*\.jpg',
68 'timestamp': 1433203629,
69 'upload_date': '20150602',
71 'uploader_id': '109747',
73 'duration': 97.859999999999999,
79 'skip_download': True,
82 # nsfw test from http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching
83 'url': 'https://vid.me/e/Wmur',
87 'title': 'naked smoking & stretching',
88 'thumbnail': r're:^https?://.*\.jpg',
89 'timestamp': 1430931613,
90 'upload_date': '20150506',
91 'uploader': 'naked-yogi',
92 'uploader_id': '1638622',
94 'duration': 653.26999999999998,
100 'skip_download': True,
103 # nsfw, user-disabled
104 'url': 'https://vid.me/dzGJ',
105 'only_matching': True,
108 'url': 'https://vid.me/Ox3G',
109 'only_matching': True,
112 'url': 'https://vid.me/KTPm',
113 'only_matching': True,
115 # no formats in the API response
116 'url': 'https://vid.me/e5g',
120 'title': 'Video upload (e5g)',
121 'thumbnail': r're:^https?://.*\.jpg',
122 'timestamp': 1401480195,
123 'upload_date': '20140530',
130 'comment_count': int,
133 'skip_download': True,
137 def _real_extract(self, url):
138 video_id = self._match_id(url)
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)
149 error = response.get('error')
151 raise ExtractorError(
152 '%s returned error: %s' % (self.IE_NAME, error), expected=True)
154 video = response['video']
156 if video.get('state') == 'deleted':
157 raise ExtractorError(
158 'Vidme said: Sorry, this video has been deleted.',
161 if video.get('state') in ('user-disabled', 'suspended'):
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.',
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):
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))
182 'format_id': f.get('type'),
184 'width': int_or_none(f.get('width')),
185 'height': int_or_none(f.get('height')),
186 'preference': 0 if f.get('type', '').endswith(
190 if not formats and video.get('complete_url'):
192 'url': video.get('complete_url'),
193 'width': int_or_none(video.get('width')),
194 'height': int_or_none(video.get('height')),
197 self._sort_formats(formats)
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'))
213 'title': title or 'Video upload (%s)' % video_id,
214 'description': description,
215 'thumbnail': thumbnail,
216 'uploader': uploader,
217 'uploader_id': uploader_id,
218 'age_limit': age_limit,
219 'timestamp': timestamp,
220 'duration': duration,
221 'view_count': view_count,
222 'like_count': like_count,
223 'comment_count': comment_count,
228 class VidmeListBaseIE(InfoExtractor):
229 # Max possible limit according to https://docs.vid.me/#api-Videos-List
232 def _entries(self, user_id, user_name):
233 for page_num in itertools.count(1):
234 page = self._download_json(
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))
239 videos = page.get('videos', [])
244 video_url = video.get('full_url') or video.get('embed_url')
246 yield self.url_result(video_url, VidmeIE.ie_key())
248 total = int_or_none(page.get('page', {}).get('total'))
249 if total and self._LIMIT * page_num >= total:
252 def _real_extract(self, url):
253 user_name = self._match_id(url)
255 user_id = self._download_json(
256 'https://api.vid.me/userByUsername?username=%s' % user_name,
257 user_name)['user']['user_id']
259 return self.playlist_result(
260 self._entries(user_id, user_name), user_id,
261 '%s - %s' % (user_name, self._TITLE))
264 class VidmeUserIE(VidmeListBaseIE):
265 IE_NAME = 'vidme:user'
266 _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z_-]{6,})(?!/likes)(?:[^\da-zA-Z_-]|$)'
270 'url': 'https://vid.me/MasakoX',
273 'title': 'MasakoX - %s' % _TITLE,
275 'playlist_mincount': 191,
277 'url': 'https://vid.me/unsQuare_netWork',
278 'only_matching': True,
282 class VidmeUserLikesIE(VidmeListBaseIE):
283 IE_NAME = 'vidme:user:likes'
284 _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z_-]{6,})/likes'
288 'url': 'https://vid.me/ErinAlexis/likes',
291 'title': 'ErinAlexis - %s' % _TITLE,
293 'playlist_mincount': 415,
295 'url': 'https://vid.me/Kaleidoscope-Ish/likes',
296 'only_matching': True,