0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-23 02:25:11 +00:00

[onionstudios] fix extraction

This commit is contained in:
Remita Amine 2019-11-06 10:44:19 +01:00
parent 3ec86619e3
commit d64ec1242e

View file

@ -5,10 +5,11 @@
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
determine_ext, compat_str,
int_or_none, int_or_none,
float_or_none, js_to_json,
mimetype2ext, parse_iso8601,
try_get,
) )
@ -17,14 +18,16 @@ class OnionStudiosIE(InfoExtractor):
_TESTS = [{ _TESTS = [{
'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937', 'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937',
'md5': '719d1f8c32094b8c33902c17bcae5e34', 'md5': '5a118d466d62b5cd03647cf2c593977f',
'info_dict': { 'info_dict': {
'id': '2937', 'id': '2937',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Hannibal charges forward, stops for a cocktail', 'title': 'Hannibal charges forward, stops for a cocktail',
'description': 'md5:545299bda6abf87e5ec666548c6a9448',
'thumbnail': r're:^https?://.*\.jpg$', 'thumbnail': r're:^https?://.*\.jpg$',
'uploader': 'The A.V. Club', 'uploader': 'a.v. club',
'uploader_id': 'the-av-club', 'upload_date': '20150619',
'timestamp': 1434728546,
}, },
}, { }, {
'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true', 'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true',
@ -44,38 +47,49 @@ def _extract_url(webpage):
def _real_extract(self, url): def _real_extract(self, url):
video_id = self._match_id(url) video_id = self._match_id(url)
webpage = self._download_webpage(
'http://onionstudios.com/embed/dc94dc2899fe644c0e7241fa04c1b732.js',
video_id)
mcp_id = compat_str(self._parse_json(self._search_regex(
r'window\.mcpMapping\s*=\s*({.+?});', webpage,
'MCP Mapping'), video_id, js_to_json)[video_id]['mcp_id'])
video_data = self._download_json( video_data = self._download_json(
'http://www.onionstudios.com/video/%s.json' % video_id, video_id) 'https://api.vmh.univision.com/metadata/v1/content/' + mcp_id,
mcp_id)['videoMetadata']
title = video_data['title'] iptc = video_data['photoVideoMetadataIPTC']
title = iptc['title']['en']
fmg = video_data.get('photoVideoMetadata_fmg') or {}
tvss_domain = fmg.get('tvssDomain') or 'https://auth.univision.com'
data = self._download_json(
tvss_domain + '/api/v3/video-auth/url-signature-tokens',
mcp_id, query={'mcpids': mcp_id})['data'][0]
formats = [] formats = []
for source in video_data.get('sources', []):
source_url = source.get('url') rendition_url = data.get('renditionUrl')
if not source_url: if rendition_url:
continue formats = self._extract_m3u8_formats(
ext = mimetype2ext(source.get('content_type')) or determine_ext(source_url) rendition_url, mcp_id, 'mp4',
if ext == 'm3u8': 'm3u8_native', m3u8_id='hls', fatal=False)
formats.extend(self._extract_m3u8_formats(
source_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)) fallback_rendition_url = data.get('fallbackRenditionUrl')
else: if fallback_rendition_url:
tbr = int_or_none(source.get('bitrate'))
formats.append({ formats.append({
'format_id': ext + ('-%d' % tbr if tbr else ''), 'format_id': 'fallback',
'url': source_url, 'tbr': int_or_none(self._search_regex(
'width': int_or_none(source.get('width')), r'_(\d+)\.mp4', fallback_rendition_url,
'tbr': tbr, 'bitrate', default=None)),
'ext': ext, 'url': fallback_rendition_url,
}) })
self._sort_formats(formats) self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'thumbnail': video_data.get('poster_url'), 'thumbnail': try_get(iptc, lambda x: x['cloudinaryLink']['link'], compat_str),
'uploader': video_data.get('channel_name'), 'uploader': fmg.get('network'),
'uploader_id': video_data.get('channel_slug'), 'duration': int_or_none(iptc.get('fileDuration')),
'duration': float_or_none(video_data.get('duration', 1000)),
'tags': video_data.get('tags'),
'formats': formats, 'formats': formats,
'description': try_get(iptc, lambda x: x['description']['en'], compat_str),
'timestamp': parse_iso8601(iptc.get('dateReleased')),
} }