]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/thisoldhouse.py
[ie/roosterteeth] Extract release date and timestamp (#9393)
[yt-dlp.git] / yt_dlp / extractor / thisoldhouse.py
1 import json
2
3 from .common import InfoExtractor
4 from .zype import ZypeIE
5 from ..networking import HEADRequest
6 from ..networking.exceptions import HTTPError
7 from ..utils import (
8 ExtractorError,
9 filter_dict,
10 parse_qs,
11 try_call,
12 urlencode_postdata,
13 )
14
15
16 class ThisOldHouseIE(InfoExtractor):
17 _NETRC_MACHINE = 'thisoldhouse'
18 _VALID_URL = r'https?://(?:www\.)?thisoldhouse\.com/(?:watch|how-to|tv-episode|(?:[^/?#]+/)?\d+)/(?P<id>[^/?#]+)'
19 _TESTS = [{
20 'url': 'https://www.thisoldhouse.com/furniture/21017078/how-to-build-a-storage-bench',
21 'info_dict': {
22 'id': '5dcdddf673c3f956ef5db202',
23 'ext': 'mp4',
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',
28 'duration': 674,
29 'view_count': int,
30 'average_rating': 0,
31 'thumbnail': r're:^https?://.*\.jpg\?\d+$',
32 'display_id': 'how-to-build-a-storage-bench',
33 },
34 'params': {
35 'skip_download': True,
36 },
37 }, {
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,
41 }, {
42 # 404 Not Found
43 'url': 'https://www.thisoldhouse.com/tv-episode/ask-toh-shelf-rough-electric',
44 'only_matching': True,
45 }, {
46 # 404 Not Found
47 'url': 'https://www.thisoldhouse.com/how-to/how-to-build-storage-bench',
48 'only_matching': True,
49 }, {
50 'url': 'https://www.thisoldhouse.com/21113884/s41-e13-paradise-lost',
51 'only_matching': True,
52 }, {
53 # iframe www.thisoldhouse.com
54 'url': 'https://www.thisoldhouse.com/21083431/seaside-transformation-the-westerly-project',
55 'only_matching': True,
56 }]
57
58 _LOGIN_URL = 'https://login.thisoldhouse.com/usernamepassword/login'
59
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'})
66
67 try:
68 auth_form = self._download_webpage(
69 self._LOGIN_URL, None, 'Submitting credentials', headers={
70 'Content-Type': 'application/json',
71 'Referer': urlh.url,
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',
75 'username': username,
76 'password': password,
77 'popup_options': {},
78 'sso': True,
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)
85 raise
86
87 self._request_webpage(
88 'https://login.thisoldhouse.com/login/callback', None, 'Completing login',
89 data=urlencode_postdata(self._hidden_inputs(auth_form)))
90
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')
98
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
103
104 return self.url_result(video_url, ZypeIE, video_id)