2 from __future__ import unicode_literals
6 from .common import InfoExtractor
13 class JWPlatformBaseIE(InfoExtractor):
14 def _parse_jwplayer_data(self, jwplayer_data, video_id, require_title=True):
15 video_data = jwplayer_data['playlist'][0]
17 for track in video_data['tracks']:
18 if track['kind'] == 'captions':
19 subtitles[track['label']] = [{'url': self._proto_relative_url(track['file'])}]
22 for source in video_data['sources']:
23 source_url = self._proto_relative_url(source['file'])
24 source_type = source.get('type') or ''
25 if source_type in ('application/vnd.apple.mpegurl', 'hls'):
26 formats.extend(self._extract_m3u8_formats(
27 source_url, video_id, 'mp4', 'm3u8_native', fatal=False))
28 elif source_type.startswith('audio'):
36 'width': int_or_none(source.get('width')),
37 'height': int_or_none(source.get('height')),
39 self._sort_formats(formats)
43 'title': video_data['title'] if require_title else video_data.get('title'),
44 'description': video_data.get('description'),
45 'thumbnail': self._proto_relative_url(video_data.get('image')),
46 'timestamp': int_or_none(video_data.get('pubdate')),
47 'duration': float_or_none(jwplayer_data.get('duration')),
48 'subtitles': subtitles,
53 class JWPlatformIE(JWPlatformBaseIE):
54 _VALID_URL = r'(?:https?://content\.jwplatform\.com/(?:feeds|players|jw6)/|jwplatform:)(?P<id>[a-zA-Z0-9]{8})'
56 'url': 'http://content.jwplatform.com/players/nPripu9l-ALJ3XQCI.js',
57 'md5': 'fa8899fa601eb7c83a64e9d568bdf325',
61 'title': 'Big Buck Bunny Trailer',
62 'description': 'Big Buck Bunny is a short animated film by the Blender Institute. It is made using free and open source software.',
63 'upload_date': '20081127',
64 'timestamp': 1227796140,
69 def _extract_url(webpage):
71 r'<script[^>]+?src=["\'](?P<url>(?:https?:)?//content.jwplatform.com/players/[a-zA-Z0-9]{8})',
74 return mobj.group('url')
76 def _real_extract(self, url):
77 video_id = self._match_id(url)
78 json_data = self._download_json('http://content.jwplatform.com/feeds/%s.json' % video_id, video_id)
79 return self._parse_jwplayer_data(json_data, video_id)