Spaces:
Running
Running
File size: 4,893 Bytes
dc878d2 b35b44d e46a815 b35b44d dc878d2 96aa740 dc878d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
const { sanitirizeName, parseToStreamUrl } = require("./helper");
const fetch = require("node-fetch");
const getAuthorization = () => {
if (!process.env.EASY_USERNAME) return null;
if (!process.env.EASY_PASSWORD) return null;
return (
"Basic " + btoa(`${process.env.EASY_USERNAME}:${process.env.EASY_PASSWORD}`)
);
};
let isRedirect = async (url) => {
try {
const controller = new AbortController();
// 5 second timeout:
const timeoutId = setTimeout(() => controller.abort(), 5000);
const response = await fetch(url, {
redirect: "manual",
signal: controller.signal,
});
clearTimeout(timeoutId);
if (response.status === 301 || response.status === 302) {
const locationURL = new URL(
response.headers.get("location"),
response.url
);
if (locationURL.href.startsWith("http")) {
await isRedirect(locationURL);
} else {
return locationURL.href;
}
} else if (response.status >= 200 && response.status < 300) {
return response.url;
} else {
// return response.url;
return null;
}
} catch (error) {
return null;
}
};
let defaultAuthorization =
// getAuthorization() || "Basic YzBudGF4OmU4TVVjSDE4Y0g3eENKZFNablVQ";
getAuthorization() || "Basic bWVka293NzQ6QFpWV3dlZGE0akBhOXUj";
// getAuthorization() || "Basic c2FwcHkwMDpHYXk2TlA0UA==";
let fetchEasynews = async (query) => {
query = sanitirizeName(query);
console.log({ query });
let url = `https://members.easynews.com/2.0/search/solr-search/?fly=2&gps=${query}&pby=9999&pno=1&s1=nsubject&s1d=%2B&s2=nrfile&s2d=%2B&s3=dsize&s3d=%2B&sS=0&d1t&d2t&b1t&b2t&px1t&px2t&fps1t&fps2t&bps1t&bps2t&hz1t&hz2t&rn1t&rn2t&grpF[]&st=adv&safeO=0&sb=1&fex=mkv mp4 ts avi flv`;
https: return await fetch(url, {
headers: {
accept: "*/*",
Authorization: defaultAuthorization,
},
referrerPolicy: "no-referrer",
method: "GET",
})
.then((res) => res.json())
.then(async (results) => {
console.log({ Initial: "data" in results ? results["data"].length : 0 });
return "data" in results
? results["data"].map((el, order) => {
const baseUrl = `${results["downURL"]}/${results["dlFarm"]}/${results["dlPort"]}`;
return {
...el,
url: parseToStreamUrl(baseUrl, {
...el,
sid: results["sid"] + ":" + order,
}),
};
})
: [];
})
.catch((err) => {
console.log({ err });
return [];
});
};
function getMeta2(id, type) {
var [tt, s, e] = id.split(":");
const api1 = `https://v2.sg.media-imdb.com/suggestion/t/${tt}.json`;
const api2 = `https://v3-cinemeta.strem.io/meta/${type}/${tt}.json`;
return fetch(api1)
.then((res) => res.json())
.then((json) => {
let { d } = json;
return d ? d[(d.length ?? 1) - 1] : {};
})
.then(({ l, y }) => ({ name: l, year: y }))
.catch((err) =>
fetch(api2)
.then((res) => res.json())
.then((json) => ({
name: json.meta["name"],
year: json.meta["releaseInfo"]?.substring(0, 4) ?? "",
}))
);
}
function getMeta(id, type) {
var [tt, s, e] = id.split(":");
const api1 = `https://v2.sg.media-imdb.com/suggestion/t/${tt}.json`;
const api2 = `https://v3-cinemeta.strem.io/meta/${type}/${tt}.json`;
return fetch(api2)
.then((res) => res.json())
.then((json) => ({
name: json.meta["name"],
year: json.meta["releaseInfo"]?.substring(0, 4) ?? "",
}))
.catch((err) =>
fetch(api1)
.then((res) => res.json())
.then((json) => {
return json.d[0];
})
.then(({ l, y }) => ({ name: l, year: y }))
);
}
async function getImdbFromKitsu(id) {
var [kitsu, _id, e] = id.split(":");
return fetch(`https://anime-kitsu.strem.fun/meta/anime/${kitsu}:${_id}.json`)
.then((_res) => _res.json())
.then((json) => {
return json["meta"];
})
.then((json) => {
try {
let imdb = json["imdb_id"];
let meta = json["videos"].find((el) => el.id == id);
const aliases = (json["aliases"] ?? []).join("||");
return [
imdb,
(meta["imdbSeason"] ?? 1).toString(),
(meta["imdbEpisode"] ?? 1).toString(),
(meta["season"] ?? 1).toString(),
(meta["imdbSeason"] ?? 1).toString() == 1
? (meta["imdbEpisode"] ?? 1).toString()
: (meta["episode"] ?? 1).toString(),
meta["imdbEpisode"] != meta["episode"] || meta["imdbSeason"] == 1,
aliases,
];
} catch (error) {
return null;
}
})
.catch((err) => null);
}
module.exports = {
getAuthorization,
isRedirect,
fetchEasynews,
getMeta2,
getMeta,
getImdbFromKitsu,
defaultAuthorization,
};
|