From 379cf9472683da96a65397604df19fdc3eecebed Mon Sep 17 00:00:00 2001 From: Joshua McKinney Date: Fri, 20 Jan 2017 19:44:08 -0600 Subject: [PATCH] [nhl] add --auth-provider option to support rogers logins Addresses https://github.com/rg3/youtube-dl/pull/11366#issuecomment-271127084 --- README.md | 1 + youtube_dl/YoutubeDL.py | 1 + youtube_dl/__init__.py | 1 + youtube_dl/extractor/common.py | 10 ++++++++ youtube_dl/extractor/nhl.py | 43 ++++++++++++++++++++++++++++------ youtube_dl/options.py | 4 ++++ 6 files changed, 53 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ea9131c3a..b75750858 100644 --- a/README.md +++ b/README.md @@ -357,6 +357,7 @@ which means you can modify it, redistribute it or use it however you like. -2, --twofactor TWOFACTOR Two-factor auth code -n, --netrc Use .netrc authentication data --video-password PASSWORD Video password (vimeo, smotri, youku) + --auth-provider PROVIDER Authentication provider (nhl, rogers) ## Adobe Pass Options: --ap-mso MSO Adobe Pass multiple-system operator (TV diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 53f20ac2c..d0357ea88 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -131,6 +131,7 @@ class YoutubeDL(object): username: Username for authentication purposes. password: Password for authentication purposes. videopassword: Password for accessing a video. + auth_provider: Authentication provider ap_mso: Adobe Pass multiple-system operator identifier. ap_username: Multiple-system operator account username. ap_password: Multiple-system operator account password. diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 6850d95e1..fe58d1fea 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -300,6 +300,7 @@ def _real_main(argv=None): 'password': opts.password, 'twofactor': opts.twofactor, 'videopassword': opts.videopassword, + 'auth_provider': opts.auth_provider, 'ap_mso': opts.ap_mso, 'ap_username': opts.ap_username, 'ap_password': opts.ap_password, diff --git a/youtube_dl/extractor/common.py b/youtube_dl/extractor/common.py index 05c51fac9..b18f51c20 100644 --- a/youtube_dl/extractor/common.py +++ b/youtube_dl/extractor/common.py @@ -715,6 +715,16 @@ class InfoExtractor(object): return username, password + def _get_auth_provider(self): + """ + Get the authentication provider (e.g. nhl / rogers) + """ + if self._downloader is None: + return None + + downloader_params = self._downloader.params + return downloader_params.get('auth_provider') + def _get_tfa_info(self, note='two-factor verification code'): """ Get the two-factor authentication info diff --git a/youtube_dl/extractor/nhl.py b/youtube_dl/extractor/nhl.py index 111be6344..46c699f07 100644 --- a/youtube_dl/extractor/nhl.py +++ b/youtube_dl/extractor/nhl.py @@ -359,7 +359,8 @@ class NHLTVIE(InfoExtractor): IE_NAME = 'nhl.com:nhltv' _VALID_URL = r'https?://(?:www\.)?nhl.com/tv/(?P\d+)(/[^/]+)*(/(?P\d+))?' _OAUTH_URL = 'https://user.svc.nhl.com/oauth/token?grant_type=client_credentials' - _LOGIN_URL = 'https://gateway.web.nhl.com/ws/subscription/flow/nhlPurchase.login' + _NHL_LOGIN_URL = 'https://gateway.web.nhl.com/ws/subscription/flow/nhlPurchase.login' + _ROGERS_LOGIN_URL = 'https://activation-rogers.svc.nhl.com/ws/subscription/flow/rogers.login-check' _NETRC_MACHINE = 'nhltv' _TESTS = [{ # This is a free video that can be accessed by anyone with an NHL TV login @@ -409,24 +410,52 @@ class NHLTVIE(InfoExtractor): 'Unable to get OAuth access token') access_token = oauth_response['access_token'] + auth_provider = self._get_auth_provider() + if auth_provider == 'rogers': + login_request = self._create_rogers_login_request(username, password, access_token) + elif auth_provider == 'nhl' or auth_provider is None: + login_request = self._create_nhl_login_request(username, password, access_token) + else: + raise ExtractorError('Unknown authentication provider: %s. Valid values are nhl, rogers' % auth_provider) + + # sets up the cookies we need to download + self._download_webpage( + login_request, None, 'Logging in', 'Unable to log in') + + def _create_nhl_login_request(self, username, password, access_token): login_data = { 'nhlCredentials': { 'email': username, 'password': password, } } - login_request = sanitized_Request( - self._LOGIN_URL, + return sanitized_Request( + self._NHL_LOGIN_URL, data=json.dumps(login_data, sort_keys=True).encode('utf-8'), headers={ - 'Referer': 'https://www.nhl.com/login', + 'Referer': 'https://www.nhl.com/login/nhl', + 'Accept': 'application/json, text/javascript, */*; q=0.01', + 'Authorization': access_token, + 'Content-Type': 'application/json' + }) + + + def _create_rogers_login_request(self, username, password, access_token): + login_data = { + 'rogerCredentials': { + 'email': username, + 'password': password, + } + } + return sanitized_Request( + self._ROGERS_LOGIN_URL, + data=json.dumps(login_data, sort_keys=True).encode('utf-8'), + headers={ + 'Referer': 'https://www.nhl.com/login/rogers', 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Authorization': access_token, 'Content-Type': 'application/json' }) - # sets up the cookies we need to download - self._download_webpage( - login_request, None, 'Logging in', 'Unable to log in') def _real_initialize(self): self._login() diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 53497fbc6..0c39cff80 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -350,6 +350,10 @@ def parseOpts(overrideArguments=None): '--video-password', dest='videopassword', metavar='PASSWORD', help='Video password (vimeo, smotri, youku)') + authentication.add_option( + '--auth-provider', + dest='auth_provider', metavar='AUTH_PROVIDER', + help='Authentication provider (nhl, rogers, ...)') adobe_pass = optparse.OptionGroup(parser, 'Adobe Pass Options') adobe_pass.add_option(