@mkterswingman/5mghost-yonder 0.0.32 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/utils/cookies.js +22 -1
- package/package.json +1 -1
package/dist/utils/cookies.js
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
/**
|
|
3
|
+
* Domains relevant to YouTube authentication.
|
|
4
|
+
* Only cookies matching these patterns are written to cookies.txt.
|
|
5
|
+
*/
|
|
6
|
+
const YOUTUBE_COOKIE_DOMAINS = [
|
|
7
|
+
"youtube.com",
|
|
8
|
+
"google.com",
|
|
9
|
+
"googleapis.com",
|
|
10
|
+
"googlevideo.com",
|
|
11
|
+
"ytimg.com",
|
|
12
|
+
];
|
|
13
|
+
function isYouTubeDomain(domain) {
|
|
14
|
+
const normalized = domain.startsWith(".") ? domain.slice(1) : domain;
|
|
15
|
+
return YOUTUBE_COOKIE_DOMAINS.some((yt) => normalized === yt || normalized.endsWith(`.${yt}`));
|
|
16
|
+
}
|
|
2
17
|
export function cookiesToNetscape(cookies) {
|
|
3
18
|
const lines = [
|
|
4
19
|
"# Netscape HTTP Cookie File",
|
|
@@ -7,10 +22,16 @@ export function cookiesToNetscape(cookies) {
|
|
|
7
22
|
"",
|
|
8
23
|
];
|
|
9
24
|
for (const c of cookies) {
|
|
25
|
+
// Why: CDP returns all domains; yt-dlp only needs YouTube/Google cookies.
|
|
26
|
+
// Non-YouTube cookies cause warning spam and bloat the file.
|
|
27
|
+
if (!isYouTubeDomain(c.domain))
|
|
28
|
+
continue;
|
|
10
29
|
const domain = c.domain.startsWith(".") ? c.domain : c.domain;
|
|
11
30
|
const includeSubdomains = c.domain.startsWith(".") ? "TRUE" : "FALSE";
|
|
12
31
|
const secure = c.secure ? "TRUE" : "FALSE";
|
|
13
|
-
|
|
32
|
+
// Why: CDP uses -1 for session cookies, but Netscape format uses 0.
|
|
33
|
+
// yt-dlp skips entries with negative expires as "invalid".
|
|
34
|
+
const expiry = c.expires < 0 ? 0 : Math.floor(c.expires);
|
|
14
35
|
lines.push(`${domain}\t${includeSubdomains}\t${c.path}\t${secure}\t${expiry}\t${c.name}\t${c.value}`);
|
|
15
36
|
}
|
|
16
37
|
return lines.join("\n") + "\n";
|