1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-02 17:22:31 +01:00

[dctptv] Restore extraction based on REST API (closes #16850)

This commit is contained in:
Sergey M․ 2018-06-29 00:35:05 +07:00
parent 7b393f9cc5
commit acbd0ff5df
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

View File

@ -5,13 +5,15 @@
from ..compat import compat_str from ..compat import compat_str
from ..utils import ( from ..utils import (
float_or_none, float_or_none,
unified_strdate, int_or_none,
unified_timestamp,
) )
class DctpTvIE(InfoExtractor): class DctpTvIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?dctp\.tv/(?:#/)?filme/(?P<id>[^/?#&]+)' _VALID_URL = r'https?://(?:www\.)?dctp\.tv/(?:#/)?filme/(?P<id>[^/?#&]+)'
_TEST = { _TESTS = [{
# 4x3
'url': 'http://www.dctp.tv/filme/videoinstallation-fuer-eine-kaufhausfassade/', 'url': 'http://www.dctp.tv/filme/videoinstallation-fuer-eine-kaufhausfassade/',
'info_dict': { 'info_dict': {
'id': '95eaa4f33dad413aa17b4ee613cccc6c', 'id': '95eaa4f33dad413aa17b4ee613cccc6c',
@ -19,31 +21,49 @@ class DctpTvIE(InfoExtractor):
'ext': 'flv', 'ext': 'flv',
'title': 'Videoinstallation für eine Kaufhausfassade', 'title': 'Videoinstallation für eine Kaufhausfassade',
'description': 'Kurzfilm', 'description': 'Kurzfilm',
'upload_date': '20110407',
'thumbnail': r're:^https?://.*\.jpg$', 'thumbnail': r're:^https?://.*\.jpg$',
'duration': 71.24, 'duration': 71.24,
'timestamp': 1302172322,
'upload_date': '20110407',
}, },
'params': { 'params': {
# rtmp download # rtmp download
'skip_download': True, 'skip_download': True,
}, },
} }, {
# 16x9
'url': 'http://www.dctp.tv/filme/sind-youtuber-die-besseren-lehrer/',
'only_matching': True,
}]
_BASE_URL = 'http://dctp-ivms2-restapi.s3.amazonaws.com'
def _real_extract(self, url): def _real_extract(self, url):
display_id = self._match_id(url) display_id = self._match_id(url)
webpage = self._download_webpage(url, display_id) version = self._download_json(
'%s/version.json' % self._BASE_URL, display_id,
'Downloading version JSON')
video_id = self._html_search_meta( restapi_base = '%s/%s/restapi' % (
'DC.identifier', webpage, 'video id', self._BASE_URL, version['version_name'])
default=None) or self._search_regex(
r'id=["\']uuid[^>]+>([^<]+)<', webpage, 'video id')
title = self._og_search_title(webpage) info = self._download_json(
'%s/slugs/%s.json' % (restapi_base, display_id), display_id,
'Downloading video info JSON')
media = self._download_json(
'%s/media/%s.json' % (restapi_base, compat_str(info['object_id'])),
display_id, 'Downloading media JSON')
uuid = media['uuid']
title = media['title']
ratio = '16x9' if media.get('is_wide') else '4x3'
play_path = 'mp4:%s_dctp_0500_%s.m4v' % (uuid, ratio)
servers = self._download_json( servers = self._download_json(
'http://www.dctp.tv/streaming_servers/', display_id, 'http://www.dctp.tv/streaming_servers/', display_id,
note='Downloading server list', fatal=False) note='Downloading server list JSON', fatal=False)
if servers: if servers:
endpoint = next( endpoint = next(
@ -60,27 +80,35 @@ def _real_extract(self, url):
formats = [{ formats = [{
'url': endpoint, 'url': endpoint,
'app': app, 'app': app,
'play_path': 'mp4:%s_dctp_0500_4x3.m4v' % video_id, 'play_path': play_path,
'page_url': url, 'page_url': url,
'player_url': 'http://svm-prod-dctptv-static.s3.amazonaws.com/dctptv-relaunch2012-109.swf', 'player_url': 'http://svm-prod-dctptv-static.s3.amazonaws.com/dctptv-relaunch2012-110.swf',
'ext': 'flv', 'ext': 'flv',
}] }]
description = self._html_search_meta('DC.description', webpage) thumbnails = []
upload_date = unified_strdate( images = media.get('images')
self._html_search_meta('DC.date.created', webpage)) if isinstance(images, list):
thumbnail = self._og_search_thumbnail(webpage) for image in images:
duration = float_or_none(self._search_regex( if not isinstance(image, dict):
r'id=["\']duration_in_ms[^+]>(\d+)', webpage, 'duration', continue
default=None), scale=1000) image_url = image.get('url')
if not image_url or not isinstance(image_url, compat_str):
continue
thumbnails.append({
'url': image_url,
'width': int_or_none(image.get('width')),
'height': int_or_none(image.get('height')),
})
return { return {
'id': video_id, 'id': uuid,
'title': title,
'formats': formats,
'display_id': display_id, 'display_id': display_id,
'description': description, 'title': title,
'upload_date': upload_date, 'alt_title': media.get('subtitle'),
'thumbnail': thumbnail, 'description': media.get('description') or media.get('teaser'),
'duration': duration, 'timestamp': unified_timestamp(media.get('created')),
'duration': float_or_none(media.get('duration_in_ms'), scale=1000),
'thumbnails': thumbnails,
'formats': formats,
} }