LinuxAcademy-DL
LinuxAcademy-DL copied to clipboard
Proposal: Automatic Cookie download
Description
I like your project and i find it very useful, although a bit tedious to do all the preparations to make it work... So I have thought of a way to automate the cookie retrieval, instead of relying on the user doing it manually.
It could possibly reduce the number of errors like #7 and #44
Explanation
I have found this interesting answer on StackExchange where it proposes to use Javascript to convert cookie and it says it's compatible with youtube-dl
...
We could use this to our advantage by using Selenium Webdriver's .execute_script()
.
I haven't tested yet but it could be something like this (i changed only a bit the answer above)...
with open("cookie.txt", "w") as cookie_file:
cookie_file.write(d.execute_script("""
/* *******************************************************************
Source: https://apple.stackexchange.com/a/425700/429715
******************************************************************* */
(function() {
let S = '# Netscape HTTP Cookie File\n';
for (raw_cookie of document.cookie.split(';')) {
let cookie = raw_cookie.trim();
let separator = cookie.indexOf('=');
let name = cookie.substring(0, separator);
let value = cookie.substring(separator + 1);
let domain = window.location.hostname;
// hopefully this will convert domains like `www.test.com` and `test.com` into `.test.com`
domain = domain.replace('www.', '.');
if (domain[0] !== '.') {
domain = '.' + domain;
}
// netscape cookie file format:
// # domain HTTP PATH SECURE timestamp name value
// .test.com TRUE / FALSE 123456789 token 1234abcdef
S += `${domain}\tTRUE\t/\tTRUE\t0\t${name}\t${value}\n`
}
return S
})();
"""))
What do you think?
If you're interested and i find the time i could try and make a PR for you (if i make it work 😄)
Oh, no
Another ck.getcookiestxt.com.
Oh, no
Another ck.getcookiestxt.com.
What do you mean?