]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vine.py
Prepare for release.
[youtubedl] / youtube_dl / extractor / vine.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5 import itertools
6
7 from .common import InfoExtractor
8 from ..utils import unified_strdate
9
10
11 class VineIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?vine\.co/v/(?P<id>\w+)'
13 _TEST = {
14 'url': 'https://vine.co/v/b9KOOWX7HUx',
15 'md5': '2f36fed6235b16da96ce9b4dc890940d',
16 'info_dict': {
17 'id': 'b9KOOWX7HUx',
18 'ext': 'mp4',
19 'title': 'Chicken.',
20 'description': 'Chicken.',
21 'upload_date': '20130519',
22 'uploader': 'Jack Dorsey',
23 'uploader_id': '76',
24 },
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30
31 webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id)
32
33 data = json.loads(self._html_search_regex(
34 r'window\.POST_DATA = { %s: ({.+?}) }' % video_id, webpage, 'vine data'))
35
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 ]
48
49 return {
50 'id': video_id,
51 'title': self._og_search_title(webpage),
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,
61 }
62
63
64 class VineUserIE(InfoExtractor):
65 IE_NAME = 'vine:user'
66 _VALID_URL = r'(?:https?://)?vine\.co/(?P<user>[^/]+)/?(\?.*)?$'
67 _VINE_BASE_URL = "https://vine.co/"
68
69 def _real_extract(self, url):
70 mobj = re.match(self._VALID_URL, url)
71 user = mobj.group('user')
72
73 profile_url = "%sapi/users/profiles/vanity/%s" % (
74 self._VINE_BASE_URL, user)
75 profile_data = self._download_json(
76 profile_url, user, note='Downloading user profile data')
77
78 user_id = profile_data['data']['userId']
79 timeline_data = []
80 for pagenum in itertools.count(1):
81 timeline_url = "%sapi/timelines/users/%s?page=%s" % (
82 self._VINE_BASE_URL, user_id, pagenum)
83 timeline_page = self._download_json(
84 timeline_url, user, note='Downloading page %d' % pagenum)
85 timeline_data.extend(timeline_page['data']['records'])
86 if timeline_page['data']['nextPage'] is None:
87 break
88
89 entries = [
90 self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
91 return self.playlist_result(entries, user)