]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vube.py
Imported Upstream version 2014.11.21
[youtubedl] / youtube_dl / extractor / vube.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 int_or_none,
8 compat_str,
9 ExtractorError,
10 )
11
12
13 class VubeIE(InfoExtractor):
14 IE_NAME = 'vube'
15 IE_DESC = 'Vube.com'
16 _VALID_URL = r'http://vube\.com/(?:[^/]+/)+(?P<id>[\da-zA-Z]{10})\b'
17
18 _TESTS = [
19 {
20 'url': 'http://vube.com/trending/William+Wei/Y8NUZ69Tf7?t=s',
21 'md5': 'e7aabe1f8f1aa826b9e4735e1f9cee42',
22 'info_dict': {
23 'id': 'Y8NUZ69Tf7',
24 'ext': 'mp4',
25 'title': 'Best Drummer Ever [HD]',
26 'description': 'md5:2d63c4b277b85c2277761c2cf7337d71',
27 'thumbnail': 're:^https?://.*\.jpg',
28 'uploader': 'William',
29 'timestamp': 1406876915,
30 'upload_date': '20140801',
31 'duration': 258.051,
32 'like_count': int,
33 'dislike_count': int,
34 'comment_count': int,
35 'categories': ['amazing', 'hd', 'best drummer ever', 'william wei', 'bucket drumming', 'street drummer', 'epic street drumming'],
36 },
37 }, {
38 'url': 'http://vube.com/Chiara+Grispo+Video+Channel/YL2qNPkqon',
39 'md5': 'db7aba89d4603dadd627e9d1973946fe',
40 'info_dict': {
41 'id': 'YL2qNPkqon',
42 'ext': 'mp4',
43 'title': 'Chiara Grispo - Price Tag by Jessie J',
44 'description': 'md5:8ea652a1f36818352428cb5134933313',
45 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/102e7e63057-5ebc-4f5c-4065-6ce4ebde131f\.jpg$',
46 'uploader': 'Chiara.Grispo',
47 'timestamp': 1388743358,
48 'upload_date': '20140103',
49 'duration': 170.56,
50 'like_count': int,
51 'dislike_count': int,
52 'comment_count': int,
53 'categories': ['pop', 'music', 'cover', 'singing', 'jessie j', 'price tag', 'chiara grispo'],
54 },
55 'skip': 'Removed due to DMCA',
56 },
57 {
58 'url': 'http://vube.com/SerainaMusic/my-7-year-old-sister-and-i-singing-alive-by-krewella/UeBhTudbfS?t=s&n=1',
59 'md5': '5d4a52492d76f72712117ce6b0d98d08',
60 'info_dict': {
61 'id': 'UeBhTudbfS',
62 'ext': 'mp4',
63 'title': 'My 7 year old Sister and I singing "Alive" by Krewella',
64 'description': 'md5:40bcacb97796339f1690642c21d56f4a',
65 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/102265d5a9f-0f17-4f6b-5753-adf08484ee1e\.jpg$',
66 'uploader': 'Seraina',
67 'timestamp': 1396492438,
68 'upload_date': '20140403',
69 'duration': 240.107,
70 'like_count': int,
71 'dislike_count': int,
72 'comment_count': int,
73 'categories': ['seraina', 'jessica', 'krewella', 'alive'],
74 },
75 'skip': 'Removed due to DMCA',
76 }, {
77 'url': 'http://vube.com/vote/Siren+Gene/0nmsMY5vEq?n=2&t=s',
78 'md5': '0584fc13b50f887127d9d1007589d27f',
79 'info_dict': {
80 'id': '0nmsMY5vEq',
81 'ext': 'mp4',
82 'title': 'Frozen - Let It Go Cover by Siren Gene',
83 'description': 'My rendition of "Let It Go" originally sung by Idina Menzel.',
84 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/10283ab622a-86c9-4681-51f2-30d1f65774af\.jpg$',
85 'uploader': 'Siren',
86 'timestamp': 1395448018,
87 'upload_date': '20140322',
88 'duration': 221.788,
89 'like_count': int,
90 'dislike_count': int,
91 'comment_count': int,
92 'categories': ['let it go', 'cover', 'idina menzel', 'frozen', 'singing', 'disney', 'siren gene'],
93 },
94 'skip': 'Removed due to DMCA',
95 }
96 ]
97
98 def _real_extract(self, url):
99 mobj = re.match(self._VALID_URL, url)
100 video_id = mobj.group('id')
101
102 video = self._download_json(
103 'http://vube.com/t-api/v1/video/%s' % video_id, video_id, 'Downloading video JSON')
104
105 public_id = video['public_id']
106
107 formats = []
108
109 for media in video['media'].get('video', []) + video['media'].get('audio', []):
110 if media['transcoding_status'] != 'processed':
111 continue
112 fmt = {
113 'url': 'http://video.thestaticvube.com/video/%s/%s.mp4' % (media['media_resolution_id'], public_id),
114 'abr': int(media['audio_bitrate']),
115 'format_id': compat_str(media['media_resolution_id']),
116 }
117 vbr = int(media['video_bitrate'])
118 if vbr:
119 fmt.update({
120 'vbr': vbr,
121 'height': int(media['height']),
122 })
123 formats.append(fmt)
124
125 self._sort_formats(formats)
126
127 if not formats and video.get('vst') == 'dmca':
128 raise ExtractorError(
129 'This video has been removed in response to a complaint received under the US Digital Millennium Copyright Act.',
130 expected=True)
131
132 title = video['title']
133 description = video.get('description')
134 thumbnail = self._proto_relative_url(video.get('thumbnail_src'), scheme='http:')
135 uploader = video.get('user_alias') or video.get('channel')
136 timestamp = int_or_none(video.get('upload_time'))
137 duration = video['duration']
138 view_count = video.get('raw_view_count')
139 like_count = video.get('total_likes')
140 dislike_count = video.get('total_hates')
141
142 comments = video.get('comments')
143 comment_count = None
144 if comments is None:
145 comment_data = self._download_json(
146 'http://vube.com/api/video/%s/comment' % video_id,
147 video_id, 'Downloading video comment JSON', fatal=False)
148 if comment_data is not None:
149 comment_count = int_or_none(comment_data.get('total'))
150 else:
151 comment_count = len(comments)
152
153 categories = [tag['text'] for tag in video['tags']]
154
155 return {
156 'id': video_id,
157 'formats': formats,
158 'title': title,
159 'description': description,
160 'thumbnail': thumbnail,
161 'uploader': uploader,
162 'timestamp': timestamp,
163 'duration': duration,
164 'view_count': view_count,
165 'like_count': like_count,
166 'dislike_count': dislike_count,
167 'comment_count': comment_count,
168 'categories': categories,
169 }