summary refs log tree commit diff
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2016-06-16 12:26:45 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2016-06-16 12:26:45 +0800
commit369ff750812ff874a0f4b4ceebb15a024e2f0a9d (patch)
tree0dd9ef8dad7950203767d0f5ead0c17707b53178
parent47212f7bcbd59af40f91796562a6b72ba0439ac4 (diff)
downloadyoutube-dl-369ff750812ff874a0f4b4ceebb15a024e2f0a9d.tar.gz
youtube-dl-369ff750812ff874a0f4b4ceebb15a024e2f0a9d.tar.xz
youtube-dl-369ff750812ff874a0f4b4ceebb15a024e2f0a9d.zip
[jwplatform] Improved JWPlayer support
-rw-r--r--youtube_dl/extractor/jwplatform.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/youtube_dl/extractor/jwplatform.py b/youtube_dl/extractor/jwplatform.py
index fa6f335e1..e44e31104 100644
--- a/youtube_dl/extractor/jwplatform.py
+++ b/youtube_dl/extractor/jwplatform.py
@@ -12,9 +12,35 @@ from ..utils import (
 
 
 class JWPlatformBaseIE(InfoExtractor):
+    @staticmethod
+    def _find_jwplayer_data(webpage):
+        # TODO: Merge this with JWPlayer-related codes in generic.py
+
+        mobj = re.search(
+            'jwplayer\((?P<quote>[\'"])[^\'" ]+(?P=quote)\)\.setup\((?P<options>[^)]+)\)',
+            webpage)
+        if mobj:
+            return mobj.group('options')
+
+    def _extract_jwplayer_data(self, webpage, video_id, *args, **kwargs):
+        jwplayer_data = self._parse_json(
+            self._find_jwplayer_data(webpage), video_id)
+        return self._parse_jwplayer_data(
+            jwplayer_data, video_id, *args, **kwargs)
+
     def _parse_jwplayer_data(self, jwplayer_data, video_id, require_title=True, m3u8_id=None, rtmp_params=None):
+        # JWPlayer backward compatibility: flattened playlists
+        # https://github.com/jwplayer/jwplayer/blob/v7.4.3/src/js/api/config.js#L81-L96
+        if 'playlist' not in jwplayer_data:
+            jwplayer_data = {'playlist': [jwplayer_data]}
+
         video_data = jwplayer_data['playlist'][0]
 
+        # JWPlayer backward compatibility: flattened sources
+        # https://github.com/jwplayer/jwplayer/blob/v7.4.3/src/js/playlist/item.js#L29-L35
+        if 'sources' not in video_data:
+            video_data['sources'] = [video_data]
+
         formats = []
         for source in video_data['sources']:
             source_url = self._proto_relative_url(source['file'])