]>
Commit | Line | Data |
---|---|---|
0138968a S |
1 | from __future__ import unicode_literals |
2 | ||
482aa3fe S |
3 | from .common import InfoExtractor |
4 | from ..compat import compat_HTTPError | |
0138968a | 5 | from ..utils import ( |
482aa3fe | 6 | ExtractorError, |
0138968a S |
7 | int_or_none, |
8 | float_or_none, | |
d9c19db3 | 9 | parse_iso8601, |
0138968a S |
10 | ) |
11 | ||
12 | ||
13 | class VidmeIE(InfoExtractor): | |
14 | _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]+)' | |
23dd1fc7 | 15 | _TESTS = [{ |
0138968a | 16 | 'url': 'https://vid.me/QNB', |
d65889bb | 17 | 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82', |
0138968a S |
18 | 'info_dict': { |
19 | 'id': 'QNB', | |
20 | 'ext': 'mp4', | |
21 | 'title': 'Fishing for piranha - the easy way', | |
22 | 'description': 'source: https://www.facebook.com/photo.php?v=312276045600871', | |
482aa3fe | 23 | 'thumbnail': 're:^https?://.*\.jpg', |
0138968a S |
24 | 'timestamp': 1406313244, |
25 | 'upload_date': '20140725', | |
482aa3fe S |
26 | 'age_limit': 0, |
27 | 'duration': 119.92, | |
3b58d94f S |
28 | 'view_count': int, |
29 | 'like_count': int, | |
d9c19db3 LL |
30 | 'comment_count': int, |
31 | }, | |
32 | }, { | |
33 | 'url': 'https://vid.me/Gc6M', | |
34 | 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82', | |
35 | 'info_dict': { | |
36 | 'id': 'Gc6M', | |
37 | 'ext': 'mp4', | |
38 | 'title': 'O Mere Dil ke chain - Arnav and Khushi VM', | |
482aa3fe | 39 | 'thumbnail': 're:^https?://.*\.jpg', |
d9c19db3 LL |
40 | 'timestamp': 1441211642, |
41 | 'upload_date': '20150902', | |
482aa3fe S |
42 | 'uploader': 'SunshineM', |
43 | 'uploader_id': '3552827', | |
44 | 'age_limit': 0, | |
45 | 'duration': 223.72, | |
d9c19db3 LL |
46 | 'view_count': int, |
47 | 'like_count': int, | |
48 | 'comment_count': int, | |
d9c19db3 LL |
49 | }, |
50 | 'params': { | |
51 | 'skip_download': True, | |
3b58d94f S |
52 | }, |
53 | }, { | |
54 | # tests uploader field | |
55 | 'url': 'https://vid.me/4Iib', | |
56 | 'info_dict': { | |
57 | 'id': '4Iib', | |
58 | 'ext': 'mp4', | |
59 | 'title': 'The Carver', | |
60 | 'description': 'md5:e9c24870018ae8113be936645b93ba3c', | |
482aa3fe | 61 | 'thumbnail': 're:^https?://.*\.jpg', |
3b58d94f S |
62 | 'timestamp': 1433203629, |
63 | 'upload_date': '20150602', | |
64 | 'uploader': 'Thomas', | |
482aa3fe S |
65 | 'uploader_id': '109747', |
66 | 'age_limit': 0, | |
67 | 'duration': 97.859999999999999, | |
3b58d94f S |
68 | 'view_count': int, |
69 | 'like_count': int, | |
d9c19db3 | 70 | 'comment_count': int, |
3b58d94f S |
71 | }, |
72 | 'params': { | |
73 | 'skip_download': True, | |
0138968a | 74 | }, |
23dd1fc7 | 75 | }, { |
482aa3fe | 76 | # nsfw test from http://naked-yogi.tumblr.com/post/118312946248/naked-smoking-stretching |
23dd1fc7 | 77 | 'url': 'https://vid.me/e/Wmur', |
482aa3fe S |
78 | 'info_dict': { |
79 | 'id': 'Wmur', | |
80 | 'ext': 'mp4', | |
81 | 'title': 'naked smoking & stretching', | |
82 | 'thumbnail': 're:^https?://.*\.jpg', | |
83 | 'timestamp': 1430931613, | |
84 | 'upload_date': '20150506', | |
85 | 'uploader': 'naked-yogi', | |
86 | 'uploader_id': '1638622', | |
87 | 'age_limit': 18, | |
88 | 'duration': 653.26999999999998, | |
89 | 'view_count': int, | |
90 | 'like_count': int, | |
91 | 'comment_count': int, | |
92 | }, | |
93 | 'params': { | |
94 | 'skip_download': True, | |
95 | }, | |
9eb31b26 S |
96 | }, { |
97 | # nsfw, user-disabled | |
98 | 'url': 'https://vid.me/dzGJ', | |
99 | 'only_matching': True, | |
0be30baf LL |
100 | }, { |
101 | # suspended | |
102 | 'url': 'https://vid.me/Ox3G', | |
103 | 'only_matching': True, | |
5f9f87c0 LL |
104 | }, { |
105 | # deleted | |
106 | 'url': 'https://vid.me/KTPm', | |
107 | 'only_matching': True, | |
0be30baf LL |
108 | }, { |
109 | # no formats in the API response | |
110 | 'url': 'https://vid.me/e5g', | |
111 | 'info_dict': { | |
112 | 'id': 'e5g', | |
113 | 'ext': 'mp4', | |
4a896377 | 114 | 'title': 'Video upload (e5g)', |
0be30baf LL |
115 | 'thumbnail': 're:^https?://.*\.jpg', |
116 | 'timestamp': 1401480195, | |
117 | 'upload_date': '20140530', | |
118 | 'uploader': None, | |
119 | 'uploader_id': None, | |
120 | 'age_limit': 0, | |
121 | 'duration': 483, | |
122 | 'view_count': int, | |
123 | 'like_count': int, | |
124 | 'comment_count': int, | |
125 | }, | |
126 | 'params': { | |
127 | 'skip_download': True, | |
128 | }, | |
23dd1fc7 | 129 | }] |
0138968a S |
130 | |
131 | def _real_extract(self, url): | |
9609f02e | 132 | video_id = self._match_id(url) |
d9c19db3 | 133 | |
482aa3fe S |
134 | try: |
135 | response = self._download_json( | |
136 | 'https://api.vid.me/videoByUrl/%s' % video_id, video_id) | |
137 | except ExtractorError as e: | |
138 | if isinstance(e.cause, compat_HTTPError) and e.cause.code == 400: | |
139 | response = self._parse_json(e.cause.read(), video_id) | |
140 | else: | |
141 | raise | |
d9c19db3 | 142 | |
482aa3fe S |
143 | error = response.get('error') |
144 | if error: | |
145 | raise ExtractorError( | |
146 | '%s returned error: %s' % (self.IE_NAME, error), expected=True) | |
0138968a | 147 | |
482aa3fe | 148 | video = response['video'] |
0138968a | 149 | |
5f9f87c0 LL |
150 | if video.get('state') == 'deleted': |
151 | raise ExtractorError( | |
152 | 'Vidme said: Sorry, this video has been deleted.', | |
153 | expected=True) | |
154 | ||
0be30baf | 155 | if video.get('state') in ('user-disabled', 'suspended'): |
59fe4824 LL |
156 | raise ExtractorError( |
157 | 'Vidme said: This video has been suspended either due to a copyright claim, ' | |
158 | 'or for violating the terms of use.', | |
159 | expected=True) | |
160 | ||
d9c19db3 | 161 | formats = [{ |
482aa3fe S |
162 | 'format_id': f.get('type'), |
163 | 'url': f['uri'], | |
164 | 'width': int_or_none(f.get('width')), | |
165 | 'height': int_or_none(f.get('height')), | |
05b476a2 | 166 | 'preference': 0 if f.get('type', '').endswith('clip') else 1, |
482aa3fe | 167 | } for f in video.get('formats', []) if f.get('uri')] |
0be30baf LL |
168 | |
169 | if not formats and video.get('complete_url'): | |
170 | formats.append({ | |
171 | 'url': video.get('complete_url'), | |
172 | 'width': int_or_none(video.get('width')), | |
173 | 'height': int_or_none(video.get('height')), | |
174 | }) | |
175 | ||
d9c19db3 | 176 | self._sort_formats(formats) |
0138968a | 177 | |
482aa3fe S |
178 | title = video['title'] |
179 | description = video.get('description') | |
180 | thumbnail = video.get('thumbnail_url') | |
181 | timestamp = parse_iso8601(video.get('date_created'), ' ') | |
182 | uploader = video.get('user', {}).get('username') | |
183 | uploader_id = video.get('user', {}).get('user_id') | |
184 | age_limit = 18 if video.get('nsfw') is True else 0 | |
185 | duration = float_or_none(video.get('duration')) | |
186 | view_count = int_or_none(video.get('view_count')) | |
187 | like_count = int_or_none(video.get('likes_count')) | |
188 | comment_count = int_or_none(video.get('comment_count')) | |
189 | ||
0138968a S |
190 | return { |
191 | 'id': video_id, | |
4a896377 | 192 | 'title': title or 'Video upload (%s)' % video_id, |
0138968a S |
193 | 'description': description, |
194 | 'thumbnail': thumbnail, | |
482aa3fe S |
195 | 'uploader': uploader, |
196 | 'uploader_id': uploader_id, | |
197 | 'age_limit': age_limit, | |
0138968a | 198 | 'timestamp': timestamp, |
0138968a S |
199 | 'duration': duration, |
200 | 'view_count': view_count, | |
201 | 'like_count': like_count, | |
d9c19db3 | 202 | 'comment_count': comment_count, |
d9c19db3 | 203 | 'formats': formats, |
0138968a | 204 | } |