From 45d1f1572510b4b4cf8c97f204871838c1730996 Mon Sep 17 00:00:00 2001 From: Sipherdrakon <64430430+Sipherdrakon@users.noreply.github.com> Date: Thu, 29 Jul 2021 00:25:00 -0400 Subject: [PATCH] [dplay] Add `ScienceChannelIE` (#567) Authored by: Sipherdrakon --- yt_dlp/extractor/discoveryplusindia.py | 3 +- yt_dlp/extractor/dplay.py | 111 +++++++++++++++---------- yt_dlp/extractor/extractors.py | 1 + 3 files changed, 69 insertions(+), 46 deletions(-) diff --git a/yt_dlp/extractor/discoveryplusindia.py b/yt_dlp/extractor/discoveryplusindia.py index ee57bb2d0..4f2f4f731 100644 --- a/yt_dlp/extractor/discoveryplusindia.py +++ b/yt_dlp/extractor/discoveryplusindia.py @@ -63,8 +63,7 @@ class DiscoveryPlusIndiaShowIE(InfoExtractor): 'info_dict': { 'id': 'how-do-they-do-it', }, - } - ] + }] def _entries(self, show_name): headers = { diff --git a/yt_dlp/extractor/dplay.py b/yt_dlp/extractor/dplay.py index bbb199094..38b08d280 100644 --- a/yt_dlp/extractor/dplay.py +++ b/yt_dlp/extractor/dplay.py @@ -296,50 +296,6 @@ def _real_extract(self, url): url, display_id, host, 'dplay' + country, country) -class DiscoveryPlusIE(DPlayIE): - _VALID_URL = r'https?://(?:www\.)?discoveryplus\.com/video' + DPlayIE._PATH_REGEX - _TESTS = [{ - 'url': 'https://www.discoveryplus.com/video/property-brothers-forever-home/food-and-family', - 'info_dict': { - 'id': '1140794', - 'display_id': 'property-brothers-forever-home/food-and-family', - 'ext': 'mp4', - 'title': 'Food and Family', - 'description': 'The brothers help a Richmond family expand their single-level home.', - 'duration': 2583.113, - 'timestamp': 1609304400, - 'upload_date': '20201230', - 'creator': 'HGTV', - 'series': 'Property Brothers: Forever Home', - 'season_number': 1, - 'episode_number': 1, - }, - 'skip': 'Available for Premium users', - }] - - def _update_disco_api_headers(self, headers, disco_base, display_id, realm): - headers['x-disco-client'] = 'WEB:UNKNOWN:dplus_us:15.0.0' - - def _download_video_playback_info(self, disco_base, video_id, headers): - return self._download_json( - disco_base + 'playback/v3/videoPlaybackInfo', - video_id, headers=headers, data=json.dumps({ - 'deviceInfo': { - 'adBlocker': False, - }, - 'videoId': video_id, - 'wisteriaProperties': { - 'platform': 'desktop', - 'product': 'dplus_us', - }, - }).encode('utf-8'))['data']['attributes']['streaming'] - - def _real_extract(self, url): - display_id = self._match_id(url) - return self._get_disco_api_info( - url, display_id, 'us1-prod-direct.discoveryplus.com', 'go', 'us') - - class HGTVDeIE(DPlayIE): _VALID_URL = r'https?://de\.hgtv\.com/sendungen' + DPlayIE._PATH_REGEX _TESTS = [{ @@ -367,3 +323,70 @@ def _real_extract(self, url): display_id = self._match_id(url) return self._get_disco_api_info( url, display_id, 'eu1-prod.disco-api.com', 'hgtv', 'de') + + +class DiscoveryPlusIE(DPlayIE): + _VALID_URL = r'https?://(?:www\.)?discoveryplus\.com/video' + DPlayIE._PATH_REGEX + _TESTS = [{ + 'url': 'https://www.discoveryplus.com/video/property-brothers-forever-home/food-and-family', + 'info_dict': { + 'id': '1140794', + 'display_id': 'property-brothers-forever-home/food-and-family', + 'ext': 'mp4', + 'title': 'Food and Family', + 'description': 'The brothers help a Richmond family expand their single-level home.', + 'duration': 2583.113, + 'timestamp': 1609304400, + 'upload_date': '20201230', + 'creator': 'HGTV', + 'series': 'Property Brothers: Forever Home', + 'season_number': 1, + 'episode_number': 1, + }, + 'skip': 'Available for Premium users', + }] + + _PRODUCT = 'dplus_us' + _API_URL = 'us1-prod-direct.discoveryplus.com' + + def _update_disco_api_headers(self, headers, disco_base, display_id, realm): + headers['x-disco-client'] = f'WEB:UNKNOWN:{self._PRODUCT}:15.0.0' + + def _download_video_playback_info(self, disco_base, video_id, headers): + return self._download_json( + disco_base + 'playback/v3/videoPlaybackInfo', + video_id, headers=headers, data=json.dumps({ + 'deviceInfo': { + 'adBlocker': False, + }, + 'videoId': video_id, + 'wisteriaProperties': { + 'platform': 'desktop', + 'product': self._PRODUCT, + }, + }).encode('utf-8'))['data']['attributes']['streaming'] + + def _real_extract(self, url): + display_id = self._match_id(url) + return self._get_disco_api_info( + url, display_id, self._API_URL, 'go', 'us') + + +class ScienceChannelIE(DiscoveryPlusIE): + _VALID_URL = r'https?://(?:www\.)?sciencechannel\.com/video' + DPlayIE._PATH_REGEX + _TESTS = [{ + 'url': 'https://www.sciencechannel.com/video/strangest-things-science-atve-us/nazi-mystery-machine', + 'info_dict': { + 'id': '2842849', + 'display_id': 'strangest-things-science-atve-us/nazi-mystery-machine', + 'ext': 'mp4', + 'title': 'Nazi Mystery Machine', + 'description': 'Experts investigate the secrets of a revolutionary encryption machine.', + 'season_number': 1, + 'episode_number': 1, + }, + 'skip': 'Available for Premium users', + }] + + _PRODUCT = 'sci' + _API_URL = 'us1-prod-direct.sciencechannel.com' diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py index 991c36014..c0c613e14 100644 --- a/yt_dlp/extractor/extractors.py +++ b/yt_dlp/extractor/extractors.py @@ -330,6 +330,7 @@ DPlayIE, DiscoveryPlusIE, HGTVDeIE, + ScienceChannelIE ) from .dreisat import DreiSatIE from .drbonanza import DRBonanzaIE