import * as fs from "fs";
type Cookie = {
name: string;
value: string;
domain: string;
path: string;
};
type Cookies = Cookie[];
const cookies = fs
.readFileSync("./nfc.json")
.toString()
.split("\n")
.filter((line) => line)
.map((line) => JSON.parse(line) as Cookies);
const checkCookie = async (cookie: Cookies) => {
return fetch("https://www.netflix.com/vn-en/", {
headers: {
accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
"accept-language": "en-US,en;q=0.6",
"cache-control": "max-age=0",
priority: "u=0, i",
Cookie: cookie.map((c) => `${c.name}=${c.value}`).join("; "),
"sec-ch-ua": '"Brave";v="125", "Chromium";v="125", "Not.A/Brand";v="24"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-model": '""',
"sec-ch-ua-platform": '"Linux"',
"sec-ch-ua-platform-version": '"6.8.9"',
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "none",
"sec-fetch-user": "?1",
"sec-gpc": "1",
"upgrade-insecure-requests": "1",
},
referrerPolicy: "strict-origin-when-cross-origin",
body: null,
method: "GET",
mode: "cors",
credentials: "include",
redirect: "manual",
});
};
const oks: Cookies[] = [];
const runnings: Record<string, Cookies> = Object.fromEntries(
cookies.map((cookie, idx) => [idx, cookie]),
);
(async () => {
while (Object.keys(runnings).length) {
const promises = [];
for (let idx in runnings) {
const res = checkCookie(runnings[idx])
.then((res) => {
console.log(`cookie ${+idx + 1} has status: ${res.status}`);
if (res.status >= 300 && res.status < 400) {
oks.push(runnings[idx]);
}
delete runnings[idx];
})
.catch((err) => {
console.error(err);
});
promises.push(res);
}
await Promise.all(promises);
}
console.log("oks:", oks.length);
fs.writeFileSync(
"./nfc-oks.json",
oks.map((c) => JSON.stringify(c)).join("\n"),
);
})();