X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Ftwentythreevideo.py;h=dc56091925e7c50c7f6b2f182a14d9ebbb679aba;hb=HEAD;hp=2bad2dbd6661fb2d8d12da1480104d5a2d232fe1;hpb=a14001a5a13b1639dc98b75b0775d251487aad1d;p=youtube-dl diff --git a/youtube_dl/extractor/twentythreevideo.py b/youtube_dl/extractor/twentythreevideo.py index 2bad2dbd6..dc5609192 100644 --- a/youtube_dl/extractor/twentythreevideo.py +++ b/youtube_dl/extractor/twentythreevideo.py @@ -1,45 +1,80 @@ from __future__ import unicode_literals +import re + from .common import InfoExtractor +from ..utils import int_or_none class TwentyThreeVideoIE(InfoExtractor): IE_NAME = '23video' - _VALID_URL = r'https?://(?:www\.)?(?P[\w-]+)\.23video\.com/v.ihtml/player.html.*photo_id=(?P\d+)' - _TEST = {} - - _URL_TEMPLATE = 'https://%s.23video.com/%s/%s/%s/%s/download-video.mp4' - _FORMATS = { - 'video_hd': { - 'width': 1280, - 'height': 720, - }, - 'video_medium': { - 'width': 640, - 'height': 360, - }, - 'video_mobile_high': { - 'width': 320, - 'height': 180, + _VALID_URL = r'https?://(?P[^.]+\.(?:twentythree\.net|23video\.com|filmweb\.no))/v\.ihtml/player\.html\?(?P.*?\bphoto(?:_|%5f)id=(?P\d+).*)' + _TESTS = [{ + 'url': 'https://video.twentythree.net/v.ihtml/player.html?showDescriptions=0&source=site&photo%5fid=20448876&autoPlay=1', + 'md5': '75fcf216303eb1dae9920d651f85ced4', + 'info_dict': { + 'id': '20448876', + 'ext': 'mp4', + 'title': 'Video Marketing Minute: Personalized Video', + 'timestamp': 1513855354, + 'upload_date': '20171221', + 'uploader_id': '12258964', + 'uploader': 'Rasmus Bysted', } - } + }, { + 'url': 'https://bonnier-publications-danmark.23video.com/v.ihtml/player.html?token=f0dc46476e06e13afd5a1f84a29e31e8&source=embed&photo%5fid=36137620', + 'only_matching': True, + }] - def _extract_formats(self, url, client_id): - client_name = self._search_regex(r'([a-z]+)\.23video\.com', url, 'client name') - video_id = self._search_regex(r'photo%5fid=([^?&]+)', url, 'video id') - token = self._search_regex(r'token=([^?&]+)', url, 'token') + def _real_extract(self, url): + domain, query, photo_id = re.match(self._VALID_URL, url).groups() + base_url = 'https://%s' % domain + photo_data = self._download_json( + base_url + '/api/photo/list?' + query, photo_id, query={ + 'format': 'json', + }, transform_source=lambda s: self._search_regex(r'(?s)({.+})', s, 'photo data'))['photo'] + title = photo_data['title'] formats = [] - for format_key in self._FORMATS.keys(): + + audio_path = photo_data.get('audio_download') + if audio_path: formats.append({ - 'url': self._URL_TEMPLATE % (client_name, client_id, video_id, - token, format_key), - 'width': self._FORMATS.get(format_key, {}).get('width'), - 'height': self._FORMATS.get(format_key, {}).get('height'), + 'format_id': 'audio', + 'url': base_url + audio_path, + 'filesize': int_or_none(photo_data.get('audio_size')), + 'vcodec': 'none', + }) + + def add_common_info_to_list(l, template, id_field, id_value): + f_base = template % id_value + f_path = photo_data.get(f_base + 'download') + if not f_path: + return + l.append({ + id_field: id_value, + 'url': base_url + f_path, + 'width': int_or_none(photo_data.get(f_base + 'width')), + 'height': int_or_none(photo_data.get(f_base + 'height')), + 'filesize': int_or_none(photo_data.get(f_base + 'size')), }) - return formats + for f in ('mobile_high', 'medium', 'hd', '1080p', '4k'): + add_common_info_to_list(formats, 'video_%s_', 'format_id', f) - def _real_extract(self, url): - # TODO: Find out how to extract client_id - raise NotImplementedError('Not able to extract the `client_id`') + thumbnails = [] + for t in ('quad16', 'quad50', 'quad75', 'quad100', 'small', 'portrait', 'standard', 'medium', 'large', 'original'): + add_common_info_to_list(thumbnails, '%s_', 'id', t) + + return { + 'id': photo_id, + 'title': title, + 'timestamp': int_or_none(photo_data.get('creation_date_epoch')), + 'duration': int_or_none(photo_data.get('video_length')), + 'view_count': int_or_none(photo_data.get('view_count')), + 'comment_count': int_or_none(photo_data.get('number_of_comments')), + 'uploader_id': photo_data.get('user_id'), + 'uploader': photo_data.get('display_name'), + 'thumbnails': thumbnails, + 'formats': formats, + }