[jwplatform] Parse video_id from JWPlayer data

And remove a mysterious comma from 115c65793a
This commit is contained in:
Yen Chi Hsuan 2016-08-15 13:29:01 +08:00
parent 1a57b8c18c
commit b6c4e36728
No known key found for this signature in database
GPG Key ID: 3FDDD575826C5C30

View File

@ -30,7 +30,7 @@ def _extract_jwplayer_data(self, webpage, video_id, *args, **kwargs):
return self._parse_jwplayer_data( return self._parse_jwplayer_data(
jwplayer_data, video_id, *args, **kwargs) jwplayer_data, video_id, *args, **kwargs)
def _parse_jwplayer_data(self, jwplayer_data, video_id, require_title=True, m3u8_id=None, rtmp_params=None, base_url=None): def _parse_jwplayer_data(self, jwplayer_data, video_id=None, require_title=True, m3u8_id=None, rtmp_params=None, base_url=None):
# JWPlayer backward compatibility: flattened playlists # JWPlayer backward compatibility: flattened playlists
# https://github.com/jwplayer/jwplayer/blob/v7.4.3/src/js/api/config.js#L81-L96 # https://github.com/jwplayer/jwplayer/blob/v7.4.3/src/js/api/config.js#L81-L96
if 'playlist' not in jwplayer_data: if 'playlist' not in jwplayer_data:
@ -43,6 +43,8 @@ def _parse_jwplayer_data(self, jwplayer_data, video_id, require_title=True, m3u8
if 'sources' not in video_data: if 'sources' not in video_data:
video_data['sources'] = [video_data] video_data['sources'] = [video_data]
this_video_id = video_id or video_data['mediaid']
formats = [] formats = []
for source in video_data['sources']: for source in video_data['sources']:
source_url = self._proto_relative_url(source['file']) source_url = self._proto_relative_url(source['file'])
@ -52,7 +54,7 @@ def _parse_jwplayer_data(self, jwplayer_data, video_id, require_title=True, m3u8
ext = mimetype2ext(source_type) or determine_ext(source_url) ext = mimetype2ext(source_type) or determine_ext(source_url)
if source_type == 'hls' or ext == 'm3u8': if source_type == 'hls' or ext == 'm3u8':
formats.extend(self._extract_m3u8_formats( formats.extend(self._extract_m3u8_formats(
source_url, video_id, 'mp4', 'm3u8_native', m3u8_id=m3u8_id, fatal=False)) source_url, this_video_id, 'mp4', 'm3u8_native', m3u8_id=m3u8_id, fatal=False))
# https://github.com/jwplayer/jwplayer/blob/master/src/js/providers/default.js#L67 # https://github.com/jwplayer/jwplayer/blob/master/src/js/providers/default.js#L67
elif source_type.startswith('audio') or ext in ('oga', 'aac', 'mp3', 'mpeg', 'vorbis'): elif source_type.startswith('audio') or ext in ('oga', 'aac', 'mp3', 'mpeg', 'vorbis'):
formats.append({ formats.append({
@ -68,7 +70,7 @@ def _parse_jwplayer_data(self, jwplayer_data, video_id, require_title=True, m3u8
'ext': ext, 'ext': ext,
} }
if source_url.startswith('rtmp'): if source_url.startswith('rtmp'):
a_format['ext'] = 'flv', a_format['ext'] = 'flv'
# See com/longtailvideo/jwplayer/media/RTMPMediaProvider.as # See com/longtailvideo/jwplayer/media/RTMPMediaProvider.as
# of jwplayer.flash.swf # of jwplayer.flash.swf
@ -95,7 +97,7 @@ def _parse_jwplayer_data(self, jwplayer_data, video_id, require_title=True, m3u8
}) })
entries.append({ entries.append({
'id': video_id, 'id': this_video_id,
'title': video_data['title'] if require_title else video_data.get('title'), 'title': video_data['title'] if require_title else video_data.get('title'),
'description': video_data.get('description'), 'description': video_data.get('description'),
'thumbnail': self._proto_relative_url(video_data.get('image')), 'thumbnail': self._proto_relative_url(video_data.get('image')),