[ie/thisoldhouse] Fix login support (#15097)

Closes #14931
Authored by: bashonly
pull/15104/head
bashonly 2 weeks ago committed by GitHub
parent 854fded114
commit 9daba4f442
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,18 +1,17 @@
import json import urllib.parse
from .brightcove import BrightcoveNewIE from .brightcove import BrightcoveNewIE
from .common import InfoExtractor from .common import InfoExtractor
from .zype import ZypeIE from .zype import ZypeIE
from ..networking import HEADRequest from ..networking import HEADRequest
from ..networking.exceptions import HTTPError
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
filter_dict, filter_dict,
parse_qs, parse_qs,
smuggle_url, smuggle_url,
try_call,
urlencode_postdata, urlencode_postdata,
) )
from ..utils.traversal import traverse_obj
class ThisOldHouseIE(InfoExtractor): class ThisOldHouseIE(InfoExtractor):
@ -77,46 +76,43 @@ class ThisOldHouseIE(InfoExtractor):
'only_matching': True, 'only_matching': True,
}] }]
_LOGIN_URL = 'https://login.thisoldhouse.com/usernamepassword/login'
def _perform_login(self, username, password): def _perform_login(self, username, password):
self._request_webpage( login_page = self._download_webpage(
HEADRequest('https://www.thisoldhouse.com/insider'), None, 'Requesting session cookies') 'https://www.thisoldhouse.com/insider-login', None, 'Downloading login page')
urlh = self._request_webpage( hidden_inputs = self._hidden_inputs(login_page)
'https://www.thisoldhouse.com/wp-login.php', None, 'Requesting login info', response = self._download_json(
errnote='Unable to login', query={'redirect_to': 'https://www.thisoldhouse.com/insider'}) 'https://www.thisoldhouse.com/wp-admin/admin-ajax.php', None, 'Logging in',
headers={
try: 'Accept': 'application/json',
auth_form = self._download_webpage( 'X-Requested-With': 'XMLHttpRequest',
self._LOGIN_URL, None, 'Submitting credentials', headers={ }, data=urlencode_postdata(filter_dict({
'Content-Type': 'application/json', 'action': 'onebill_subscriber_login',
'Referer': urlh.url, 'email': username,
}, data=json.dumps(filter_dict({
**{('client_id' if k == 'client' else k): v[0] for k, v in parse_qs(urlh.url).items()},
'tenant': 'thisoldhouse',
'username': username,
'password': password, 'password': password,
'popup_options': {}, 'pricingPlanTerm': hidden_inputs['pricing_plan_term'],
'sso': True, 'utm_parameters': hidden_inputs.get('utm_parameters'),
'_csrf': try_call(lambda: self._get_cookies(self._LOGIN_URL)['_csrf'].value), 'nonce': hidden_inputs['mdcr_onebill_login_nonce'],
'_intstate': 'deprecated', })))
}), separators=(',', ':')).encode())
except ExtractorError as e:
if isinstance(e.cause, HTTPError) and e.cause.status == 401:
raise ExtractorError('Invalid username or password', expected=True)
raise
self._request_webpage( message = traverse_obj(response, ('data', 'message', {str}))
'https://login.thisoldhouse.com/login/callback', None, 'Completing login', if not response['success']:
data=urlencode_postdata(self._hidden_inputs(auth_form))) if message and 'Something went wrong' in message:
raise ExtractorError('Invalid username or password', expected=True)
raise ExtractorError(message or 'Login was unsuccessful')
if message and 'Your subscription is not active' in message:
self.report_warning(
f'{self.IE_NAME} said your subscription is not active. '
f'If your subscription is active, this could be caused by too many sign-ins, '
f'and you should instead try using {self._login_hint(method="cookies")[4:]}')
else:
self.write_debug(f'{self.IE_NAME} said: {message}')
def _real_extract(self, url): def _real_extract(self, url):
display_id = self._match_id(url) display_id = self._match_id(url)
webpage = self._download_webpage(url, display_id) webpage, urlh = self._download_webpage_handle(url, display_id)
if 'To Unlock This content' in webpage: # If login response says inactive subscription, site redirects to frontpage for Insider content
self.raise_login_required( if 'To Unlock This content' in webpage or urllib.parse.urlparse(urlh.url).path in ('', '/'):
'This video is only available for subscribers. ' self.raise_login_required('This video is only available for subscribers')
'Note that --cookies-from-browser may not work due to this site using session cookies')
video_url, video_id = self._search_regex( video_url, video_id = self._search_regex(
r'<iframe[^>]+src=[\'"]((?:https?:)?//(?:www\.)?thisoldhouse\.(?:chorus\.build|com)/videos/zype/([0-9a-f]{24})[^\'"]*)[\'"]', r'<iframe[^>]+src=[\'"]((?:https?:)?//(?:www\.)?thisoldhouse\.(?:chorus\.build|com)/videos/zype/([0-9a-f]{24})[^\'"]*)[\'"]',

Loading…
Cancel
Save