]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/arkena.py
New upstream version 2016.12.01
[youtubedl] / youtube_dl / extractor / arkena.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 determine_ext,
9 float_or_none,
10 int_or_none,
11 mimetype2ext,
12 parse_iso8601,
13 strip_jsonp,
14 )
15
16
17 class ArkenaIE(InfoExtractor):
18 _VALID_URL = r'https?://play\.arkena\.com/(?:config|embed)/avp/v\d/player/media/(?P<id>[^/]+)/[^/]+/(?P<account_id>\d+)'
19 _TESTS = [{
20 'url': 'https://play.arkena.com/embed/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411',
21 'md5': 'b96f2f71b359a8ecd05ce4e1daa72365',
22 'info_dict': {
23 'id': 'b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe',
24 'ext': 'mp4',
25 'title': 'Big Buck Bunny',
26 'description': 'Royalty free test video',
27 'timestamp': 1432816365,
28 'upload_date': '20150528',
29 'is_live': False,
30 },
31 }, {
32 'url': 'https://play.arkena.com/config/avp/v2/player/media/b41dda37-d8e7-4d3f-b1b5-9a9db578bdfe/1/129411/?callbackMethod=jQuery1111023664739129262213_1469227693893',
33 'only_matching': True,
34 }, {
35 'url': 'http://play.arkena.com/config/avp/v1/player/media/327336/darkmatter/131064/?callbackMethod=jQuery1111002221189684892677_1469227595972',
36 'only_matching': True,
37 }, {
38 'url': 'http://play.arkena.com/embed/avp/v1/player/media/327336/darkmatter/131064/',
39 'only_matching': True,
40 }]
41
42 @staticmethod
43 def _extract_url(webpage):
44 # See https://support.arkena.com/display/PLAY/Ways+to+embed+your+video
45 mobj = re.search(
46 r'<iframe[^>]+src=(["\'])(?P<url>(?:https?:)?//play\.arkena\.com/embed/avp/.+?)\1',
47 webpage)
48 if mobj:
49 return mobj.group('url')
50
51 def _real_extract(self, url):
52 mobj = re.match(self._VALID_URL, url)
53 video_id = mobj.group('id')
54 account_id = mobj.group('account_id')
55
56 playlist = self._download_json(
57 'https://play.arkena.com/config/avp/v2/player/media/%s/0/%s/?callbackMethod=_'
58 % (video_id, account_id),
59 video_id, transform_source=strip_jsonp)['Playlist'][0]
60
61 media_info = playlist['MediaInfo']
62 title = media_info['Title']
63 media_files = playlist['MediaFiles']
64
65 is_live = False
66 formats = []
67 for kind_case, kind_formats in media_files.items():
68 kind = kind_case.lower()
69 for f in kind_formats:
70 f_url = f.get('Url')
71 if not f_url:
72 continue
73 is_live = f.get('Live') == 'true'
74 exts = (mimetype2ext(f.get('Type')), determine_ext(f_url, None))
75 if kind == 'm3u8' or 'm3u8' in exts:
76 formats.extend(self._extract_m3u8_formats(
77 f_url, video_id, 'mp4',
78 entry_protocol='m3u8' if is_live else 'm3u8_native',
79 m3u8_id=kind, fatal=False, live=is_live))
80 elif kind == 'flash' or 'f4m' in exts:
81 formats.extend(self._extract_f4m_formats(
82 f_url, video_id, f4m_id=kind, fatal=False))
83 elif kind == 'dash' or 'mpd' in exts:
84 formats.extend(self._extract_mpd_formats(
85 f_url, video_id, mpd_id=kind, fatal=False))
86 elif kind == 'silverlight':
87 # TODO: process when ism is supported (see
88 # https://github.com/rg3/youtube-dl/issues/8118)
89 continue
90 else:
91 tbr = float_or_none(f.get('Bitrate'), 1000)
92 formats.append({
93 'url': f_url,
94 'format_id': '%s-%d' % (kind, tbr) if tbr else kind,
95 'tbr': tbr,
96 })
97 self._sort_formats(formats)
98
99 description = media_info.get('Description')
100 video_id = media_info.get('VideoId') or video_id
101 timestamp = parse_iso8601(media_info.get('PublishDate'))
102 thumbnails = [{
103 'url': thumbnail['Url'],
104 'width': int_or_none(thumbnail.get('Size')),
105 } for thumbnail in (media_info.get('Poster') or []) if thumbnail.get('Url')]
106
107 return {
108 'id': video_id,
109 'title': title,
110 'description': description,
111 'timestamp': timestamp,
112 'is_live': is_live,
113 'thumbnails': thumbnails,
114 'formats': formats,
115 }