]>
Commit | Line | Data |
---|---|---|
5dc733f0 JMF |
1 | from __future__ import unicode_literals |
2 | ||
eb1634cb | 3 | import re |
ea783d01 | 4 | import itertools |
eb1634cb PH |
5 | |
6 | from .common import InfoExtractor | |
f919201e | 7 | from ..utils import unified_strdate |
eb1634cb PH |
8 | |
9 | ||
10 | class VineIE(InfoExtractor): | |
64f1aba8 | 11 | _VALID_URL = r'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)' |
3359fb66 | 12 | _TESTS = [{ |
5dc733f0 JMF |
13 | 'url': 'https://vine.co/v/b9KOOWX7HUx', |
14 | 'md5': '2f36fed6235b16da96ce9b4dc890940d', | |
15 | 'info_dict': { | |
16 | 'id': 'b9KOOWX7HUx', | |
17 | 'ext': 'mp4', | |
5dc733f0 | 18 | 'title': 'Chicken.', |
f5e43bc6 | 19 | 'alt_title': 'Vine by Jack Dorsey', |
f919201e S |
20 | 'description': 'Chicken.', |
21 | 'upload_date': '20130519', | |
22 | 'uploader': 'Jack Dorsey', | |
23 | 'uploader_id': '76', | |
5dc733f0 | 24 | }, |
3359fb66 S |
25 | }, { |
26 | 'url': 'https://vine.co/v/MYxVapFvz2z', | |
27 | 'md5': '7b9a7cbc76734424ff942eb52c8f1065', | |
28 | 'info_dict': { | |
29 | 'id': 'MYxVapFvz2z', | |
30 | 'ext': 'mp4', | |
31 | 'title': 'Fuck Da Police #Mikebrown #justice #ferguson #prayforferguson #protesting #NMOS14', | |
32 | 'alt_title': 'Vine by Luna', | |
33 | 'description': 'Fuck Da Police #Mikebrown #justice #ferguson #prayforferguson #protesting #NMOS14', | |
34 | 'upload_date': '20140815', | |
35 | 'uploader': 'Luna', | |
36 | 'uploader_id': '1102363502380728320', | |
37 | }, | |
38 | }, { | |
39 | 'url': 'https://vine.co/v/bxVjBbZlPUH', | |
40 | 'md5': 'ea27decea3fa670625aac92771a96b73', | |
41 | 'info_dict': { | |
42 | 'id': 'bxVjBbZlPUH', | |
43 | 'ext': 'mp4', | |
44 | 'title': '#mw3 #ac130 #killcam #angelofdeath', | |
45 | 'alt_title': 'Vine by Z3k3', | |
46 | 'description': '#mw3 #ac130 #killcam #angelofdeath', | |
47 | 'upload_date': '20130430', | |
48 | 'uploader': 'Z3k3', | |
49 | 'uploader_id': '936470460173008896', | |
50 | }, | |
64f1aba8 S |
51 | }, { |
52 | 'url': 'https://vine.co/oembed/MYxVapFvz2z.json', | |
53 | 'only_matching': True, | |
3359fb66 | 54 | }] |
eb1634cb PH |
55 | |
56 | def _real_extract(self, url): | |
63e0f295 | 57 | video_id = self._match_id(url) |
f919201e | 58 | webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id) |
eb1634cb | 59 | |
4c4780c2 S |
60 | data = self._parse_json( |
61 | self._html_search_regex( | |
62 | r'window\.POST_DATA = { %s: ({.+?}) };\s*</script>' % video_id, | |
63 | webpage, 'vine data'), | |
64 | video_id) | |
0049594e | 65 | |
63e0f295 | 66 | formats = [{ |
2684871b NJ |
67 | 'format_id': '%(format)s-%(rate)s' % f, |
68 | 'vcodec': f['format'], | |
69 | 'quality': f['rate'], | |
70 | 'url': f['videoUrl'], | |
6ac41a4e | 71 | } for f in data['videoUrls']] |
2684871b NJ |
72 | |
73 | self._sort_formats(formats) | |
eb1634cb | 74 | |
5dc733f0 JMF |
75 | return { |
76 | 'id': video_id, | |
5dc733f0 | 77 | 'title': self._og_search_title(webpage), |
d4b963d0 | 78 | 'alt_title': self._og_search_description(webpage, default=None), |
f919201e S |
79 | 'description': data['description'], |
80 | 'thumbnail': data['thumbnailUrl'], | |
81 | 'upload_date': unified_strdate(data['created']), | |
82 | 'uploader': data['username'], | |
83 | 'uploader_id': data['userIdStr'], | |
84 | 'like_count': data['likes']['count'], | |
85 | 'comment_count': data['comments']['count'], | |
86 | 'repost_count': data['reposts']['count'], | |
87 | 'formats': formats, | |
acd69589 | 88 | } |
ea783d01 | 89 | |
a172b258 | 90 | |
ea783d01 JN |
91 | class VineUserIE(InfoExtractor): |
92 | IE_NAME = 'vine:user' | |
b128c9ed | 93 | _VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$' |
ea783d01 | 94 | _VINE_BASE_URL = "https://vine.co/" |
b128c9ed S |
95 | _TESTS = [ |
96 | { | |
97 | 'url': 'https://vine.co/Visa', | |
98 | 'info_dict': { | |
99 | 'id': 'Visa', | |
100 | }, | |
101 | 'playlist_mincount': 46, | |
22a6f150 | 102 | }, |
b128c9ed S |
103 | { |
104 | 'url': 'https://vine.co/u/941705360593584128', | |
105 | 'only_matching': True, | |
106 | }, | |
107 | ] | |
ea783d01 | 108 | |
a172b258 PH |
109 | def _real_extract(self, url): |
110 | mobj = re.match(self._VALID_URL, url) | |
111 | user = mobj.group('user') | |
b128c9ed | 112 | u = mobj.group('u') |
ea783d01 | 113 | |
b128c9ed S |
114 | profile_url = "%sapi/users/profiles/%s%s" % ( |
115 | self._VINE_BASE_URL, 'vanity/' if not u else '', user) | |
a172b258 PH |
116 | profile_data = self._download_json( |
117 | profile_url, user, note='Downloading user profile data') | |
ea783d01 | 118 | |
ea783d01 JN |
119 | user_id = profile_data['data']['userId'] |
120 | timeline_data = [] | |
121 | for pagenum in itertools.count(1): | |
b128c9ed | 122 | timeline_url = "%sapi/timelines/users/%s?page=%s&size=100" % ( |
a172b258 PH |
123 | self._VINE_BASE_URL, user_id, pagenum) |
124 | timeline_page = self._download_json( | |
125 | timeline_url, user, note='Downloading page %d' % pagenum) | |
ea783d01 JN |
126 | timeline_data.extend(timeline_page['data']['records']) |
127 | if timeline_page['data']['nextPage'] is None: | |
128 | break | |
ea783d01 | 129 | |
a172b258 PH |
130 | entries = [ |
131 | self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data] | |
ea783d01 | 132 | return self.playlist_result(entries, user) |