[slutload] Add new extractor
[youtube-dl] / youtube_dl / extractor / vine.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
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/(?P<id>\w+)'
12     _TEST = {
13         'url': 'https://vine.co/v/b9KOOWX7HUx',
14         'md5': '2f36fed6235b16da96ce9b4dc890940d',
15         'info_dict': {
16             'id': 'b9KOOWX7HUx',
17             'ext': 'mp4',
18             'title': 'Chicken.',
19             'description': 'Chicken.',
20             'upload_date': '20130519',
21             'uploader': 'Jack Dorsey',
22             'uploader_id': '76',
23         },
24     }
25
26     def _real_extract(self, url):
27         mobj = re.match(self._VALID_URL, url)
28         video_id = mobj.group('id')
29
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             {
37                 'url': data['videoLowURL'],
38                 'ext': 'mp4',
39                 'format_id': 'low',
40             },
41             {
42                 'url': data['videoUrl'],
43                 'ext': 'mp4',
44                 'format_id': 'standard',
45             }
46         ]
47
48         return {
49             'id': video_id,
50             'title': self._og_search_title(webpage),
51             'description': data['description'],
52             'thumbnail': data['thumbnailUrl'],
53             'upload_date': unified_strdate(data['created']),
54             'uploader': data['username'],
55             'uploader_id': data['userIdStr'],
56             'like_count': data['likes']['count'],
57             'comment_count': data['comments']['count'],
58             'repost_count': data['reposts']['count'],
59             'formats': formats,
60         }