Skip to content

Commit

Permalink
Provide cookies to YT-DLP (if any).
Browse files Browse the repository at this point in the history
  • Loading branch information
meowcateatrat committed Jan 9, 2025
1 parent 0a96ceb commit 63fdbba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 4 additions & 1 deletion plugin/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
"uuid": "elephant",
"name": "Elephant",
"description": "Provides support for downloading videos from various sites.",
"version": "1.1.19",
"version": "1.1.20",
"icon": "icon.svg",
"mediaParser": true,
"mediaListParser": true,
"minApiVersion": 2,
"minFeaturesLevel": 2,
"dependencies": {
"Python": {"minVersion": "3.9"}
},
"permissions": [
"launchPython"
],
"scripts": [
"tools.js",
"msabstractparser.js",
"msparser.js",
"msbatchparser.js"
Expand Down
8 changes: 8 additions & 0 deletions plugin/msabstractparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var msAbstractParser = (function()
console.log("parsing...");

var args = [];
var tmpCookies;

var proxyUrl = qtJsNetworkProxyMgr.proxyForUrl(obj.url).url();
if (proxyUrl)
Expand All @@ -21,6 +22,13 @@ var msAbstractParser = (function()

args.push("-J", "--flat-playlist", "--no-warnings", "--compat-options", "no-youtube-unavailable-videos");

if (obj.cookies && obj.cookies.length)
{
tmpCookies = qtJsTools.createTmpFile("request_" + obj.requestId + "_cookies");
if (tmpCookies && tmpCookies.writeText(cookiesToNetscapeText(obj.cookies)))
args.push("--cookies", tmpCookies.path);
}

if (customArgs.length)
args = args.concat(customArgs);

Expand Down
Binary file modified plugin/signature.dat
Binary file not shown.
22 changes: 22 additions & 0 deletions plugin/tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// converts cookies array to Netscape cookie file format
function cookiesToNetscapeText(cookies)
{
let r = "# Netscape HTTP Cookie File\n";

for (let i = 0; i < cookies.length; ++i)
{
let c = cookies[i];

r += c.domain + '\t' +
"FALSE" + '\t' +
"/" + '\t' +
(c.isSecure ? "TRUE" : "FALSE") + '\t' +
(c.expirationDate.getTime() ? c.expirationDate.getTime() / 1000 : 0) + '\t' +
c.name + '\t' +
c.value;

r += '\n';
}

return r;
}

0 comments on commit 63fdbba

Please sign in to comment.