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