]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vube.py
Merge pull request #3461 from tinybug/patch-2
[yt-dlp.git] / youtube_dl / extractor / vube.py
CommitLineData
c85e4cf7 1from __future__ import unicode_literals
2
1a2ecbfb 3import json
c85e4cf7 4import re
c85e4cf7 5
6from .common import InfoExtractor
5f0f8013 7from ..utils import int_or_none
c85e4cf7 8
9
10class VubeIE(InfoExtractor):
11 IE_NAME = 'vube'
12 IE_DESC = 'Vube.com'
b5368ace 13 _VALID_URL = r'http://vube\.com/(?:[^/]+/)+(?P<id>[\da-zA-Z]{10})\b'
c85e4cf7 14
b5368ace
S
15 _TESTS = [
16 {
17 'url': 'http://vube.com/Chiara+Grispo+Video+Channel/YL2qNPkqon',
18 'md5': 'db7aba89d4603dadd627e9d1973946fe',
19 'info_dict': {
20 'id': 'YL2qNPkqon',
21 'ext': 'mp4',
22 'title': 'Chiara Grispo - Price Tag by Jessie J',
23 'description': 'md5:8ea652a1f36818352428cb5134933313',
1a2ecbfb 24 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/102e7e63057-5ebc-4f5c-4065-6ce4ebde131f\.jpg$',
b5368ace 25 'uploader': 'Chiara.Grispo',
b5368ace
S
26 'timestamp': 1388743358,
27 'upload_date': '20140103',
b090af59
PH
28 'duration': 170.56,
29 'like_count': int,
30 'dislike_count': int,
31 'comment_count': int,
b5368ace
S
32 }
33 },
34 {
35 'url': 'http://vube.com/SerainaMusic/my-7-year-old-sister-and-i-singing-alive-by-krewella/UeBhTudbfS?t=s&n=1',
36 'md5': '5d4a52492d76f72712117ce6b0d98d08',
37 'info_dict': {
38 'id': 'UeBhTudbfS',
39 'ext': 'mp4',
40 'title': 'My 7 year old Sister and I singing "Alive" by Krewella',
41 'description': 'md5:40bcacb97796339f1690642c21d56f4a',
1a2ecbfb 42 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/102265d5a9f-0f17-4f6b-5753-adf08484ee1e\.jpg$',
b5368ace 43 'uploader': 'Seraina',
b5368ace
S
44 'timestamp': 1396492438,
45 'upload_date': '20140403',
b090af59
PH
46 'duration': 240.107,
47 'like_count': int,
48 'dislike_count': int,
49 'comment_count': int,
b5368ace 50 }
1a2ecbfb
PH
51 }, {
52 'url': 'http://vube.com/vote/Siren+Gene/0nmsMY5vEq?n=2&t=s',
53 'md5': '0584fc13b50f887127d9d1007589d27f',
54 'info_dict': {
55 'id': '0nmsMY5vEq',
56 'ext': 'mp4',
57 'title': 'Frozen - Let It Go Cover by Siren Gene',
58 'description': 'My rendition of "Let It Go" originally sung by Idina Menzel.',
59 'uploader': 'Siren Gene',
60 'uploader_id': 'Siren',
61 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/10283ab622a-86c9-4681-51f2-30d1f65774af\.jpg$',
62 'duration': 221.788,
63 'like_count': int,
64 'dislike_count': int,
b090af59 65 'comment_count': int,
1a2ecbfb 66 }
c85e4cf7 67 }
b5368ace 68 ]
c85e4cf7 69
70 def _real_extract(self, url):
71 mobj = re.match(self._VALID_URL, url)
72 video_id = mobj.group('id')
73
d42b2d29 74 json_url = 'http://vube.com/t-api/v1/video/%s?country=US&limit=120&region=US' % video_id
75 data = self._download_json(json_url, video_id)
1a2ecbfb
PH
76 video = (
77 data.get('video') or
78 data)
79 assert isinstance(video, dict)
c85e4cf7 80
81 public_id = video['public_id']
82
5f0f8013
S
83 formats = [
84 {
85 'url': 'http://video.thestaticvube.com/video/%s/%s.mp4' % (fmt['media_resolution_id'], public_id),
86 'height': int(fmt['height']),
87 'abr': int(fmt['audio_bitrate']),
88 'vbr': int(fmt['video_bitrate']),
89 'format_id': fmt['media_resolution_id']
90 } for fmt in video['mtm'] if fmt['transcoding_status'] == 'processed'
91 ]
c85e4cf7 92
93 self._sort_formats(formats)
94
95 title = video['title']
f4635912 96 description = video.get('description')
1a2ecbfb
PH
97 thumbnail = self._proto_relative_url(
98 video.get('thumbnail') or video.get('thumbnail_src'),
99 scheme='http:')
100 uploader = data.get('user', {}).get('channel', {}).get('name') or video.get('user_alias')
101 uploader_id = data.get('user', {}).get('name')
102 timestamp = int_or_none(video.get('upload_time'))
c85e4cf7 103 duration = video['duration']
5f0f8013 104 view_count = video.get('raw_view_count')
1a2ecbfb 105 like_count = video.get('rlikes')
b090af59
PH
106 if like_count is None:
107 like_count = video.get('total_likes')
1a2ecbfb 108 dislike_count = video.get('rhates')
b090af59
PH
109 if dislike_count is None:
110 dislike_count = video.get('total_hates')
c85e4cf7 111
b090af59
PH
112 comments = video.get('comments')
113 comment_count = None
114 if comments is None:
115 comment_data = self._download_json(
116 'http://vube.com/api/video/%s/comment' % video_id,
117 video_id, 'Downloading video comment JSON', fatal=False)
118 if comment_data is not None:
119 comment_count = int_or_none(comment_data.get('total'))
120 else:
121 comment_count = len(comments)
c85e4cf7 122
123 return {
124 'id': video_id,
125 'formats': formats,
126 'title': title,
127 'description': description,
128 'thumbnail': thumbnail,
129 'uploader': uploader,
130 'uploader_id': uploader_id,
b5368ace 131 'timestamp': timestamp,
c85e4cf7 132 'duration': duration,
133 'view_count': view_count,
134 'like_count': like_count,
135 'dislike_count': dislike_count,
136 'comment_count': comment_count,
31f77343 137 }