[vube] Improve URL detection and extract timestamp
[youtube-dl] / youtube_dl / extractor / vube.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6
7
8 class VubeIE(InfoExtractor):
9     IE_NAME = 'vube'
10     IE_DESC = 'Vube.com'
11     _VALID_URL = r'http://vube\.com/(?:[^/]+/)+(?P<id>[\da-zA-Z]{10})\b'
12
13     _TESTS = [
14         {
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                 'timestamp': 1388743358,
26                 'upload_date': '20140103',
27                 'duration': 170.56
28             }
29         },
30         {
31             'url': 'http://vube.com/SerainaMusic/my-7-year-old-sister-and-i-singing-alive-by-krewella/UeBhTudbfS?t=s&n=1',
32             'md5': '5d4a52492d76f72712117ce6b0d98d08',
33             'info_dict': {
34                 'id': 'UeBhTudbfS',
35                 'ext': 'mp4',
36                 'title': 'My 7 year old Sister and I singing "Alive" by Krewella',
37                 'description': 'md5:40bcacb97796339f1690642c21d56f4a',
38                 'thumbnail': 'http://frame.thestaticvube.com/snap/228x128/102265d5a9f-0f17-4f6b-5753-adf08484ee1e.jpg',
39                 'uploader': 'Seraina',
40                 'uploader_id': 'XU9VE2BQ2q',
41                 'timestamp': 1396492438,
42                 'upload_date': '20140403',
43                 'duration': 240.107
44             }
45         }
46     ]
47
48     def _real_extract(self, url):
49         mobj = re.match(self._VALID_URL, url)
50         video_id = mobj.group('id')
51
52         video = self._download_json('http://vube.com/api/v2/video/%s' % video_id,
53             video_id, 'Downloading video JSON')
54
55         public_id = video['public_id']
56
57         formats = [{'url': 'http://video.thestaticvube.com/video/%s/%s.mp4' % (fmt['media_resolution_id'], public_id),
58                    'height': int(fmt['height']),
59                    'abr': int(fmt['audio_bitrate']),
60                    'vbr': int(fmt['video_bitrate']),
61                    'format_id': fmt['media_resolution_id']
62                    } for fmt in video['mtm'] if fmt['transcoding_status'] == 'processed']
63
64         self._sort_formats(formats)
65
66         title = video['title']
67         description = video.get('description')
68         thumbnail = video['thumbnail_src']
69         if thumbnail.startswith('//'):
70             thumbnail = 'http:' + thumbnail
71         uploader = video['user_alias']
72         uploader_id = video['user_url_id']
73         timestamp = int(video['upload_time'])
74         duration = video['duration']
75         view_count = video['raw_view_count']
76         like_count = video['total_likes']
77         dislike_count= video['total_hates']
78
79         comment = self._download_json('http://vube.com/api/video/%s/comment' % video_id,
80             video_id, 'Downloading video comment JSON')
81
82         comment_count = comment['total']
83
84         return {
85             'id': video_id,
86             'formats': formats,
87             'title': title,
88             'description': description,
89             'thumbnail': thumbnail,
90             'uploader': uploader,
91             'uploader_id': uploader_id,
92             'timestamp': timestamp,
93             'duration': duration,
94             'view_count': view_count,
95             'like_count': like_count,
96             'dislike_count': dislike_count,
97             'comment_count': comment_count,
98         }