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