]>
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 S |
8 | from ..utils import ( |
9 | int_or_none, | |
10 | unified_strdate, | |
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.', |
f5e43bc6 | 23 | 'alt_title': 'Vine by Jack Dorsey', |
f919201e S |
24 | 'upload_date': '20130519', |
25 | 'uploader': 'Jack Dorsey', | |
26 | 'uploader_id': '76', | |
6ae938b2 | 27 | 'view_count': int, |
2e022397 S |
28 | 'like_count': int, |
29 | 'comment_count': int, | |
30 | 'repost_count': int, | |
5dc733f0 | 31 | }, |
3359fb66 S |
32 | }, { |
33 | 'url': 'https://vine.co/v/MYxVapFvz2z', | |
34 | 'md5': '7b9a7cbc76734424ff942eb52c8f1065', | |
35 | 'info_dict': { | |
36 | 'id': 'MYxVapFvz2z', | |
37 | 'ext': 'mp4', | |
38 | 'title': 'Fuck Da Police #Mikebrown #justice #ferguson #prayforferguson #protesting #NMOS14', | |
10c38c7c | 39 | 'alt_title': 'Vine by Mars Ruiz', |
3359fb66 | 40 | 'upload_date': '20140815', |
10c38c7c | 41 | 'uploader': 'Mars Ruiz', |
3359fb66 | 42 | 'uploader_id': '1102363502380728320', |
6ae938b2 | 43 | 'view_count': int, |
2e022397 S |
44 | 'like_count': int, |
45 | 'comment_count': int, | |
46 | 'repost_count': int, | |
3359fb66 S |
47 | }, |
48 | }, { | |
49 | 'url': 'https://vine.co/v/bxVjBbZlPUH', | |
50 | 'md5': 'ea27decea3fa670625aac92771a96b73', | |
51 | 'info_dict': { | |
52 | 'id': 'bxVjBbZlPUH', | |
53 | 'ext': 'mp4', | |
54 | 'title': '#mw3 #ac130 #killcam #angelofdeath', | |
55 | 'alt_title': 'Vine by Z3k3', | |
3359fb66 S |
56 | 'upload_date': '20130430', |
57 | 'uploader': 'Z3k3', | |
58 | 'uploader_id': '936470460173008896', | |
6ae938b2 | 59 | 'view_count': int, |
2e022397 S |
60 | 'like_count': int, |
61 | 'comment_count': int, | |
62 | 'repost_count': int, | |
3359fb66 | 63 | }, |
64f1aba8 S |
64 | }, { |
65 | 'url': 'https://vine.co/oembed/MYxVapFvz2z.json', | |
66 | 'only_matching': True, | |
94a773fe LL |
67 | }, { |
68 | 'url': 'https://vine.co/v/e192BnZnZ9V', | |
69 | 'info_dict': { | |
70 | 'id': 'e192BnZnZ9V', | |
71 | 'ext': 'mp4', | |
91816e8f | 72 | 'title': 'ยิ้ม~ เขิน~ อาย~ น่าร้ากอ้ะ >//< @n_whitewo @orlameena #lovesicktheseries #lovesickseason2', |
94a773fe | 73 | 'alt_title': 'Vine by Pimry_zaa', |
94a773fe LL |
74 | 'upload_date': '20150705', |
75 | 'uploader': 'Pimry_zaa', | |
76 | 'uploader_id': '1135760698325307392', | |
6ae938b2 | 77 | 'view_count': int, |
2e022397 S |
78 | 'like_count': int, |
79 | 'comment_count': int, | |
80 | 'repost_count': int, | |
94a773fe LL |
81 | }, |
82 | 'params': { | |
83 | 'skip_download': True, | |
84 | }, | |
3359fb66 | 85 | }] |
eb1634cb PH |
86 | |
87 | def _real_extract(self, url): | |
63e0f295 | 88 | video_id = self._match_id(url) |
f919201e | 89 | webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id) |
eb1634cb | 90 | |
4c4780c2 | 91 | data = self._parse_json( |
cc449417 | 92 | self._search_regex( |
564dc3c6 | 93 | r'window\.POST_DATA\s*=\s*({.+?});\s*</script>', |
4c4780c2 S |
94 | webpage, 'vine data'), |
95 | video_id) | |
ac2d8f54 | 96 | |
564dc3c6 | 97 | data = data[list(data.keys())[0]] |
0049594e | 98 | |
63e0f295 | 99 | formats = [{ |
2684871b | 100 | 'format_id': '%(format)s-%(rate)s' % f, |
91816e8f S |
101 | 'vcodec': f.get('format'), |
102 | 'quality': f.get('rate'), | |
2684871b | 103 | 'url': f['videoUrl'], |
91816e8f | 104 | } for f in data['videoUrls'] if f.get('videoUrl')] |
2684871b NJ |
105 | |
106 | self._sort_formats(formats) | |
eb1634cb | 107 | |
91816e8f S |
108 | username = data.get('username') |
109 | ||
5dc733f0 JMF |
110 | return { |
111 | 'id': video_id, | |
91816e8f S |
112 | 'title': data.get('description') or self._og_search_title(webpage), |
113 | 'alt_title': 'Vine by %s' % username if username else self._og_search_description(webpage, default=None), | |
114 | 'thumbnail': data.get('thumbnailUrl'), | |
115 | 'upload_date': unified_strdate(data.get('created')), | |
116 | 'uploader': username, | |
117 | 'uploader_id': data.get('userIdStr'), | |
6ae938b2 | 118 | 'view_count': int_or_none(data.get('loops', {}).get('count')), |
91816e8f S |
119 | 'like_count': int_or_none(data.get('likes', {}).get('count')), |
120 | 'comment_count': int_or_none(data.get('comments', {}).get('count')), | |
121 | 'repost_count': int_or_none(data.get('reposts', {}).get('count')), | |
f919201e | 122 | 'formats': formats, |
acd69589 | 123 | } |
ea783d01 | 124 | |
a172b258 | 125 | |
ea783d01 JN |
126 | class VineUserIE(InfoExtractor): |
127 | IE_NAME = 'vine:user' | |
b128c9ed | 128 | _VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$' |
611c1dd9 | 129 | _VINE_BASE_URL = 'https://vine.co/' |
b128c9ed S |
130 | _TESTS = [ |
131 | { | |
132 | 'url': 'https://vine.co/Visa', | |
133 | 'info_dict': { | |
134 | 'id': 'Visa', | |
135 | }, | |
136 | 'playlist_mincount': 46, | |
22a6f150 | 137 | }, |
b128c9ed S |
138 | { |
139 | 'url': 'https://vine.co/u/941705360593584128', | |
140 | 'only_matching': True, | |
141 | }, | |
142 | ] | |
ea783d01 | 143 | |
a172b258 PH |
144 | def _real_extract(self, url): |
145 | mobj = re.match(self._VALID_URL, url) | |
146 | user = mobj.group('user') | |
b128c9ed | 147 | u = mobj.group('u') |
ea783d01 | 148 | |
611c1dd9 | 149 | profile_url = '%sapi/users/profiles/%s%s' % ( |
b128c9ed | 150 | self._VINE_BASE_URL, 'vanity/' if not u else '', user) |
a172b258 PH |
151 | profile_data = self._download_json( |
152 | profile_url, user, note='Downloading user profile data') | |
ea783d01 | 153 | |
ea783d01 JN |
154 | user_id = profile_data['data']['userId'] |
155 | timeline_data = [] | |
156 | for pagenum in itertools.count(1): | |
611c1dd9 | 157 | timeline_url = '%sapi/timelines/users/%s?page=%s&size=100' % ( |
a172b258 PH |
158 | self._VINE_BASE_URL, user_id, pagenum) |
159 | timeline_page = self._download_json( | |
160 | timeline_url, user, note='Downloading page %d' % pagenum) | |
ea783d01 JN |
161 | timeline_data.extend(timeline_page['data']['records']) |
162 | if timeline_page['data']['nextPage'] is None: | |
163 | break | |
ea783d01 | 164 | |
a172b258 PH |
165 | entries = [ |
166 | self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data] | |
ea783d01 | 167 | return self.playlist_result(entries, user) |