]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/jwplatform.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_urlparse
16 class JWPlatformBaseIE(InfoExtractor
):
18 def _find_jwplayer_data(webpage
):
19 # TODO: Merge this with JWPlayer-related codes in generic.py
22 'jwplayer\((?P<quote>[\'"])[^\'" ]+(?P=quote)\)\.setup\((?P<options>[^)]+)\)',
25 return mobj
.group('options')
27 def _extract_jwplayer_data(self
, webpage
, video_id
, *args
, **kwargs
):
28 jwplayer_data
= self
._parse
_json
(
29 self
._find
_jwplayer
_data
(webpage
), video_id
)
30 return self
._parse
_jwplayer
_data
(
31 jwplayer_data
, video_id
, *args
, **kwargs
)
33 def _parse_jwplayer_data(self
, jwplayer_data
, video_id
=None, require_title
=True, m3u8_id
=None, rtmp_params
=None, base_url
=None):
34 # JWPlayer backward compatibility: flattened playlists
35 # https://github.com/jwplayer/jwplayer/blob/v7.4.3/src/js/api/config.js#L81-L96
36 if 'playlist' not in jwplayer_data
:
37 jwplayer_data
= {'playlist': [jwplayer_data
]}
40 for video_data
in jwplayer_data
['playlist']:
41 # JWPlayer backward compatibility: flattened sources
42 # https://github.com/jwplayer/jwplayer/blob/v7.4.3/src/js/playlist/item.js#L29-L35
43 if 'sources' not in video_data
:
44 video_data
['sources'] = [video_data
]
46 this_video_id
= video_id
or video_data
['mediaid']
49 for source
in video_data
['sources']:
50 source_url
= self
._proto
_relative
_url
(source
['file'])
52 source_url
= compat_urlparse
.urljoin(base_url
, source_url
)
53 source_type
= source
.get('type') or ''
54 ext
= mimetype2ext(source_type
) or determine_ext(source_url
)
55 if source_type
== 'hls' or ext
== 'm3u8':
56 formats
.extend(self
._extract
_m
3u8_formats
(
57 source_url
, this_video_id
, 'mp4', 'm3u8_native', m3u8_id
=m3u8_id
, fatal
=False))
58 # https://github.com/jwplayer/jwplayer/blob/master/src/js/providers/default.js#L67
59 elif source_type
.startswith('audio') or ext
in ('oga', 'aac', 'mp3', 'mpeg', 'vorbis'):
68 'width': int_or_none(source
.get('width')),
69 'height': int_or_none(source
.get('height')),
72 if source_url
.startswith('rtmp'):
73 a_format
['ext'] = 'flv'
75 # See com/longtailvideo/jwplayer/media/RTMPMediaProvider.as
76 # of jwplayer.flash.swf
77 rtmp_url_parts
= re
.split(
78 r
'((?:mp4|mp3|flv):)', source_url
, 1)
79 if len(rtmp_url_parts
) == 3:
80 rtmp_url
, prefix
, play_path
= rtmp_url_parts
83 'play_path': prefix
+ play_path
,
86 a_format
.update(rtmp_params
)
87 formats
.append(a_format
)
88 self
._sort
_formats
(formats
)
91 tracks
= video_data
.get('tracks')
92 if tracks
and isinstance(tracks
, list):
94 if track
.get('file') and track
.get('kind') == 'captions':
95 subtitles
.setdefault(track
.get('label') or 'en', []).append({
96 'url': self
._proto
_relative
_url
(track
['file'])
101 'title': video_data
['title'] if require_title
else video_data
.get('title'),
102 'description': video_data
.get('description'),
103 'thumbnail': self
._proto
_relative
_url
(video_data
.get('image')),
104 'timestamp': int_or_none(video_data
.get('pubdate')),
105 'duration': float_or_none(jwplayer_data
.get('duration')),
106 'subtitles': subtitles
,
109 if len(entries
) == 1:
112 return self
.playlist_result(entries
)
115 class JWPlatformIE(JWPlatformBaseIE
):
116 _VALID_URL
= r
'(?:https?://content\.jwplatform\.com/(?:feeds|players|jw6)/|jwplatform:)(?P<id>[a-zA-Z0-9]{8})'
118 'url': 'http://content.jwplatform.com/players/nPripu9l-ALJ3XQCI.js',
119 'md5': 'fa8899fa601eb7c83a64e9d568bdf325',
123 'title': 'Big Buck Bunny Trailer',
124 'description': 'Big Buck Bunny is a short animated film by the Blender Institute. It is made using free and open source software.',
125 'upload_date': '20081127',
126 'timestamp': 1227796140,
131 def _extract_url(webpage
):
133 r
'<script[^>]+?src=["\'](?P
<url
>(?
:https?
:)?
//content
.jwplatform
.com
/players
/[a
-zA
-Z0
-9]{8}
)',
136 return mobj.group('url
')
138 def _real_extract(self, url):
139 video_id = self._match_id(url)
140 json_data = self._download_json('http
://content
.jwplatform
.com
/feeds
/%s.json
' % video_id, video_id)
141 return self._parse_jwplayer_data(json_data, video_id)