]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/jwplatform.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class JWPlatformBaseIE(InfoExtractor
):
16 def _find_jwplayer_data(webpage
):
17 # TODO: Merge this with JWPlayer-related codes in generic.py
20 'jwplayer\((?P<quote>[\'"])[^\'" ]+(?P=quote)\)\.setup\((?P<options>[^)]+)\)',
23 return mobj
.group('options')
25 def _extract_jwplayer_data(self
, webpage
, video_id
, *args
, **kwargs
):
26 jwplayer_data
= self
._parse
_json
(
27 self
._find
_jwplayer
_data
(webpage
), video_id
)
28 return self
._parse
_jwplayer
_data
(
29 jwplayer_data
, video_id
, *args
, **kwargs
)
31 def _parse_jwplayer_data(self
, jwplayer_data
, video_id
, require_title
=True, m3u8_id
=None, rtmp_params
=None):
32 # JWPlayer backward compatibility: flattened playlists
33 # https://github.com/jwplayer/jwplayer/blob/v7.4.3/src/js/api/config.js#L81-L96
34 if 'playlist' not in jwplayer_data
:
35 jwplayer_data
= {'playlist': [jwplayer_data
]}
37 video_data
= jwplayer_data
['playlist'][0]
39 # JWPlayer backward compatibility: flattened sources
40 # https://github.com/jwplayer/jwplayer/blob/v7.4.3/src/js/playlist/item.js#L29-L35
41 if 'sources' not in video_data
:
42 video_data
['sources'] = [video_data
]
45 for source
in video_data
['sources']:
46 source_url
= self
._proto
_relative
_url
(source
['file'])
47 source_type
= source
.get('type') or ''
48 if source_type
in ('application/vnd.apple.mpegurl', 'hls') or determine_ext(source_url
) == 'm3u8':
49 formats
.extend(self
._extract
_m
3u8_formats
(
50 source_url
, video_id
, 'mp4', 'm3u8_native', m3u8_id
=m3u8_id
, fatal
=False))
51 elif source_type
.startswith('audio'):
59 'width': int_or_none(source
.get('width')),
60 'height': int_or_none(source
.get('height')),
62 if source_url
.startswith('rtmp'):
63 a_format
['ext'] = 'flv',
65 # See com/longtailvideo/jwplayer/media/RTMPMediaProvider.as
66 # of jwplayer.flash.swf
67 rtmp_url_parts
= re
.split(
68 r
'((?:mp4|mp3|flv):)', source_url
, 1)
69 if len(rtmp_url_parts
) == 3:
70 rtmp_url
, prefix
, play_path
= rtmp_url_parts
73 'play_path': prefix
+ play_path
,
76 a_format
.update(rtmp_params
)
77 formats
.append(a_format
)
78 self
._sort
_formats
(formats
)
81 tracks
= video_data
.get('tracks')
82 if tracks
and isinstance(tracks
, list):
84 if track
.get('file') and track
.get('kind') == 'captions':
85 subtitles
.setdefault(track
.get('label') or 'en', []).append({
86 'url': self
._proto
_relative
_url
(track
['file'])
91 'title': video_data
['title'] if require_title
else video_data
.get('title'),
92 'description': video_data
.get('description'),
93 'thumbnail': self
._proto
_relative
_url
(video_data
.get('image')),
94 'timestamp': int_or_none(video_data
.get('pubdate')),
95 'duration': float_or_none(jwplayer_data
.get('duration')),
96 'subtitles': subtitles
,
101 class JWPlatformIE(JWPlatformBaseIE
):
102 _VALID_URL
= r
'(?:https?://content\.jwplatform\.com/(?:feeds|players|jw6)/|jwplatform:)(?P<id>[a-zA-Z0-9]{8})'
104 'url': 'http://content.jwplatform.com/players/nPripu9l-ALJ3XQCI.js',
105 'md5': 'fa8899fa601eb7c83a64e9d568bdf325',
109 'title': 'Big Buck Bunny Trailer',
110 'description': 'Big Buck Bunny is a short animated film by the Blender Institute. It is made using free and open source software.',
111 'upload_date': '20081127',
112 'timestamp': 1227796140,
117 def _extract_url(webpage
):
119 r
'<script[^>]+?src=["\'](?P
<url
>(?
:https?
:)?
//content
.jwplatform
.com
/players
/[a
-zA
-Z0
-9]{8}
)',
122 return mobj.group('url
')
124 def _real_extract(self, url):
125 video_id = self._match_id(url)
126 json_data = self._download_json('http
://content
.jwplatform
.com
/feeds
/%s.json
' % video_id, video_id)
127 return self._parse_jwplayer_data(json_data, video_id)