[vube] Extract audio and categories

This commit is contained in:
Sergey M․ 2014-08-07 20:04:29 +07:00
parent d9760fd43c
commit 5961017202

View file

@ -1,10 +1,12 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import json
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import int_or_none from ..utils import (
int_or_none,
compat_str,
)
class VubeIE(InfoExtractor): class VubeIE(InfoExtractor):
@ -29,6 +31,7 @@ class VubeIE(InfoExtractor):
'like_count': int, 'like_count': int,
'dislike_count': int, 'dislike_count': int,
'comment_count': int, 'comment_count': int,
'categories': ['pop', 'music', 'cover', 'singing', 'jessie j', 'price tag', 'chiara grispo'],
} }
}, },
{ {
@ -47,6 +50,7 @@ class VubeIE(InfoExtractor):
'like_count': int, 'like_count': int,
'dislike_count': int, 'dislike_count': int,
'comment_count': int, 'comment_count': int,
'categories': ['seraina', 'jessica', 'krewella', 'alive'],
} }
}, { }, {
'url': 'http://vube.com/vote/Siren+Gene/0nmsMY5vEq?n=2&t=s', 'url': 'http://vube.com/vote/Siren+Gene/0nmsMY5vEq?n=2&t=s',
@ -56,13 +60,15 @@ class VubeIE(InfoExtractor):
'ext': 'mp4', 'ext': 'mp4',
'title': 'Frozen - Let It Go Cover by Siren Gene', 'title': 'Frozen - Let It Go Cover by Siren Gene',
'description': 'My rendition of "Let It Go" originally sung by Idina Menzel.', 'description': 'My rendition of "Let It Go" originally sung by Idina Menzel.',
'uploader': 'Siren Gene',
'uploader_id': 'Siren',
'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/10283ab622a-86c9-4681-51f2-30d1f65774af\.jpg$', 'thumbnail': 're:^http://frame\.thestaticvube\.com/snap/[0-9x]+/10283ab622a-86c9-4681-51f2-30d1f65774af\.jpg$',
'uploader': 'Siren',
'timestamp': 1395448018,
'upload_date': '20140322',
'duration': 221.788, 'duration': 221.788,
'like_count': int, 'like_count': int,
'dislike_count': int, 'dislike_count': int,
'comment_count': int, 'comment_count': int,
'categories': ['let it go', 'cover', 'idina menzel', 'frozen', 'singing', 'disney', 'siren gene'],
} }
} }
] ]
@ -71,43 +77,40 @@ class VubeIE(InfoExtractor):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id') video_id = mobj.group('id')
json_url = 'http://vube.com/t-api/v1/video/%s?country=US&limit=120&region=US' % video_id video = self._download_json(
data = self._download_json(json_url, video_id) 'http://vube.com/t-api/v1/video/%s' % video_id, video_id, 'Downloading video JSON')
video = (
data.get('video') or
data)
assert isinstance(video, dict)
public_id = video['public_id'] public_id = video['public_id']
formats = [ formats = []
{
'url': 'http://video.thestaticvube.com/video/%s/%s.mp4' % (fmt['media_resolution_id'], public_id), for media in video['media'].get('video', []) + video['media'].get('audio', []):
'height': int(fmt['height']), if media['transcoding_status'] != 'processed':
'abr': int(fmt['audio_bitrate']), continue
'vbr': int(fmt['video_bitrate']), fmt = {
'format_id': fmt['media_resolution_id'] 'url': 'http://video.thestaticvube.com/video/%s/%s.mp4' % (media['media_resolution_id'], public_id),
} for fmt in video['mtm'] if fmt['transcoding_status'] == 'processed' 'abr': int(media['audio_bitrate']),
] 'format_id': compat_str(media['media_resolution_id']),
}
vbr = int(media['video_bitrate'])
if vbr:
fmt.update({
'vbr': vbr,
'height': int(media['height']),
})
formats.append(fmt)
self._sort_formats(formats) self._sort_formats(formats)
title = video['title'] title = video['title']
description = video.get('description') description = video.get('description')
thumbnail = self._proto_relative_url( thumbnail = self._proto_relative_url(video.get('thumbnail_src'), scheme='http:')
video.get('thumbnail') or video.get('thumbnail_src'), uploader = video.get('user_alias') or video.get('channel')
scheme='http:')
uploader = data.get('user', {}).get('channel', {}).get('name') or video.get('user_alias')
uploader_id = data.get('user', {}).get('name')
timestamp = int_or_none(video.get('upload_time')) timestamp = int_or_none(video.get('upload_time'))
duration = video['duration'] duration = video['duration']
view_count = video.get('raw_view_count') view_count = video.get('raw_view_count')
like_count = video.get('rlikes') like_count = video.get('total_likes')
if like_count is None: dislike_count = video.get('total_hates')
like_count = video.get('total_likes')
dislike_count = video.get('rhates')
if dislike_count is None:
dislike_count = video.get('total_hates')
comments = video.get('comments') comments = video.get('comments')
comment_count = None comment_count = None
@ -120,6 +123,8 @@ class VubeIE(InfoExtractor):
else: else:
comment_count = len(comments) comment_count = len(comments)
categories = [tag['text'] for tag in video['tags']]
return { return {
'id': video_id, 'id': video_id,
'formats': formats, 'formats': formats,
@ -127,11 +132,11 @@ class VubeIE(InfoExtractor):
'description': description, 'description': description,
'thumbnail': thumbnail, 'thumbnail': thumbnail,
'uploader': uploader, 'uploader': uploader,
'uploader_id': uploader_id,
'timestamp': timestamp, 'timestamp': timestamp,
'duration': duration, 'duration': duration,
'view_count': view_count, 'view_count': view_count,
'like_count': like_count, 'like_count': like_count,
'dislike_count': dislike_count, 'dislike_count': dislike_count,
'comment_count': comment_count, 'comment_count': comment_count,
'categories': categories,
} }