]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vine.py
Imported Upstream version 2015.01.16
[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 'alt_title': 'Vine by Jack Dorsey',
21 'description': 'Chicken.',
22 'upload_date': '20130519',
23 'uploader': 'Jack Dorsey',
24 'uploader_id': '76',
25 },
26 }
27
28 def _real_extract(self, url):
29 video_id = self._match_id(url)
30 webpage = self._download_webpage('https://vine.co/v/' + video_id, video_id)
31
32 data = json.loads(self._html_search_regex(
33 r'window\.POST_DATA = { %s: ({.+?}) }' % video_id, webpage, 'vine data'))
34
35 formats = [{
36 'url': data['videoLowURL'],
37 'ext': 'mp4',
38 'format_id': 'low',
39 }, {
40 'url': data['videoUrl'],
41 'ext': 'mp4',
42 'format_id': 'standard',
43 }]
44
45 return {
46 'id': video_id,
47 'title': self._og_search_title(webpage),
48 'alt_title': self._og_search_description(webpage),
49 'description': data['description'],
50 'thumbnail': data['thumbnailUrl'],
51 'upload_date': unified_strdate(data['created']),
52 'uploader': data['username'],
53 'uploader_id': data['userIdStr'],
54 'like_count': data['likes']['count'],
55 'comment_count': data['comments']['count'],
56 'repost_count': data['reposts']['count'],
57 'formats': formats,
58 }
59
60
61 class VineUserIE(InfoExtractor):
62 IE_NAME = 'vine:user'
63 _VALID_URL = r'(?:https?://)?vine\.co/(?P<u>u/)?(?P<user>[^/]+)/?(\?.*)?$'
64 _VINE_BASE_URL = "https://vine.co/"
65 _TESTS = [
66 {
67 'url': 'https://vine.co/Visa',
68 'info_dict': {
69 'id': 'Visa',
70 },
71 'playlist_mincount': 46,
72 },
73 {
74 'url': 'https://vine.co/u/941705360593584128',
75 'only_matching': True,
76 },
77 ]
78
79 def _real_extract(self, url):
80 mobj = re.match(self._VALID_URL, url)
81 user = mobj.group('user')
82 u = mobj.group('u')
83
84 profile_url = "%sapi/users/profiles/%s%s" % (
85 self._VINE_BASE_URL, 'vanity/' if not u else '', user)
86 profile_data = self._download_json(
87 profile_url, user, note='Downloading user profile data')
88
89 user_id = profile_data['data']['userId']
90 timeline_data = []
91 for pagenum in itertools.count(1):
92 timeline_url = "%sapi/timelines/users/%s?page=%s&size=100" % (
93 self._VINE_BASE_URL, user_id, pagenum)
94 timeline_page = self._download_json(
95 timeline_url, user, note='Downloading page %d' % pagenum)
96 timeline_data.extend(timeline_page['data']['records'])
97 if timeline_page['data']['nextPage'] is None:
98 break
99
100 entries = [
101 self.url_result(e['permalinkUrl'], 'Vine') for e in timeline_data]
102 return self.playlist_result(entries, user)