2 from __future__ import unicode_literals
6 from .common import InfoExtractor
14 class JWPlatformBaseIE(InfoExtractor):
15 def _parse_jwplayer_data(self, jwplayer_data, video_id, require_title=True, m3u8_id=None, rtmp_params=None):
16 video_data = jwplayer_data['playlist'][0]
19 for source in video_data['sources']:
20 source_url = self._proto_relative_url(source['file'])
21 source_type = source.get('type') or ''
22 if source_type in ('application/vnd.apple.mpegurl', 'hls') or determine_ext(source_url) == 'm3u8':
23 formats.extend(self._extract_m3u8_formats(
24 source_url, video_id, 'mp4', 'm3u8_native', m3u8_id=m3u8_id, fatal=False))
25 elif source_type.startswith('audio'):
33 'width': int_or_none(source.get('width')),
34 'height': int_or_none(source.get('height')),
36 if source_url.startswith('rtmp'):
37 a_format['ext'] = 'flv',
39 # See com/longtailvideo/jwplayer/media/RTMPMediaProvider.as
40 # of jwplayer.flash.swf
41 rtmp_url_parts = re.split(
42 r'((?:mp4|mp3|flv):)', source_url, 1)
43 if len(rtmp_url_parts) == 3:
44 rtmp_url, prefix, play_path = rtmp_url_parts
47 'play_path': prefix + play_path,
50 a_format.update(rtmp_params)
51 formats.append(a_format)
52 self._sort_formats(formats)
55 tracks = video_data.get('tracks')
56 if tracks and isinstance(tracks, list):
58 if track.get('file') and track.get('kind') == 'captions':
59 subtitles.setdefault(track.get('label') or 'en', []).append({
60 'url': self._proto_relative_url(track['file'])
65 'title': video_data['title'] if require_title else video_data.get('title'),
66 'description': video_data.get('description'),
67 'thumbnail': self._proto_relative_url(video_data.get('image')),
68 'timestamp': int_or_none(video_data.get('pubdate')),
69 'duration': float_or_none(jwplayer_data.get('duration')),
70 'subtitles': subtitles,
75 class JWPlatformIE(JWPlatformBaseIE):
76 _VALID_URL = r'(?:https?://content\.jwplatform\.com/(?:feeds|players|jw6)/|jwplatform:)(?P<id>[a-zA-Z0-9]{8})'
78 'url': 'http://content.jwplatform.com/players/nPripu9l-ALJ3XQCI.js',
79 'md5': 'fa8899fa601eb7c83a64e9d568bdf325',
83 'title': 'Big Buck Bunny Trailer',
84 'description': 'Big Buck Bunny is a short animated film by the Blender Institute. It is made using free and open source software.',
85 'upload_date': '20081127',
86 'timestamp': 1227796140,
91 def _extract_url(webpage):
93 r'<script[^>]+?src=["\'](?P<url>(?:https?:)?//content.jwplatform.com/players/[a-zA-Z0-9]{8})',
96 return mobj.group('url')
98 def _real_extract(self, url):
99 video_id = self._match_id(url)
100 json_data = self._download_json('http://content.jwplatform.com/feeds/%s.json' % video_id, video_id)
101 return self._parse_jwplayer_data(json_data, video_id)