[arkena] fix extraction

This commit is contained in:
Remita Amine 2020-12-20 12:03:35 +01:00
parent a8b31505ed
commit 3ba6aabd25

View File

@ -6,13 +6,11 @@ import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import compat_urlparse from ..compat import compat_urlparse
from ..utils import ( from ..utils import (
determine_ext,
ExtractorError, ExtractorError,
float_or_none, float_or_none,
int_or_none, int_or_none,
mimetype2ext,
parse_iso8601, parse_iso8601,
strip_jsonp, try_get,
) )
@ -20,22 +18,27 @@ class ArkenaIE(InfoExtractor):
_VALID_URL = r'''(?x) _VALID_URL = r'''(?x)
https?:// https?://
(?: (?:
video\.arkena\.com/play2/embed/player\?| video\.(?:arkena|qbrick)\.com/play2/embed/player\?|
play\.arkena\.com/(?:config|embed)/avp/v\d/player/media/(?P<id>[^/]+)/[^/]+/(?P<account_id>\d+) play\.arkena\.com/(?:config|embed)/avp/v\d/player/media/(?P<id>[^/]+)/[^/]+/(?P<account_id>\d+)
) )
''' '''
_TESTS = [{ _TESTS = [{
'url': 'https://play.arkena.com/embed/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411', 'url': 'https://video.qbrick.com/play2/embed/player?accountId=1034090&mediaId=d8ab4607-00090107-aab86310',
'md5': 'b96f2f71b359a8ecd05ce4e1daa72365', 'md5': '97f117754e5f3c020f5f26da4a44ebaf',
'info_dict': { 'info_dict': {
'id': 'b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe', 'id': 'd8ab4607-00090107-aab86310',
'ext': 'mp4', 'ext': 'mp4',
'title': 'Big Buck Bunny', 'title': 'EM_HT20_117_roslund_v2.mp4',
'description': 'Royalty free test video', 'timestamp': 1608285912,
'timestamp': 1432816365, 'upload_date': '20201218',
'upload_date': '20150528', 'duration': 1429.162667,
'is_live': False, 'subtitles': {
'sv': 'count:3',
},
}, },
}, {
'url': 'https://play.arkena.com/embed/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411',
'only_matching': True,
}, { }, {
'url': 'https://play.arkena.com/config/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411/?callbackMethod=jQuery1111023664739129262213_1469227693893', 'url': 'https://play.arkena.com/config/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411/?callbackMethod=jQuery1111023664739129262213_1469227693893',
'only_matching': True, 'only_matching': True,
@ -72,62 +75,89 @@ class ArkenaIE(InfoExtractor):
if not video_id or not account_id: if not video_id or not account_id:
raise ExtractorError('Invalid URL', expected=True) raise ExtractorError('Invalid URL', expected=True)
playlist = self._download_json( media = self._download_json(
'https://play.arkena.com/config/avp/v2/player/media/%s/0/%s/?callbackMethod=_' 'https://video.qbrick.com/api/v1/public/accounts/%s/medias/%s' % (account_id, video_id),
% (video_id, account_id), video_id, query={
video_id, transform_source=strip_jsonp)['Playlist'][0] # https://video.qbrick.com/docs/api/examples/library-api.html
'fields': 'asset/resources/*/renditions/*(height,id,language,links/*(href,mimeType),type,size,videos/*(audios/*(codec,sampleRate),bitrate,codec,duration,height,width),width),created,metadata/*(title,description),tags',
})
metadata = media.get('metadata') or {}
title = metadata['title']
media_info = playlist['MediaInfo'] duration = None
title = media_info['Title']
media_files = playlist['MediaFiles']
is_live = False
formats = [] formats = []
for kind_case, kind_formats in media_files.items(): thumbnails = []
kind = kind_case.lower() subtitles = {}
for f in kind_formats: for resource in media['asset']['resources']:
f_url = f.get('Url') for rendition in (resource.get('renditions') or []):
if not f_url: rendition_type = rendition.get('type')
continue for i, link in enumerate(rendition.get('links') or []):
is_live = f.get('Live') == 'true' href = link.get('href')
exts = (mimetype2ext(f.get('Type')), determine_ext(f_url, None)) if not href:
if kind == 'm3u8' or 'm3u8' in exts: continue
formats.extend(self._extract_m3u8_formats( if rendition_type == 'image':
f_url, video_id, 'mp4', 'm3u8_native', thumbnails.append({
m3u8_id=kind, fatal=False, live=is_live)) 'filesize': int_or_none(rendition.get('size')),
elif kind == 'flash' or 'f4m' in exts: 'height': int_or_none(rendition.get('height')),
formats.extend(self._extract_f4m_formats( 'id': rendition.get('id'),
f_url, video_id, f4m_id=kind, fatal=False)) 'url': href,
elif kind == 'dash' or 'mpd' in exts: 'width': int_or_none(rendition.get('width')),
formats.extend(self._extract_mpd_formats( })
f_url, video_id, mpd_id=kind, fatal=False)) elif rendition_type == 'subtitle':
elif kind == 'silverlight': subtitles.setdefault(rendition.get('language') or 'en', []).append({
# TODO: process when ism is supported (see 'url': href,
# https://github.com/ytdl-org/youtube-dl/issues/8118) })
continue elif rendition_type == 'video':
else: f = {
tbr = float_or_none(f.get('Bitrate'), 1000) 'filesize': int_or_none(rendition.get('size')),
formats.append({ 'format_id': rendition.get('id'),
'url': f_url, 'url': href,
'format_id': '%s-%d' % (kind, tbr) if tbr else kind, }
'tbr': tbr, video = try_get(rendition, lambda x: x['videos'][i], dict)
}) if video:
if not duration:
duration = float_or_none(video.get('duration'))
f.update({
'height': int_or_none(video.get('height')),
'tbr': int_or_none(video.get('bitrate'), 1000),
'vcodec': video.get('codec'),
'width': int_or_none(video.get('width')),
})
audio = try_get(video, lambda x: x['audios'][0], dict)
if audio:
f.update({
'acodec': audio.get('codec'),
'asr': int_or_none(audio.get('sampleRate')),
})
formats.append(f)
elif rendition_type == 'index':
mime_type = link.get('mimeType')
if mime_type == 'application/smil+xml':
formats.extend(self._extract_smil_formats(
href, video_id, fatal=False))
elif mime_type == 'application/x-mpegURL':
formats.extend(self._extract_m3u8_formats(
href, video_id, 'mp4', 'm3u8_native',
m3u8_id='hls', fatal=False))
elif mime_type == 'application/hds+xml':
formats.extend(self._extract_f4m_formats(
href, video_id, f4m_id='hds', fatal=False))
elif mime_type == 'application/dash+xml':
formats.extend(self._extract_f4m_formats(
href, video_id, f4m_id='hds', fatal=False))
elif mime_type == 'application/vnd.ms-sstr+xml':
formats.extend(self._extract_ism_formats(
href, video_id, ism_id='mss', fatal=False))
self._sort_formats(formats) self._sort_formats(formats)
description = media_info.get('Description')
video_id = media_info.get('VideoId') or video_id
timestamp = parse_iso8601(media_info.get('PublishDate'))
thumbnails = [{
'url': thumbnail['Url'],
'width': int_or_none(thumbnail.get('Size')),
} for thumbnail in (media_info.get('Poster') or []) if thumbnail.get('Url')]
return { return {
'id': video_id, 'id': video_id,
'title': title, 'title': title,
'description': description, 'description': metadata.get('description'),
'timestamp': timestamp, 'timestamp': parse_iso8601(media.get('created')),
'is_live': is_live,
'thumbnails': thumbnails, 'thumbnails': thumbnails,
'subtitles': subtitles,
'duration': duration,
'tags': media.get('tags'),
'formats': formats, 'formats': formats,
} }