From 02f4d4e44f0b0ec7c4a1e0b3d991e068c5f5e86e Mon Sep 17 00:00:00 2001 From: John Hawkinson Date: Mon, 10 Oct 2016 10:55:42 -0400 Subject: [PATCH] Move JWPlayer JSON array handling to IQM2 Out of @yan12125's concern that the presumption that JWPlayer data as an array representing multiple formats rather than a playlist might be specific to IQM2, move this code from jwplatform.py to iqm2.py. JWPlatformBase now reverts to throwing a TypeError if it gets an array. Now IQM2 redefines the _extract_jwplayer_data() method as well, but it continues to leverage JWPlatformBase for _parse_jwplayer_data(), which is the bulk of the work. --- youtube_dl/extractor/iqm2.py | 14 +++++++++++++- youtube_dl/extractor/jwplatform.py | 6 +----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/youtube_dl/extractor/iqm2.py b/youtube_dl/extractor/iqm2.py index ee3b46450..367aec9ff 100644 --- a/youtube_dl/extractor/iqm2.py +++ b/youtube_dl/extractor/iqm2.py @@ -1,12 +1,12 @@ # coding: utf-8 from __future__ import unicode_literals -from ..utils import smuggle_url import re from .common import InfoExtractor from ..compat import compat_urlparse from .jwplatform import JWPlatformBaseIE +from ..utils import js_to_json # IQM2 aka Accela is a municipal meeting management platform that # (among other things) stores livestreamed video from municipal @@ -63,6 +63,18 @@ class IQM2IE(JWPlatformBaseIE): 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, + transform_source=js_to_json) + + assert(isinstance(jwplayer_data, list)) + jwplayer_data = {'sources': jwplayer_data } + jwplayer_data['tracks'] = jwplayer_data['sources'][0].get('tracks') + + return self._parse_jwplayer_data( + jwplayer_data, video_id, *args, **kwargs) + def _real_extract(self, url): parent_id = self._match_id(url) webpage = self._download_webpage(url, parent_id) diff --git a/youtube_dl/extractor/jwplatform.py b/youtube_dl/extractor/jwplatform.py index ff7097160..ea848f529 100644 --- a/youtube_dl/extractor/jwplatform.py +++ b/youtube_dl/extractor/jwplatform.py @@ -50,11 +50,7 @@ class JWPlatformBaseIE(InfoExtractor): # 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: - if isinstance(video_data, list): - video_data = {'sources': video_data } - video_data['tracks'] = video_data['sources'][0].get('tracks') - else: - video_data['sources'] = [video_data] + video_data['sources'] = [video_data] this_video_id = video_id or video_data['mediaid']