From d9c19db340c568db1afcd6d85ab5b9c4681dd7df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Wed, 9 Sep 2015 17:02:28 +0200 Subject: [PATCH] Extract all vid.me formats --- youtube_dl/extractor/vidme.py | 82 ++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/youtube_dl/extractor/vidme.py b/youtube_dl/extractor/vidme.py index 157bb74fe..7f44948e9 100644 --- a/youtube_dl/extractor/vidme.py +++ b/youtube_dl/extractor/vidme.py @@ -1,10 +1,10 @@ from __future__ import unicode_literals -from .common import InfoExtractor +from .common import InfoExtractor, ExtractorError from ..utils import ( int_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[\da-zA-Z]+)' _TESTS = [{ 'url': 'https://vid.me/QNB', - 'md5': 'f42d05e7149aeaec5c037b17e5d3dc82', + 'md5': 'c62f1156138dc3323902188c5b5a8bd6', 'info_dict': { 'id': 'QNB', 'ext': 'mp4', @@ -24,6 +24,26 @@ class VidmeIE(InfoExtractor): 'thumbnail': 're:^https?://.*\.jpg', 'view_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 @@ -40,6 +60,7 @@ class VidmeIE(InfoExtractor): 'thumbnail': 're:^https?://.*\.jpg', 'view_count': int, 'like_count': int, + 'comment_count': int, }, 'params': { 'skip_download': True, @@ -51,45 +72,46 @@ class VidmeIE(InfoExtractor): }] def _real_extract(self, url): - url = url.replace('vid.me/e/', 'vid.me/') 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_data = data.get('video') + if video_data is None: + raise ExtractorError('Could not extract the vid.me video data') + + title = video_data.get('title') + description = video_data.get('description') + thumbnail = video_data.get('thumbnail_url') + timestamp = parse_iso8601(video_data.get('date_created'), ' ') + duration = float_or_none(video_data.get('duration')) + view_count = int_or_none(video_data.get('view_count')) + like_count = int_or_none(video_data.get('likes_count')) + comment_count = int_or_none(video_data.get('comment_count')) - video_url = self._html_search_regex( - r'\s*([\d,\.]+)\s*plays?', - webpage, 'view count', fatal=False)) - like_count = str_to_int(self._html_search_regex( - r'class="score js-video-vote-score"[^>]+data-score="([\d,\.\s]+)">', - webpage, 'like count', fatal=False)) - uploader = self._html_search_regex( - 'class="video_author_username"[^>]*>([^<]+)', - webpage, 'uploader', default=None) + formats = [{ + 'format_id': format['type'], + 'url': format['uri'], + 'width': int_or_none(format['width']), + 'height': int_or_none(format['height']), + } for format in video_data.get('formats', [])] + self._sort_formats(formats) return { 'id': video_id, - 'url': video_url, 'title': title, 'description': description, 'thumbnail': thumbnail, 'timestamp': timestamp, - 'width': width, - 'height': height, 'duration': duration, 'view_count': view_count, 'like_count': like_count, + 'comment_count': comment_count, 'uploader': uploader, + 'formats': formats, } -- 2.22.2