]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vine.py
d/control: Add build-dependency on dh-python as per warning from dh_python2.
[youtubedl] / youtube_dl / extractor / vine.py
1 from __future__ import unicode_literals
2
3 import re
4 import itertools
5
6 from .common import InfoExtractor
7 from ..utils import unified_strdate
8
9
10 class VineIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?vine\.co/(?:v|oembed)/(?P<id>\w+)'
12 _TESTS = [{
13 'url': 'https://vine.co/v/b9KOOWX7HUx',
14 'md5': '2f36fed6235b16da96ce9b4dc890940d',
15 'info_dict': {
16 'id': 'b9KOOWX7HUx',
17 'ext': 'mp4',
18 'title': 'Chicken.',
19 'alt_title': 'Vine by Jack Dorsey',
20 'description': 'Chicken.',
21 'upload_date': '20130519',
22 'uploader': 'Jack Dorsey',
23 'uploader_id': '76',
24 },
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 },
51 }, {
52 'url': 'https://vine.co/oembed/MYxVapFvz2z.json',
53 'only_matching': True,
54 }]
55
56 def _real_extract(self, url):
57 video_id = self._match_id(url)
58 webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id)
59
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)
65
66 formats = [{
67 'format_id': '%(format)s-%(rate)s' % f,
68 'vcodec': f['format'],
69 'quality': f['rate'],
70 'url': f['videoUrl'],
71 } for f in data['videoUrls']]
72
73 self._sort_formats(formats)
74
75 return {
76 'id': video_id,
77 'title': self._og_search_title(webpage),
78 'alt_title': self._og_search_description(webpage, default=None),
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,
88 }
89
90
91 class VineUserIE(InfoExtractor):
92 IE_NAME = 'vine:user'
93 _VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$'
94 _VINE_BASE_URL = "https://vine.co/"
95 _TESTS = [
96 {
97 'url': 'https://vine.co/Visa',
98 'info_dict': {
99 'id': 'Visa',
100 },
101 'playlist_mincount': 46,
102 },
103 {
104 'url': 'https://vine.co/u/941705360593584128',
105 'only_matching': True,
106 },
107 ]
108
109 def _real_extract(self, url):
110 mobj = re.match(self._VALID_URL, url)
111 user = mobj.group('user')
112 u = mobj.group('u')
113
114 profile_url = "%sapi/users/profiles/%s%s" % (
115 self._VINE_BASE_URL, 'vanity/' if not u else '', user)
116 profile_data = self._download_json(
117 profile_url, user, note='Downloading user profile data')
118
119 user_id = profile_data['data']['userId']
120 timeline_data = []
121 for pagenum in itertools.count(1):
122 timeline_url = "%sapi/timelines/users/%s?page=%s&size=100" % (
123 self._VINE_BASE_URL, user_id, pagenum)
124 timeline_page = self._download_json(
125 timeline_url, user, note='Downloading page %d' % pagenum)
126 timeline_data.extend(timeline_page['data']['records'])
127 if timeline_page['data']['nextPage'] is None:
128 break
129
130 entries = [
131 self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
132 return self.playlist_result(entries, user)