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