2016-07-23 10:55:54 +00:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
2016-12-31 19:46:18 +00:00
|
|
|
ExtractorError,
|
2016-07-23 10:55:54 +00:00
|
|
|
float_or_none,
|
|
|
|
int_or_none,
|
|
|
|
parse_iso8601,
|
2021-08-22 19:02:00 +00:00
|
|
|
parse_qs,
|
2021-01-01 12:26:37 +00:00
|
|
|
try_get,
|
2016-07-23 10:55:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class ArkenaIE(InfoExtractor):
|
2016-12-31 19:46:18 +00:00
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
https?://
|
|
|
|
(?:
|
2021-01-01 12:26:37 +00:00
|
|
|
video\.(?:arkena|qbrick)\.com/play2/embed/player\?|
|
2016-12-31 19:46:18 +00:00
|
|
|
play\.arkena\.com/(?:config|embed)/avp/v\d/player/media/(?P<id>[^/]+)/[^/]+/(?P<account_id>\d+)
|
|
|
|
)
|
|
|
|
'''
|
2016-07-23 10:55:54 +00:00
|
|
|
_TESTS = [{
|
2021-01-01 12:26:37 +00:00
|
|
|
'url': 'https://video.qbrick.com/play2/embed/player?accountId=1034090&mediaId=d8ab4607-00090107-aab86310',
|
|
|
|
'md5': '97f117754e5f3c020f5f26da4a44ebaf',
|
2016-07-23 10:55:54 +00:00
|
|
|
'info_dict': {
|
2021-01-01 12:26:37 +00:00
|
|
|
'id': 'd8ab4607-00090107-aab86310',
|
2016-07-23 10:55:54 +00:00
|
|
|
'ext': 'mp4',
|
2021-01-01 12:26:37 +00:00
|
|
|
'title': 'EM_HT20_117_roslund_v2.mp4',
|
|
|
|
'timestamp': 1608285912,
|
|
|
|
'upload_date': '20201218',
|
|
|
|
'duration': 1429.162667,
|
|
|
|
'subtitles': {
|
|
|
|
'sv': 'count:3',
|
|
|
|
},
|
2016-07-23 10:55:54 +00:00
|
|
|
},
|
2021-01-01 12:26:37 +00:00
|
|
|
}, {
|
|
|
|
'url': 'https://play.arkena.com/embed/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411',
|
|
|
|
'only_matching': True,
|
2016-07-23 10:55:54 +00:00
|
|
|
}, {
|
|
|
|
'url': 'https://play.arkena.com/config/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411/?callbackMethod=jQuery1111023664739129262213_1469227693893',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'http://play.arkena.com/config/avp/v1/player/media/327336/darkmatter/131064/?callbackMethod=jQuery1111002221189684892677_1469227595972',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'http://play.arkena.com/embed/avp/v1/player/media/327336/darkmatter/131064/',
|
|
|
|
'only_matching': True,
|
2016-12-31 19:46:18 +00:00
|
|
|
}, {
|
|
|
|
'url': 'http://video.arkena.com/play2/embed/player?accountId=472718&mediaId=35763b3b-00090078-bf604299&pageStyling=styled',
|
|
|
|
'only_matching': True,
|
2016-07-23 10:55:54 +00:00
|
|
|
}]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _extract_url(webpage):
|
|
|
|
# See https://support.arkena.com/display/PLAY/Ways+to+embed+your+video
|
|
|
|
mobj = re.search(
|
|
|
|
r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//play\.arkena\.com/embed/avp/.+?)\1',
|
|
|
|
webpage)
|
|
|
|
if mobj:
|
|
|
|
return mobj.group('url')
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2021-08-19 01:41:24 +00:00
|
|
|
mobj = self._match_valid_url(url)
|
2016-07-23 10:55:54 +00:00
|
|
|
video_id = mobj.group('id')
|
|
|
|
account_id = mobj.group('account_id')
|
|
|
|
|
2016-12-31 19:46:18 +00:00
|
|
|
# Handle http://video.arkena.com/play2/embed/player URL
|
|
|
|
if not video_id:
|
2021-08-22 19:02:00 +00:00
|
|
|
qs = parse_qs(url)
|
2016-12-31 19:46:18 +00:00
|
|
|
video_id = qs.get('mediaId', [None])[0]
|
|
|
|
account_id = qs.get('accountId', [None])[0]
|
|
|
|
if not video_id or not account_id:
|
|
|
|
raise ExtractorError('Invalid URL', expected=True)
|
|
|
|
|
2021-01-01 12:26:37 +00:00
|
|
|
media = self._download_json(
|
|
|
|
'https://video.qbrick.com/api/v1/public/accounts/%s/medias/%s' % (account_id, video_id),
|
|
|
|
video_id, query={
|
|
|
|
# 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']
|
2016-07-23 10:55:54 +00:00
|
|
|
|
2021-01-01 12:26:37 +00:00
|
|
|
duration = None
|
2016-07-23 10:55:54 +00:00
|
|
|
formats = []
|
2021-01-01 12:26:37 +00:00
|
|
|
thumbnails = []
|
|
|
|
subtitles = {}
|
|
|
|
for resource in media['asset']['resources']:
|
|
|
|
for rendition in (resource.get('renditions') or []):
|
|
|
|
rendition_type = rendition.get('type')
|
|
|
|
for i, link in enumerate(rendition.get('links') or []):
|
|
|
|
href = link.get('href')
|
|
|
|
if not href:
|
|
|
|
continue
|
|
|
|
if rendition_type == 'image':
|
|
|
|
thumbnails.append({
|
|
|
|
'filesize': int_or_none(rendition.get('size')),
|
|
|
|
'height': int_or_none(rendition.get('height')),
|
|
|
|
'id': rendition.get('id'),
|
|
|
|
'url': href,
|
|
|
|
'width': int_or_none(rendition.get('width')),
|
|
|
|
})
|
|
|
|
elif rendition_type == 'subtitle':
|
|
|
|
subtitles.setdefault(rendition.get('language') or 'en', []).append({
|
|
|
|
'url': href,
|
|
|
|
})
|
|
|
|
elif rendition_type == 'video':
|
|
|
|
f = {
|
|
|
|
'filesize': int_or_none(rendition.get('size')),
|
|
|
|
'format_id': rendition.get('id'),
|
|
|
|
'url': href,
|
|
|
|
}
|
|
|
|
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))
|
2016-07-23 10:55:54 +00:00
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
2021-01-01 12:26:37 +00:00
|
|
|
'description': metadata.get('description'),
|
|
|
|
'timestamp': parse_iso8601(media.get('created')),
|
2016-07-23 10:55:54 +00:00
|
|
|
'thumbnails': thumbnails,
|
2021-01-01 12:26:37 +00:00
|
|
|
'subtitles': subtitles,
|
|
|
|
'duration': duration,
|
|
|
|
'tags': media.get('tags'),
|
2016-07-23 10:55:54 +00:00
|
|
|
'formats': formats,
|
|
|
|
}
|