]>
Commit | Line | Data |
---|---|---|
91816e8f | 1 | # coding: utf-8 |
5dc733f0 JMF |
2 | from __future__ import unicode_literals |
3 | ||
eb1634cb PH |
4 | |
5 | from .common import InfoExtractor | |
8e41c9ad | 6 | from ..compat import compat_str |
91816e8f | 7 | from ..utils import ( |
f962790e | 8 | determine_ext, |
91816e8f | 9 | int_or_none, |
f962790e | 10 | unified_timestamp, |
91816e8f | 11 | ) |
eb1634cb PH |
12 | |
13 | ||
14 | class VineIE(InfoExtractor): | |
64f1aba8 | 15 | _VALID_URL = r'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)' |
3359fb66 | 16 | _TESTS = [{ |
5dc733f0 JMF |
17 | 'url': 'https://vine.co/v/b9KOOWX7HUx', |
18 | 'md5': '2f36fed6235b16da96ce9b4dc890940d', | |
19 | 'info_dict': { | |
20 | 'id': 'b9KOOWX7HUx', | |
21 | 'ext': 'mp4', | |
5dc733f0 | 22 | 'title': 'Chicken.', |
f962790e S |
23 | 'alt_title': 'Vine by Jack', |
24 | 'timestamp': 1368997951, | |
f919201e | 25 | 'upload_date': '20130519', |
f962790e | 26 | 'uploader': 'Jack', |
f919201e | 27 | 'uploader_id': '76', |
6ae938b2 | 28 | 'view_count': int, |
2e022397 S |
29 | 'like_count': int, |
30 | 'comment_count': int, | |
31 | 'repost_count': int, | |
5dc733f0 | 32 | }, |
94a773fe LL |
33 | }, { |
34 | 'url': 'https://vine.co/v/e192BnZnZ9V', | |
35 | 'info_dict': { | |
36 | 'id': 'e192BnZnZ9V', | |
37 | 'ext': 'mp4', | |
91816e8f | 38 | 'title': 'ยิ้ม~ เขิน~ อาย~ น่าร้ากอ้ะ >//< @n_whitewo @orlameena #lovesicktheseries #lovesickseason2', |
94a773fe | 39 | 'alt_title': 'Vine by Pimry_zaa', |
f962790e | 40 | 'timestamp': 1436057405, |
94a773fe LL |
41 | 'upload_date': '20150705', |
42 | 'uploader': 'Pimry_zaa', | |
43 | 'uploader_id': '1135760698325307392', | |
6ae938b2 | 44 | 'view_count': int, |
2e022397 S |
45 | 'like_count': int, |
46 | 'comment_count': int, | |
47 | 'repost_count': int, | |
94a773fe LL |
48 | }, |
49 | 'params': { | |
50 | 'skip_download': True, | |
51 | }, | |
f962790e S |
52 | }, { |
53 | 'url': 'https://vine.co/v/MYxVapFvz2z', | |
54 | 'only_matching': True, | |
55 | }, { | |
56 | 'url': 'https://vine.co/v/bxVjBbZlPUH', | |
57 | 'only_matching': True, | |
58 | }, { | |
59 | 'url': 'https://vine.co/oembed/MYxVapFvz2z.json', | |
60 | 'only_matching': True, | |
3359fb66 | 61 | }] |
eb1634cb PH |
62 | |
63 | def _real_extract(self, url): | |
63e0f295 | 64 | video_id = self._match_id(url) |
ac2d8f54 | 65 | |
f962790e S |
66 | data = self._download_json( |
67 | 'https://archive.vine.co/posts/%s.json' % video_id, video_id) | |
0049594e | 68 | |
f962790e S |
69 | def video_url(kind): |
70 | for url_suffix in ('Url', 'URL'): | |
71 | format_url = data.get('video%s%s' % (kind, url_suffix)) | |
72 | if format_url: | |
73 | return format_url | |
2684871b | 74 | |
f962790e S |
75 | formats = [] |
76 | for quality, format_id in enumerate(('low', '', 'dash')): | |
77 | format_url = video_url(format_id.capitalize()) | |
78 | if not format_url: | |
79 | continue | |
80 | # DASH link returns plain mp4 | |
81 | if format_id == 'dash' and determine_ext(format_url) == 'mpd': | |
82 | formats.extend(self._extract_mpd_formats( | |
83 | format_url, video_id, mpd_id='dash', fatal=False)) | |
84 | else: | |
85 | formats.append({ | |
86 | 'url': format_url, | |
87 | 'format_id': format_id or 'standard', | |
88 | 'quality': quality, | |
89 | }) | |
8e6cc12c | 90 | self._check_formats(formats, video_id) |
2684871b | 91 | self._sort_formats(formats) |
eb1634cb | 92 | |
91816e8f S |
93 | username = data.get('username') |
94 | ||
e8f20ffa YCH |
95 | alt_title = 'Vine by %s' % username if username else None |
96 | ||
5dc733f0 JMF |
97 | return { |
98 | 'id': video_id, | |
e8f20ffa YCH |
99 | 'title': data.get('description') or alt_title or 'Vine video', |
100 | 'alt_title': alt_title, | |
91816e8f | 101 | 'thumbnail': data.get('thumbnailUrl'), |
f962790e | 102 | 'timestamp': unified_timestamp(data.get('created')), |
91816e8f S |
103 | 'uploader': username, |
104 | 'uploader_id': data.get('userIdStr'), | |
f962790e S |
105 | 'view_count': int_or_none(data.get('loops')), |
106 | 'like_count': int_or_none(data.get('likes')), | |
107 | 'comment_count': int_or_none(data.get('comments')), | |
108 | 'repost_count': int_or_none(data.get('reposts')), | |
f919201e | 109 | 'formats': formats, |
acd69589 | 110 | } |
ea783d01 | 111 | |
a172b258 | 112 | |
ea783d01 JN |
113 | class VineUserIE(InfoExtractor): |
114 | IE_NAME = 'vine:user' | |
8e41c9ad | 115 | _VALID_URL = r'https?://vine\.co/(?P<u>u/)?(?P<user>[^/]+)' |
611c1dd9 | 116 | _VINE_BASE_URL = 'https://vine.co/' |
8e41c9ad S |
117 | _TESTS = [{ |
118 | 'url': 'https://vine.co/itsruthb', | |
119 | 'info_dict': { | |
120 | 'id': 'itsruthb', | |
121 | 'title': 'Ruth B', | |
122 | 'description': '| Instagram/Twitter: itsruthb | still a lost boy from neverland', | |
b128c9ed | 123 | }, |
8e41c9ad S |
124 | 'playlist_mincount': 611, |
125 | }, { | |
126 | 'url': 'https://vine.co/u/942914934646415360', | |
127 | 'only_matching': True, | |
128 | }] | |
129 | ||
130 | @classmethod | |
131 | def suitable(cls, url): | |
132 | return False if VineIE.suitable(url) else super(VineUserIE, cls).suitable(url) | |
ea783d01 | 133 | |
a172b258 | 134 | def _real_extract(self, url): |
5ad28e7f | 135 | mobj = self._match_valid_url(url) |
a172b258 | 136 | user = mobj.group('user') |
b128c9ed | 137 | u = mobj.group('u') |
ea783d01 | 138 | |
611c1dd9 | 139 | profile_url = '%sapi/users/profiles/%s%s' % ( |
b128c9ed | 140 | self._VINE_BASE_URL, 'vanity/' if not u else '', user) |
a172b258 PH |
141 | profile_data = self._download_json( |
142 | profile_url, user, note='Downloading user profile data') | |
ea783d01 | 143 | |
8e41c9ad S |
144 | data = profile_data['data'] |
145 | user_id = data.get('userId') or data['userIdStr'] | |
146 | profile = self._download_json( | |
9b5aead6 | 147 | 'https://archive.vine.co/profiles/%s.json' % user_id, user_id) |
a172b258 | 148 | entries = [ |
8e41c9ad S |
149 | self.url_result( |
150 | 'https://vine.co/v/%s' % post_id, ie='Vine', video_id=post_id) | |
151 | for post_id in profile['posts'] | |
152 | if post_id and isinstance(post_id, compat_str)] | |
153 | return self.playlist_result( | |
154 | entries, user, profile.get('username'), profile.get('description')) |