]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vine.py
Merge remote-tracking branch 'jnormore/vine_user'
[yt-dlp.git] / youtube_dl / extractor / vine.py
CommitLineData
5dc733f0
JMF
1from __future__ import unicode_literals
2
eb1634cb 3import re
f919201e 4import json
ea783d01 5import itertools
eb1634cb
PH
6
7from .common import InfoExtractor
f919201e 8from ..utils import unified_strdate
eb1634cb
PH
9
10
11class VineIE(InfoExtractor):
5dc733f0 12 _VALID_URL = r'https?://(?:www\.)?vine\.co/v/(?P<id>\w+)'
6f5ac90c 13 _TEST = {
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.',
f919201e
S
20 'description': 'Chicken.',
21 'upload_date': '20130519',
22 'uploader': 'Jack Dorsey',
23 'uploader_id': '76',
5dc733f0 24 },
6f5ac90c 25 }
eb1634cb
PH
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
eb1634cb 29 video_id = mobj.group('id')
eb1634cb 30
f919201e 31 webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id)
eb1634cb 32
f919201e
S
33 data = json.loads(self._html_search_regex(
34 r'window\.POST_DATA = { %s: ({.+?}) }' % video_id, webpage, 'vine data'))
0049594e 35
f919201e
S
36 formats = [
37 {
38 'url': data['videoLowURL'],
39 'ext': 'mp4',
40 'format_id': 'low',
41 },
42 {
43 'url': data['videoUrl'],
44 'ext': 'mp4',
45 'format_id': 'standard',
46 }
47 ]
eb1634cb 48
5dc733f0
JMF
49 return {
50 'id': video_id,
5dc733f0 51 'title': self._og_search_title(webpage),
f919201e
S
52 'description': data['description'],
53 'thumbnail': data['thumbnailUrl'],
54 'upload_date': unified_strdate(data['created']),
55 'uploader': data['username'],
56 'uploader_id': data['userIdStr'],
57 'like_count': data['likes']['count'],
58 'comment_count': data['comments']['count'],
59 'repost_count': data['reposts']['count'],
60 'formats': formats,
acd69589 61 }
ea783d01
JN
62
63class VineUserIE(InfoExtractor):
64 IE_NAME = 'vine:user'
65 _VALID_URL = r'(?:https?://)?vine\.co/(?P<user>[^/]+)/?(\?.*)?$'
66 _VINE_BASE_URL = "https://vine.co/"
67
68 def _profile_url(self, user):
69 return "%sapi/users/profiles/vanity/%s"%(self._VINE_BASE_URL, user)
70
71 def _timeline_url(self, user_id, page=1):
72 return "%sapi/timelines/users/%s?page=%s"%(self._VINE_BASE_URL, user_id, page)
73
74 def _profile_data(self, user):
75 return self._download_json(self._profile_url(user), user)
76
77 def _timeline_data(self, user):
78 profile_data = self._profile_data(user)
79 user_id = profile_data['data']['userId']
80 timeline_data = []
81 for pagenum in itertools.count(1):
82 timeline_page = self._download_json(self._timeline_url(user_id, pagenum), user)
83 timeline_data.extend(timeline_page['data']['records'])
84 if timeline_page['data']['nextPage'] is None:
85 break
86 return timeline_data
87
88 def _extract_videos(self, user):
89 timeline_data = self._timeline_data(user)
90 entries = [self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
91 return self.playlist_result(entries, user)
92
93 def _real_extract(self, url):
94 mobj = re.match(self._VALID_URL, url)
95 user = mobj.group('user')
96 return self._extract_videos(user)