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