From 082893d66df40b15af8308b24acdaec0a62c4f73 Mon Sep 17 00:00:00 2001 From: JCGoran Date: Wed, 20 Sep 2017 18:56:26 +0000 Subject: [PATCH 1/2] Update cnbc.py --- youtube_dl/extractor/cnbc.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/youtube_dl/extractor/cnbc.py b/youtube_dl/extractor/cnbc.py index d354d9f95..129296e4d 100644 --- a/youtube_dl/extractor/cnbc.py +++ b/youtube_dl/extractor/cnbc.py @@ -1,14 +1,19 @@ # coding: utf-8 from __future__ import unicode_literals +import re + from .common import InfoExtractor -from ..utils import smuggle_url +from ..utils import ( + smuggle_url, + js_to_json, +) class CNBCIE(InfoExtractor): - _VALID_URL = r'https?://video\.cnbc\.com/gallery/\?video=(?P[0-9]+)' + _VALID_URL = r'https?://www\.cnbc\.com/video/[0-9]{4}/[0-9]{2}/[0-9]{2}/(?P.+)\.html' _TEST = { - 'url': 'http://video.cnbc.com/gallery/?video=3000503714', + 'url': 'https://www.cnbc.com/video/2016/03/30/fighting-zombies-is-big-business.html', 'info_dict': { 'id': '3000503714', 'ext': 'mp4', @@ -25,12 +30,23 @@ class CNBCIE(InfoExtractor): } def _real_extract(self, url): - video_id = self._match_id(url) + mob = re.search(self._VALID_URL, url) + video_id = mob.group('title') + webpage = self._download_webpage(url, video_id) + mobj = re.search( + r'mpscall\s*=\s*(?P<json_data>[^)]+),\s*mpsopts', + webpage) + if mobj is None: + raise ExtractorError('Unable to extract video urls') + + urls_info = self._parse_json( + mobj.group('json_data'), video_id, transform_source = js_to_json) + return { '_type': 'url_transparent', 'ie_key': 'ThePlatform', 'url': smuggle_url( - 'http://link.theplatform.com/s/gZWlPC/media/guid/2408950221/%s?mbr=true&manifest=m3u' % video_id, + 'http://link.theplatform.com/s/gZWlPC/media/guid/2408950221/%s?mbr=true&manifest=m3u' % urls_info.get('content_id'), {'force_smil_url': True}), - 'id': video_id, + 'id': urls_info.get('content_id'), } From c081ea0d825cca6b2dc0fccc8688f5810f72f1b1 Mon Sep 17 00:00:00 2001 From: JCGoran <JCGoran@users.noreply.github.com> Date: Wed, 20 Sep 2017 22:00:42 +0000 Subject: [PATCH 2/2] Fix for CNBC videos --- youtube_dl/extractor/cnbc.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/youtube_dl/extractor/cnbc.py b/youtube_dl/extractor/cnbc.py index 129296e4d..58e353dfc 100644 --- a/youtube_dl/extractor/cnbc.py +++ b/youtube_dl/extractor/cnbc.py @@ -1,8 +1,6 @@ # coding: utf-8 from __future__ import unicode_literals -import re - from .common import InfoExtractor from ..utils import ( smuggle_url, @@ -11,7 +9,7 @@ from ..utils import ( class CNBCIE(InfoExtractor): - _VALID_URL = r'https?://www\.cnbc\.com/video/[0-9]{4}/[0-9]{2}/[0-9]{2}/(?P<title>.+)\.html' + _VALID_URL = r'https?://www\.cnbc\.com/video/[0-9]{4}/[0-9]{2}/[0-9]{2}/(?P<id>.+)\.html' _TEST = { 'url': 'https://www.cnbc.com/video/2016/03/30/fighting-zombies-is-big-business.html', 'info_dict': { @@ -30,23 +28,22 @@ class CNBCIE(InfoExtractor): } def _real_extract(self, url): - mob = re.search(self._VALID_URL, url) - video_id = mob.group('title') + video_id = self._match_id(url) webpage = self._download_webpage(url, video_id) - mobj = re.search( + video_url = self._search_regex( r'mpscall\s*=\s*(?P<json_data>[^)]+),\s*mpsopts', - webpage) - if mobj is None: + webpage, 'json_data') + if video_url is None: raise ExtractorError('Unable to extract video urls') urls_info = self._parse_json( - mobj.group('json_data'), video_id, transform_source = js_to_json) + video_url, video_id, transform_source = js_to_json) return { '_type': 'url_transparent', 'ie_key': 'ThePlatform', 'url': smuggle_url( - 'http://link.theplatform.com/s/gZWlPC/media/guid/2408950221/%s?mbr=true&manifest=m3u' % urls_info.get('content_id'), + 'http://link.theplatform.com/s/gZWlPC/media/guid/2408950221/%s?mbr=true&manifest=m3u' % urls_info['content_id'], {'force_smil_url': True}), - 'id': urls_info.get('content_id'), + 'id': urls_info['content_id'], }