New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get session cookies when using --cookies-from-browser #5534
Comments
Definitely not intended. I thought chrome doesn't write session cookies to disk 🤔. If it does, we should "fix" the cookies similar to https://github.com/yt-dlp/yt-dlp/blob/b96187a9603aaa7ead8ad94ac82433f085ea4895/yt_dlp/utils.py#L1654-L1667 |
It does because of the |
Firefox is also affected by this issue: It seems like session cookies are not stored in its Instead, they are in Once uncompressed, the |
Was about to open the same issue, here is what I found: Disclaimer at the start - I did this investigation with a recent version of brave, will need to check if this applies to all chromium browsers and if so from which version. The brave cookies database has 2 columns related to cookie expiry: expires_utc and has_expires. yt-dlp only checks the expires_utc column:
The current logic in yt-dlp takes expires_utc only and the phyton cookie will consider a value of 0 as expired: class Cookie:
# ...
def is_expired(self, now=None):
if now is None: now = time.time()
if (self.expires is not None) and (self.expires <= now):
return True
return False To support session_cookies we should therefore set expires to None, since they do not expire. |
@Tblue can you elaborate on what you mean by with the prefix? I could confirm that this file is created when I close firefox: ~/Library/Application Support/Firefox/Profiles/$profile.default-esr/sessionstore.jsonlz4 It starts like this:
I tried removing the |
Actually nevermind, I found this superuser thread on it: https://superuser.com/a/1363751 And it linked this python gist that I could test sucessfully: https://gist.github.com/Tblue/62ff47bef7f894e92ed5 I could also confirm that the cookie can be found in there, I censored mine so we have a reference for the format: jsonpath /cookies/4 {
"host": ".vimeo.com",
"value": "the cookie value",
"path": "/",
"name": "12345678_password",
"secure": true,
"originAttributes": {
"firstPartyDomain": "",
"geckoViewSessionContextId": "",
"inIsolatedMozBrowser": false,
"partitionKey": "",
"privateBrowsingId": 0,
"userContextId": 0
},
"schemeMap": 2
}, Edit: I am blind, this is even the gist of @Tblue. 😄 Before we can make a PR with this - could you just confirm that you are also willing to publish it (or parts of it) under UNLICENSE? I think we would only need to copy this method: https://gist.github.com/Tblue/62ff47bef7f894e92ed5#file-mozlz4a-py-L76 |
Yup, and I was going to link to that Gist - I’ve written it. 🙂
|
Sure, feel free to use the Gist under the UNLICENSE.
|
@StefanLobbenmeier, you might also find this script useful as an inspiration (feel free to treat it as licensed under the UNLICENSE as well): dump-firefox-cookies.py |
Keeping open until this is solved for Firefox as well |
Yeah did not have the time to implement for Firefox, but it’s still on my radar. If someone else wants to take it I don’t mind though :) |
DO NOT REMOVE OR SKIP THE ISSUE TEMPLATE
Checklist
Provide a description that is worded well enough to be understood
While investigating #4514 I found a different behavior between
--cookies cookies.txt
and--cookies-from-browser chrome
.The first option injected all cookies into the request, while the latter one was missing the session cookies.
Session cookies have
expires=None
anddiscard=True
. Taking a look into the codebase I see that session cookies imported from Chrome haveexpires=0
anddiscard=False
.yt-dlp/yt_dlp/cookies.py
Lines 335 to 339 in d7b460d
Is this intended or possibly a bug?
Provide verbose output that clearly demonstrates the problem
yt-dlp -vU <your command line>
)[debug] Command-line config
) and insert it belowComplete Verbose Output
The text was updated successfully, but these errors were encountered: