Repository: yt-dlp/yt-dlp

Issue:
This Old House (Insider)
### DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE

- [X] I understand that I will be **blocked** if I *intentionally* remove or skip any mandatory\* field

### Checklist

- [X] I'm reporting that yt-dlp is broken on a **supported** site
- [X] I've verified that I'm running yt-dlp version **2023.09.24** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are playable in a browser with the same IP and same login details
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/yt-dlp/yt-dlp/wiki/FAQ#video-url-contains-an-ampersand--and-im-getting-some-strange-output-1-2839-or-v-is-not-recognized-as-an-internal-or-external-command)
- [X] I've searched [known issues](https://github.com/yt-dlp/yt-dlp/issues/3766) and the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues **including closed ones**. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and I'm willing to share it if required

### Region

USA

### Provide a description that is worded well enough to be understood

Error when accessing https://www.thisoldhouse.com/season-45-lexington-modern/93763/s45-e1-on-a-mission getting the following ERROR: [Zype] 650b202288307d000106dd82: This video requires a purchase entitlement in order to watch.

I have tried passing username and password as well as --cookies-from-browser Chrome and --cookies cookies\thisoldhouse_cookies.txt.



### Provide verbose output that clearly demonstrates the problem

- [X] Run **your** yt-dlp command with **-vU** flag added (`yt-dlp -vU <your command line>`)
- [ ] If using API, add `'verbose': True` to `YoutubeDL` params instead
- [X] Copy the WHOLE output (starting with `[debug] Command-line config`) and insert it below

### Complete Verbose Output

```shell
[debug] Command-line config: ['-Uv', '--cookies', 'cookies\\thisoldhouse.com_cookies.txt', 'https://www.thisoldhouse.com/season-45-lexington-modern/93763/s45-e1-on-a-mission', '-o', 'This Old House - S45E01.mp4']
[debug] Encodings: locale cp1252, fs utf-8, pref cp1252, out utf-8, error utf-8, screen utf-8
[debug] yt-dlp version stable@2023.09.24 [088add956] (pip)
[debug] Python 3.10.5 (CPython AMD64 64bit) - Windows-10-10.0.19045-SP0 (OpenSSL 1.1.1n  15 Mar 2022)
[debug] exe versions: ffmpeg 2022-10-10-git-f3b5277057-full_build-www.gyan.dev (setts), ffprobe 2022-10-10-git-f3b5277057-full_build-www.gyan.dev
[debug] Optional libraries: Cryptodome-3.15.0, brotli-1.0.9, certifi-2022.09.24, mutagen-1.46.0, sqlite3-3.37.2, websockets-10.3
[debug] Proxy map: {}
[debug] Loaded 1886 extractors
[debug] Fetching release info: https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest
Available version: stable@2023.09.24, Current version: stable@2023.09.24
yt-dlp is up to date (stable@2023.09.24)
[ThisOldHouse] Extracting URL: https://www.thisoldhouse.com/season-45-lexington-modern/93763/s45-e1-on-a-mission
[ThisOldHouse] s45-e1-on-a-mission: Downloading webpage
[Zype] Extracting URL: https://player.zype.com/embed/650b202288307d000106dd82.html?api_key=hsOk_yMSPYNrT22e9pu8hihLXjaZf0JW5jsOWv4ZqyHJFvkJn6rtToHl09tbbsbe
[Zype] 650b202288307d000106dd82: Downloading JSON metadata
ERROR: [Zype] 650b202288307d000106dd82: This video requires a purchase entitlement in order to watch.
  File "C:\Users\Jules\AppData\Local\Programs\Python\Python310\lib\site-packages\yt_dlp\extractor\common.py", line 715, in extract
    ie_result = self._real_extract(url)
  File "C:\Users\Jules\AppData\Local\Programs\Python\Python310\lib\site-packages\yt_dlp\extractor\zype.py", line 41, in _real_extract
    raise ExtractorError(self._parse_json(
```



Discussion:
Can share account privately. 
@garret1317 let me know what's next will share account. 
Can someone please look at this.

'This video requires a purchase entitlement in order to watch.'    

I can share the account information.
@scarng63 I could look into fixing it when I have time.
To share account info, you can email me, `bashonly ( a t ) proton mail [ d o t ] com`,
or join the [yt-dlp discord server](https://discord.gg/H5MNcFW63r) and DM me on there (same username)

> @scarng63 I could look into fixing it when I have time. To share account info, you can email me, `bashonly ( a t ) proton mail [ d o t ] com`, or join the [yt-dlp discord server](https://discord.gg/H5MNcFW63r) and DM me on there (same username)

Thanks email sent.

Resolving patch:
diff --git a/yt_dlp/extractor/thisoldhouse.py b/yt_dlp/extractor/thisoldhouse.py
--- a/yt_dlp/extractor/thisoldhouse.py
+++ b/yt_dlp/extractor/thisoldhouse.py
@@ -1,11 +1,23 @@
+import json
+
 from .common import InfoExtractor
+from .zype import ZypeIE
 from ..networking import HEADRequest
+from ..networking.exceptions import HTTPError
+from ..utils import (
+    ExtractorError,
+    filter_dict,
+    parse_qs,
+    try_call,
+    urlencode_postdata,
+)
 
 
 class ThisOldHouseIE(InfoExtractor):
-    _VALID_URL = r'https?://(?:www\.)?thisoldhouse\.com/(?:watch|how-to|tv-episode|(?:[^/]+/)?\d+)/(?P<id>[^/?#]+)'
+    _NETRC_MACHINE = 'thisoldhouse'
+    _VALID_URL = r'https?://(?:www\.)?thisoldhouse\.com/(?:watch|how-to|tv-episode|(?:[^/?#]+/)?\d+)/(?P<id>[^/?#]+)'
     _TESTS = [{
-        'url': 'https://www.thisoldhouse.com/how-to/how-to-build-storage-bench',
+        'url': 'https://www.thisoldhouse.com/furniture/21017078/how-to-build-a-storage-bench',
         'info_dict': {
             'id': '5dcdddf673c3f956ef5db202',
             'ext': 'mp4',
@@ -23,13 +35,16 @@ class ThisOldHouseIE(InfoExtractor):
             'skip_download': True,
         },
     }, {
+        # Page no longer has video
         'url': 'https://www.thisoldhouse.com/watch/arlington-arts-crafts-arts-and-crafts-class-begins',
         'only_matching': True,
     }, {
+        # 404 Not Found
         'url': 'https://www.thisoldhouse.com/tv-episode/ask-toh-shelf-rough-electric',
         'only_matching': True,
     }, {
-        'url': 'https://www.thisoldhouse.com/furniture/21017078/how-to-build-a-storage-bench',
+        # 404 Not Found
+        'url': 'https://www.thisoldhouse.com/how-to/how-to-build-storage-bench',
         'only_matching': True,
     }, {
         'url': 'https://www.thisoldhouse.com/21113884/s41-e13-paradise-lost',
@@ -39,17 +54,51 @@ class ThisOldHouseIE(InfoExtractor):
         'url': 'https://www.thisoldhouse.com/21083431/seaside-transformation-the-westerly-project',
         'only_matching': True,
     }]
-    _ZYPE_TMPL = 'https://player.zype.com/embed/%s.html?api_key=hsOk_yMSPYNrT22e9pu8hihLXjaZf0JW5jsOWv4ZqyHJFvkJn6rtToHl09tbbsbe'
+
+    _LOGIN_URL = 'https://login.thisoldhouse.com/usernamepassword/login'
+
+    def _perform_login(self, username, password):
+        self._request_webpage(
+            HEADRequest('https://www.thisoldhouse.com/insider'), None, 'Requesting session cookies')
+        urlh = self._request_webpage(
+            'https://www.thisoldhouse.com/wp-login.php', None, 'Requesting login info',
+            errnote='Unable to login', query={'redirect_to': 'https://www.thisoldhouse.com/insider'})
+
+        try:
+            auth_form = self._download_webpage(
+                self._LOGIN_URL, None, 'Submitting credentials', headers={
+                    'Content-Type': 'application/json',
+                    'Referer': urlh.url,
+                }, 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,
+                    'popup_options': {},
+                    'sso': True,
+                    '_csrf': try_call(lambda: self._get_cookies(self._LOGIN_URL)['_csrf'].value),
+                    '_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(
+            'https://login.thisoldhouse.com/login/callback', None, 'Completing login',
+            data=urlencode_postdata(self._hidden_inputs(auth_form)))
 
     def _real_extract(self, url):
         display_id = self._match_id(url)
         webpage = self._download_webpage(url, display_id)
         if 'To Unlock This content' in webpage:
-            self.raise_login_required(method='cookies')
-        video_url = self._search_regex(
+            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(
             r'<iframe[^>]+src=[\'"]((?:https?:)?//(?:www\.)?thisoldhouse\.(?:chorus\.build|com)/videos/zype/([0-9a-f]{24})[^\'"]*)[\'"]',
-            webpage, 'video url')
-        if 'subscription_required=true' in video_url or 'c-entry-group-labels__image' in webpage:
-            return self.url_result(self._request_webpage(HEADRequest(video_url), display_id).url, 'Zype', display_id)
-        video_id = self._search_regex(r'(?:https?:)?//(?:www\.)?thisoldhouse\.(?:chorus\.build|com)/videos/zype/([0-9a-f]{24})', video_url, 'video id')
-        return self.url_result(self._ZYPE_TMPL % video_id, 'Zype', video_id)
+            webpage, 'video url', group=(1, 2))
+        video_url = self._request_webpage(HEADRequest(video_url), video_id, 'Resolving Zype URL').url
+
+        return self.url_result(video_url, ZypeIE, video_id)


Test patch: