3 from .common
import InfoExtractor
4 from .zype
import ZypeIE
5 from ..networking
import HEADRequest
6 from ..networking
.exceptions
import HTTPError
16 class ThisOldHouseIE(InfoExtractor
):
17 _NETRC_MACHINE
= 'thisoldhouse'
18 _VALID_URL
= r
'https?://(?:www\.)?thisoldhouse\.com/(?:watch|how-to|tv-episode|(?:[^/?#]+/)?\d+)/(?P<id>[^/?#]+)'
20 'url': 'https://www.thisoldhouse.com/furniture/21017078/how-to-build-a-storage-bench',
22 'id': '5dcdddf673c3f956ef5db202',
24 'title': 'How to Build a Storage Bench',
25 'description': 'In the workshop, Tom Silva and Kevin O\'Connor build a storage bench for an entryway.',
26 'timestamp': 1442548800,
27 'upload_date': '20150918',
31 'thumbnail': r
're:^https?://.*\.jpg\?\d+$',
32 'display_id': 'how-to-build-a-storage-bench',
35 'skip_download': True,
38 # Page no longer has video
39 'url': 'https://www.thisoldhouse.com/watch/arlington-arts-crafts-arts-and-crafts-class-begins',
40 'only_matching': True,
43 'url': 'https://www.thisoldhouse.com/tv-episode/ask-toh-shelf-rough-electric',
44 'only_matching': True,
47 'url': 'https://www.thisoldhouse.com/how-to/how-to-build-storage-bench',
48 'only_matching': True,
50 'url': 'https://www.thisoldhouse.com/21113884/s41-e13-paradise-lost',
51 'only_matching': True,
53 # iframe www.thisoldhouse.com
54 'url': 'https://www.thisoldhouse.com/21083431/seaside-transformation-the-westerly-project',
55 'only_matching': True,
58 _LOGIN_URL
= 'https://login.thisoldhouse.com/usernamepassword/login'
60 def _perform_login(self
, username
, password
):
61 self
._request
_webpage
(
62 HEADRequest('https://www.thisoldhouse.com/insider'), None, 'Requesting session cookies')
63 urlh
= self
._request
_webpage
(
64 'https://www.thisoldhouse.com/wp-login.php', None, 'Requesting login info',
65 errnote
='Unable to login', query
={'redirect_to': 'https://www.thisoldhouse.com/insider'}
)
68 auth_form
= self
._download
_webpage
(
69 self
._LOGIN
_URL
, None, 'Submitting credentials', headers
={
70 'Content-Type': 'application/json',
72 }, data
=json
.dumps(filter_dict({
73 **{('client_id' if k == 'client' else k): v[0] for k, v in parse_qs(urlh.url).items()}
,
74 'tenant': 'thisoldhouse',
79 '_csrf': try_call(lambda: self
._get
_cookies
(self
._LOGIN
_URL
)['_csrf'].value
),
80 '_intstate': 'deprecated',
81 }), separators
=(',', ':')).encode())
82 except ExtractorError
as e
:
83 if isinstance(e
.cause
, HTTPError
) and e
.cause
.status
== 401:
84 raise ExtractorError('Invalid username or password', expected
=True)
87 self
._request
_webpage
(
88 'https://login.thisoldhouse.com/login/callback', None, 'Completing login',
89 data
=urlencode_postdata(self
._hidden
_inputs
(auth_form
)))
91 def _real_extract(self
, url
):
92 display_id
= self
._match
_id
(url
)
93 webpage
= self
._download
_webpage
(url
, display_id
)
94 if 'To Unlock This content' in webpage
:
95 self
.raise_login_required(
96 'This video is only available for subscribers. '
97 'Note that --cookies-from-browser may not work due to this site using session cookies')
99 video_url
, video_id
= self
._search
_regex
(
100 r
'<iframe[^>]+src=[\'"]((?:https?:)?//(?:www\.)?thisoldhouse\.(?:chorus\.build|com)/videos/zype/([0-9a-f]{24})[^\'"]*)[\'"]',
101 webpage, 'video url', group=(1, 2))
102 video_url = self._request_webpage(HEADRequest(video_url), video_id, 'Resolving Zype URL').url
104 return self.url_result(video_url, ZypeIE, video_id)