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