Extract all vid.me formats

This commit is contained in:
Lukáš Lalinský 2015-09-09 17:02:28 +02:00 committed by Sergey M․
parent 6c4d243de5
commit d9c19db340
1 changed files with 52 additions and 30 deletions

View File

@ -1,10 +1,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from .common import InfoExtractor from .common import InfoExtractor, ExtractorError
from ..utils import ( from ..utils import (
int_or_none, int_or_none,
float_or_none, float_or_none,
str_to_int, parse_iso8601,
) )
@ -12,7 +12,7 @@ class VidmeIE(InfoExtractor):
_VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]+)' _VALID_URL = r'https?://vid\.me/(?:e/)?(?P<id>[\da-zA-Z]+)'
_TESTS = [{ _TESTS = [{
'url': 'https://vid.me/QNB', 'url': 'https://vid.me/QNB',
'md5': 'f42d05e7149aeaec5c037b17e5d3dc82', 'md5': 'c62f1156138dc3323902188c5b5a8bd6',
'info_dict': { 'info_dict': {
'id': 'QNB', 'id': 'QNB',
'ext': 'mp4', 'ext': 'mp4',
@ -24,6 +24,26 @@ class VidmeIE(InfoExtractor):
'thumbnail': 're:^https?://.*\.jpg', 'thumbnail': 're:^https?://.*\.jpg',
'view_count': int, 'view_count': int,
'like_count': int, 'like_count': int,
'comment_count': int,
},
}, {
'url': 'https://vid.me/Gc6M',
'md5': 'f42d05e7149aeaec5c037b17e5d3dc82',
'info_dict': {
'id': 'Gc6M',
'ext': 'mp4',
'title': 'O Mere Dil ke chain - Arnav and Khushi VM',
'duration': 223.72,
'timestamp': 1441211642,
'upload_date': '20150902',
'thumbnail': 're:^https?://.*\.jpg',
'view_count': int,
'like_count': int,
'comment_count': int,
'comment_count': int,
},
'params': {
'skip_download': True,
}, },
}, { }, {
# tests uploader field # tests uploader field
@ -40,6 +60,7 @@ class VidmeIE(InfoExtractor):
'thumbnail': 're:^https?://.*\.jpg', 'thumbnail': 're:^https?://.*\.jpg',
'view_count': int, 'view_count': int,
'like_count': int, 'like_count': int,
'comment_count': int,
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@ -51,45 +72,46 @@ class VidmeIE(InfoExtractor):
}] }]
def _real_extract(self, url): def _real_extract(self, url):
url = url.replace('vid.me/e/', 'vid.me/')
video_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id) api_url = 'https://api.vid.me/videoByUrl/' + video_id
data = self._download_json(api_url, video_id)
video_url = self._html_search_regex( video_data = data.get('video')
r'<source src="([^"]+)"', webpage, 'video URL') if video_data is None:
raise ExtractorError('Could not extract the vid.me video data')
title = self._og_search_title(webpage) title = video_data.get('title')
description = self._og_search_description(webpage, default='') description = video_data.get('description')
thumbnail = self._og_search_thumbnail(webpage) thumbnail = video_data.get('thumbnail_url')
timestamp = int_or_none(self._og_search_property( timestamp = parse_iso8601(video_data.get('date_created'), ' ')
'updated_time', webpage, fatal=False)) duration = float_or_none(video_data.get('duration'))
width = int_or_none(self._og_search_property( view_count = int_or_none(video_data.get('view_count'))
'video:width', webpage, fatal=False)) like_count = int_or_none(video_data.get('likes_count'))
height = int_or_none(self._og_search_property( comment_count = int_or_none(video_data.get('comment_count'))
'video:height', webpage, fatal=False))
duration = float_or_none(self._html_search_regex( uploader = None
r'data-duration="([^"]+)"', webpage, 'duration', fatal=False)) user_data = video_data.get('user')
view_count = str_to_int(self._html_search_regex( if user_data is not None:
r'<(?:li|span) class="video_views">\s*([\d,\.]+)\s*plays?', uploader = user_data.get('username')
webpage, 'view count', fatal=False))
like_count = str_to_int(self._html_search_regex( formats = [{
r'class="score js-video-vote-score"[^>]+data-score="([\d,\.\s]+)">', 'format_id': format['type'],
webpage, 'like count', fatal=False)) 'url': format['uri'],
uploader = self._html_search_regex( 'width': int_or_none(format['width']),
'class="video_author_username"[^>]*>([^<]+)', 'height': int_or_none(format['height']),
webpage, 'uploader', default=None) } for format in video_data.get('formats', [])]
self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,
'url': video_url,
'title': title, 'title': title,
'description': description, 'description': description,
'thumbnail': thumbnail, 'thumbnail': thumbnail,
'timestamp': timestamp, 'timestamp': timestamp,
'width': width,
'height': height,
'duration': duration, 'duration': duration,
'view_count': view_count, 'view_count': view_count,
'like_count': like_count, 'like_count': like_count,
'comment_count': comment_count,
'uploader': uploader, 'uploader': uploader,
'formats': formats,
} }