Merge remote-tracking branch 'origin/master'
[youtube-dl] / youtube_dl / extractor / vube.py
1 from __future__ import unicode_literals
2
3 import re
4 import datetime
5
6 from .common import InfoExtractor
7
8
9 class VubeIE(InfoExtractor):
10     IE_NAME = 'vube'
11     IE_DESC = 'Vube.com'
12     _VALID_URL = r'http://vube\.com/[^/]+/(?P<id>[\da-zA-Z]{10})'
13
14     _TEST = {
15         'url': 'http://vube.com/Chiara+Grispo+Video+Channel/YL2qNPkqon',
16         'md5': 'db7aba89d4603dadd627e9d1973946fe',
17         'info_dict': {
18             'id': 'YL2qNPkqon',
19             'ext': 'mp4',
20             'title': 'Chiara Grispo - Price Tag by Jessie J',
21             'description': 'md5:8ea652a1f36818352428cb5134933313',
22             'thumbnail': 'http://frame.thestaticvube.com/snap/228x128/102e7e63057-5ebc-4f5c-4065-6ce4ebde131f.jpg',
23             'uploader': 'Chiara.Grispo',
24             'uploader_id': '1u3hX0znhP',
25             'upload_date': '20140103',
26             'duration': 170.56
27         }
28     }
29
30     def _real_extract(self, url):
31         mobj = re.match(self._VALID_URL, url)
32         video_id = mobj.group('id')
33
34         video = self._download_json('http://vube.com/api/v2/video/%s' % video_id,
35             video_id, 'Downloading video JSON')
36
37         public_id = video['public_id']
38
39         formats = [{'url': 'http://video.thestaticvube.com/video/%s/%s.mp4' % (fmt['media_resolution_id'], public_id),
40                    'height': int(fmt['height']),
41                    'abr': int(fmt['audio_bitrate']),
42                    'vbr': int(fmt['video_bitrate']),
43                    'format_id': fmt['media_resolution_id']
44                    } for fmt in video['mtm'] if fmt['transcoding_status'] == 'processed']
45
46         self._sort_formats(formats)
47
48         title = video['title']
49         description = video.get('description')
50         thumbnail = video['thumbnail_src']
51         if thumbnail.startswith('//'):
52             thumbnail = 'http:' + thumbnail
53         uploader = video['user_alias']
54         uploader_id = video['user_url_id']
55         upload_date = datetime.datetime.fromtimestamp(int(video['upload_time'])).strftime('%Y%m%d')
56         duration = video['duration']
57         view_count = video['raw_view_count']
58         like_count = video['total_likes']
59         dislike_count= video['total_hates']
60
61         comment = self._download_json('http://vube.com/api/video/%s/comment' % video_id,
62             video_id, 'Downloading video comment JSON')
63
64         comment_count = comment['total']
65
66         return {
67             'id': video_id,
68             'formats': formats,
69             'title': title,
70             'description': description,
71             'thumbnail': thumbnail,
72             'uploader': uploader,
73             'uploader_id': uploader_id,
74             'upload_date': upload_date,
75             'duration': duration,
76             'view_count': view_count,
77             'like_count': like_count,
78             'dislike_count': dislike_count,
79             'comment_count': comment_count,
80         }