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