Skip to content

Commit 85a6726

Browse files
committed
Stuff is working
1 parent dd081ae commit 85a6726

File tree

7 files changed

+196
-426
lines changed

7 files changed

+196
-426
lines changed

index.js

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const express = require('express');
44
const fs = require('fs');
55
const path = require('path');
66
const os = require('os');
7+
const https = require('https'); // Add this import
78

89
const expressApp = express();
910
let serverPort, ytWin;
@@ -30,17 +31,49 @@ const logStream = fs.createWriteStream(liveLogPath, { flags: 'a' });
3031
});
3132

3233
function convertCookiesToNetscapeFormat(cookies) {
33-
return cookies.map(cookie =>
34-
[cookie.domain || '', 'TRUE', cookie.path, String(cookie.secure), String(cookie.expirationDate), cookie.name, cookie.value].join('\t')
35-
).join('\n');
34+
return [
35+
"# Netscape HTTP Cookie File", // Required header
36+
...cookies.map(cookie => {
37+
let domain = cookie.domain || "";
38+
if (!domain.startsWith(".")) {
39+
domain = "." + domain; // Ensure proper domain format
40+
}
41+
return [
42+
domain,
43+
"TRUE", // Include subdomains (assumed safe for most use cases)
44+
cookie.path || "/", // Default to root path if missing
45+
cookie.secure ? "TRUE" : "FALSE", // Secure flag
46+
Math.floor(cookie.expirationDate || 0), // Ensure it's a valid timestamp
47+
cookie.name,
48+
cookie.value
49+
].join("\t");
50+
})
51+
].join("\n");
3652
}
3753

38-
function ensureFile(filePath, command) {
54+
function ensureFile(filePath, url) {
3955
if (!fs.existsSync(filePath)) {
4056
fs.mkdirSync(path.dirname(filePath), { recursive: true });
41-
if (command) exec(command);
42-
fs.writeFileSync(filePath, '', 'utf8');
43-
console.log(`${path.basename(filePath)} created successfully.`);
57+
if (url) {
58+
const file = fs.createWriteStream(filePath);
59+
https.get(url, (response) => {
60+
if (response.statusCode === 200) {
61+
response.pipe(file);
62+
file.on('finish', () => {
63+
file.close();
64+
fs.chmodSync(filePath, '755'); // Make the file executable
65+
console.log(`${path.basename(filePath)} downloaded and made executable.`);
66+
});
67+
} else {
68+
console.error(`Failed to download ${url}. Status code: ${response.statusCode}`);
69+
}
70+
}).on('error', (err) => {
71+
console.error(`Error downloading ${url}:`, err.message);
72+
});
73+
} else {
74+
fs.writeFileSync(filePath, '', 'utf8');
75+
console.log(`${path.basename(filePath)} created successfully.`);
76+
}
4477
} else {
4578
console.log(`${path.basename(filePath)} already exists.`);
4679
}
@@ -195,7 +228,7 @@ app.whenReady().then(() => {
195228
ensureFile(path.join(userDataDir, 'yt-cookie.txt'));
196229
ensureFile(
197230
path.join(executablesDir, 'yt-dlp-mac'),
198-
`cd "${executablesDir}" && wget https://jemcats.software/github_pages/VideoSnatcher/files/yt-dlp-mac && chmod +x yt-dlp-mac`
231+
'https://jemcats.software/github_pages/VideoSnatcher/files/yt-dlp-mac'
199232
);
200233
createMainWindow();
201234
});

0 commit comments

Comments
 (0)