Repository: yt-dlp/yt-dlp

Issue:
[HiDive]: Login fails when both cookies and netrc are given
### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2022.03.08.1** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/ytdl-org/youtube-dl#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 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

United States

### Description

When I try to download from HIDIVE without a `cookies.txt` it uses my netrc credentials and successfully downloads. Once I run the command again using the `cookies.txt` that `yt-dlp` dumps from the successful download, I get the error message shown in the logs. I get the same error message when I use a `cookies.txt` dumped from my browser. Funimation and Crunchyroll both work with the `cookies.txt` dumped from my browser.

The issue persists when trying from different countries using a vpn.

Also, I install and update `yt-dlp` with `pip3 install --force-reinstall -I https://github.com/yt-dlp/yt-dlp/archive/master.zip`

### Verbose log

```shell
[debug] Command-line config: ['-vU', '-N', '32', '--embed-subs', '--remux-video', 'mkv', '-a', 'batch_file', '-o', 'S%(season_number)02dE%(episode_number)02d.%(ext)s']
[debug] User config "/home/{user}/.config/yt-dlp/config": ['--netrc', '--cookies', '~/.config/yt-dlp/cookies.txt']
[debug] Batch file urls: ['https://www.hidive.com/stream/made-in-abyss/s01e001']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2022.03.08.1 [c0c2c57d3]
[debug] Lazy loading extractors is disabled
[debug] Python version 3.8.10 (CPython 64bit) - Linux-5.4.0-100-generic-x86_64-with-glibc2.29
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 4.2.4, ffprobe 4.2.4, phantomjs 2.1.1, rtmpdump 2.4
[debug] Optional libraries: brotli, certifi, Cryptodome, secretstorage, mutagen, sqlite, websockets
[debug] Proxy map: {}
Latest version: 2022.03.08.1, Current version: 2022.03.08.1
yt-dlp is up to date (2022.03.08.1)
[HiDive] None: Downloading webpage
ERROR: [HiDive] made-in-abyss/s01e001: Unable to extract login form; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "/home/{user}/.local/lib/python3.8/site-packages/yt_dlp/extractor/common.py", line 639, in extract
    self.initialize()
  File "/home/{user}/.local/lib/python3.8/site-packages/yt_dlp/extractor/common.py", line 544, in initialize
    self._perform_login(username, password)
  File "/home/{user}/.local/lib/python3.8/site-packages/yt_dlp/extractor/hidive.py", line 40, in _perform_login
    form = self._search_regex(
  File "/home/{user}/.local/lib/python3.8/site-packages/yt_dlp/extractor/common.py", line 1229, in _search_regex
    raise RegexNotFoundError('Unable to extract %s' % _name)
```

[HiDive]: Login fails when both cookies and netrc are given
### Checklist

- [X] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2022.03.08.1** ([update instructions](https://github.com/yt-dlp/yt-dlp#update)) or later (specify commit)
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that all URLs and arguments with special characters are [properly quoted or escaped](https://github.com/ytdl-org/youtube-dl#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 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

United States

### Description

When I try to download from HIDIVE without a `cookies.txt` it uses my netrc credentials and successfully downloads. Once I run the command again using the `cookies.txt` that `yt-dlp` dumps from the successful download, I get the error message shown in the logs. I get the same error message when I use a `cookies.txt` dumped from my browser. Funimation and Crunchyroll both work with the `cookies.txt` dumped from my browser.

The issue persists when trying from different countries using a vpn.

Also, I install and update `yt-dlp` with `pip3 install --force-reinstall -I https://github.com/yt-dlp/yt-dlp/archive/master.zip`

### Verbose log

```shell
[debug] Command-line config: ['-vU', '-N', '32', '--embed-subs', '--remux-video', 'mkv', '-a', 'batch_file', '-o', 'S%(season_number)02dE%(episode_number)02d.%(ext)s']
[debug] User config "/home/{user}/.config/yt-dlp/config": ['--netrc', '--cookies', '~/.config/yt-dlp/cookies.txt']
[debug] Batch file urls: ['https://www.hidive.com/stream/made-in-abyss/s01e001']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, err utf-8, pref UTF-8
[debug] yt-dlp version 2022.03.08.1 [c0c2c57d3]
[debug] Lazy loading extractors is disabled
[debug] Python version 3.8.10 (CPython 64bit) - Linux-5.4.0-100-generic-x86_64-with-glibc2.29
[debug] Checking exe version: ffmpeg -bsfs
[debug] Checking exe version: ffprobe -bsfs
[debug] exe versions: ffmpeg 4.2.4, ffprobe 4.2.4, phantomjs 2.1.1, rtmpdump 2.4
[debug] Optional libraries: brotli, certifi, Cryptodome, secretstorage, mutagen, sqlite, websockets
[debug] Proxy map: {}
Latest version: 2022.03.08.1, Current version: 2022.03.08.1
yt-dlp is up to date (2022.03.08.1)
[HiDive] None: Downloading webpage
ERROR: [HiDive] made-in-abyss/s01e001: Unable to extract login form; please report this issue on  https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using  yt-dlp -U
  File "/home/{user}/.local/lib/python3.8/site-packages/yt_dlp/extractor/common.py", line 639, in extract
    self.initialize()
  File "/home/{user}/.local/lib/python3.8/site-packages/yt_dlp/extractor/common.py", line 544, in initialize
    self._perform_login(username, password)
  File "/home/{user}/.local/lib/python3.8/site-packages/yt_dlp/extractor/hidive.py", line 40, in _perform_login
    form = self._search_regex(
  File "/home/{user}/.local/lib/python3.8/site-packages/yt_dlp/extractor/common.py", line 1229, in _search_regex
    raise RegexNotFoundError('Unable to extract %s' % _name)
```



Discussion:
Disclaimer: I know very little about web programming and currently have no development environment to test, so this is purely theoretical

chrunchyroll.py starts the _perform_login() function with the following snippet:
```
       if self._get_cookies(self._LOGIN_URL).get('etp_rt'):
            return
```

The hidive _perform_login() function does not check any cookies, so I'm guessing that's what's missing.
The following cookies seems to be added after logging in to hidive:

- .AspNet.ApplicationCookie
- AuthA
- AuthI
- AuthR
- IsWelcomed
- ProfileUID
- UserStatus
- __RequestVerificationToken

So maybe the fix is as simple as adding the following to the top of _perform_login():
```
        if self._get_cookies(self._LOGIN_URL).get('__RequestVerificationToken'):
            return
```

Feel free to test and make a PR if it works, otherwise I might get around to it eventually, but no promises.
Disclaimer: I know very little about web programming and currently have no development environment to test, so this is purely theoretical

chrunchyroll.py starts the _perform_login() function with the following snippet:
```
       if self._get_cookies(self._LOGIN_URL).get('etp_rt'):
            return
```

The hidive _perform_login() function does not check any cookies, so I'm guessing that's what's missing.
The following cookies seems to be added after logging in to hidive:

- .AspNet.ApplicationCookie
- AuthA
- AuthI
- AuthR
- IsWelcomed
- ProfileUID
- UserStatus
- __RequestVerificationToken

So maybe the fix is as simple as adding the following to the top of _perform_login():
```
        if self._get_cookies(self._LOGIN_URL).get('__RequestVerificationToken'):
            return
```

Feel free to test and make a PR if it works, otherwise I might get around to it eventually, but no promises.

Resolving patch:
diff --git a/yt_dlp/extractor/hidive.py b/yt_dlp/extractor/hidive.py
--- a/yt_dlp/extractor/hidive.py
+++ b/yt_dlp/extractor/hidive.py
@@ -38,7 +38,9 @@ def _perform_login(self, username, password):
         webpage = self._download_webpage(self._LOGIN_URL, None)
         form = self._search_regex(
             r'(?s)<form[^>]+action="/account/login"[^>]*>(.+?)</form>',
-            webpage, 'login form')
+            webpage, 'login form', default=None)
+        if not form:  # logged in
+            return
         data = self._hidden_inputs(form)
         data.update({
             'Email': username,


Test patch: