Repository: yt-dlp/yt-dlp

Issue:
[dropout] Problem with extractor login process when cookies imported
### Checklist

- [x] I'm reporting a broken site
- [X] I've verified that I'm running yt-dlp version **2022.05.18** ([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/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

I had some difficulties pulling videos from dropout.tv but figured out what was wrong. 

The way that the extractor works is that it first goes to dropout.tv/login to extract an authentication token and store it in a variable and then logs in. Then the authentication token, now authorized, is used to request the video data.

The problem is that my default yt-dlp configuration is set to look for cookies in the firefox folder. The extractor doesn't know how to pull the authentication token from the firefox cookies, but the firefox cookies are applied when the extractor loads up the webpage. 

When the extractor goes to the login page, because the cookies are loaded, the user is already logged in and there is no authentication token available and there isn't an option to actually log in. 

There are a few ways to handle this that pop into mind

1. The cookies can be parsed to get the session ID and use that, bypassing the whole login process. I would suggest not logging out if this occurs so the cookies aren't invalidated.
2. If the authenticity_token is not found on the login page, try hitting the logout page and then reloading the login page. It'll likely be there now. This might invalidate the users existing browser based session though. 
3. Is there a way to scrape and interact with the login page without any loaded cookies being utilized? That would be the cleanest method, IMHO. 

Another problem: 
There is another report of people hitting authentication limitations. I think it might be related to how the extractor works, where it logs in to perform an action and then logs out. In fact, if you point yt-dlp at a URL representing a whole season, it logs out and logs back in for each video in the season. If the extractor can maintain the session for the whole download process, it'll seriously reduce the risk of being rate limited. 


### Verbose log

```shell
(not verbose, sorry)
adam@Storage /m/s/t/U/Season 06> yt-dlp --netrc "https://www.dropout.tv/um-actually/season:7/videos/porco-rosso-super-mario-odyssey-the-wonder-twins"
[Cookies] Extracting cookies from firefox
[Cookies] Extracted 511 cookies from firefox
[Dropout] porco-rosso-super-mario-odyssey-the-wonder-twins: Getting authenticity token
[Dropout] porco-rosso-super-mario-odyssey-the-wonder-twins: Logging out
ERROR: [Dropout] porco-rosso-super-mario-odyssey-the-wonder-twins: Unable to extract authenticity_token; 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
```



Discussion:
I am looking into this issue, and found another problem (at least for me). When using the `--username` and `--password` options and logged out, the dropout extractor will correctly login and download the video information. However, the extracted information is then passed on to the vimeo embedded extractor which tries to login again using the username and password supplied on the command line interface. This fails because vimeo doesn't use the vimeo login when downloading embedded files from dropout.

The issue is due to this line: https://github.com/yt-dlp/yt-dlp/blob/145c5a83a80536b781fd043016bd27c91c760667/yt_dlp/extractor/common.py#L543

Because the vimeo base extractor does support logging in, this returns true and thus a login is tried via username and password.

Now this problem is circumvented by using a netrc file with the 'dropout' machine instead of using the command line options. However I think it's more intuitive have the command line options work for the main extractor. As I'm fixing the original bug I also want to fix this new issue, so I want to see some pointers in how I could prevent this second login. Are there any extractors that use a subextractor in this way that have faced the same problem?

Resolving patch:
diff --git a/yt_dlp/extractor/dropout.py b/yt_dlp/extractor/dropout.py
--- a/yt_dlp/extractor/dropout.py
+++ b/yt_dlp/extractor/dropout.py
@@ -119,16 +119,16 @@ def _login(self, display_id):
 
     def _real_extract(self, url):
         display_id = self._match_id(url)
-        login_err, webpage = False, ''
-        try:
+
+        webpage = None
+        if self._get_cookies('https://www.dropout.tv').get('_session'):
+            webpage = self._download_webpage(url, display_id)
+        if not webpage or '<div id="watch-unauthorized"' in webpage:
             login_err = self._login(display_id)
             webpage = self._download_webpage(url, display_id)
-        finally:
-            if not login_err:
-                self._download_webpage('https://www.dropout.tv/logout', display_id, note='Logging out', fatal=False)
-            elif '<div id="watch-unauthorized"' in webpage:
+            if login_err and '<div id="watch-unauthorized"' in webpage:
                 if login_err is True:
-                    self.raise_login_required(method='password')
+                    self.raise_login_required(method='any')
                 raise ExtractorError(login_err, expected=True)
 
         embed_url = self._search_regex(r'embed_url:\s*["\'](.+?)["\']', webpage, 'embed url')


Test patch: