add youtube kids to invidious, type invidious

This commit is contained in:
Michael C 2023-07-06 18:25:50 -04:00
parent 60f9274438
commit 0d9c3dc807
No known key found for this signature in database
GPG key ID: FFB04FB3B878B7B4
3 changed files with 77 additions and 23 deletions

View file

@ -4,8 +4,9 @@ This file is only ran by GitHub Actions in order to populate the Invidious insta
This file should not be shipped with the extension This file should not be shipped with the extension
*/ */
import { writeFile, existsSync } from 'fs'; import { writeFile, existsSync } from "fs"
import { join } from 'path'; import { join } from "path"
import { InvidiousInstance, instanceMap } from "./invidiousType"
// import file from https://api.invidious.io/instances.json // import file from https://api.invidious.io/instances.json
if (!existsSync(join(__dirname, "data.json"))) { if (!existsSync(join(__dirname, "data.json"))) {
@ -15,41 +16,40 @@ if (!existsSync(join(__dirname, "data.json"))) {
// @ts-ignore // @ts-ignore
import * as data from "../ci/data.json"; import * as data from "../ci/data.json";
type instanceMap = { // static non-invidious instances
name: string; const staticInstances = ["www.youtubekids.com"];
url: string;
dailyRatios: {ratio: string; label: string }[];
thirtyDayUptime: string;
}[]
// only https servers // only https servers
const mapped: instanceMap = data const mapped: instanceMap = data
// eslint-disable-next-line @typescript-eslint/no-explicit-any .filter((i: InvidiousInstance) => i[1]?.type === "https")
.filter((i: any) => i[1]?.type === 'https') .map((instance: InvidiousInstance) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
.map((instance: any) => {
return { return {
name: instance[0], name: instance[0],
url: instance[1].uri, url: instance[1].uri,
dailyRatios: instance[1].monitor.dailyRatios, dailyRatios: instance[1].monitor.dailyRatios,
thirtyDayUptime: instance[1]?.monitor['30dRatio'].ratio, thirtyDayUptime: instance[1]?.monitor["30dRatio"].ratio,
} }
}) });
// reliability and sanity checks // reliability and sanity checks
const reliableCheck = mapped const reliableCheck = mapped
.filter((instance) => { .filter((instance) => {
// 30d uptime >= 90% // 30d uptime >= 90%
const thirtyDayUptime = Number(instance.thirtyDayUptime) >= 90 const thirtyDayUptime = Number(instance.thirtyDayUptime) >= 90;
// available for at least 80/90 days // available for at least 80/90 days
const dailyRatioCheck = instance.dailyRatios.filter(status => status.label !== "black") const dailyRatioCheck = instance.dailyRatios.filter(status => status.label !== "black");
return (thirtyDayUptime && dailyRatioCheck.length >= 80) return thirtyDayUptime && dailyRatioCheck.length >= 80;
}) })
// url includes name // url includes name
.filter(instance => instance.url.includes(instance.name)) .filter((instance) => instance.url.includes(instance.name));
// finally map to array // finally map to array
const result: string[] = reliableCheck.map(instance => instance.name).sort() const result: string[] = reliableCheck.map((instance) => instance.name).sort();
writeFile(join(__dirname, "./invidiouslist.json"), JSON.stringify(result), (err) => {
if (err) return console.log(err); writeFile(
}) join(__dirname, "./invidiouslist.json"),
JSON.stringify([...staticInstances, ...result]),
(err) => {
if (err) return console.log(err);
}
);

54
ci/invidiousType.ts Normal file
View file

@ -0,0 +1,54 @@
type ratio = {
ratio: string;
label: string;
}
export type instanceMap = {
name: string;
url: string;
dailyRatios: {ratio: string; label: string }[];
thirtyDayUptime: string;
}[]
export type InvidiousInstance = [
string,
{
flag: string;
region: string;
stats: null | {
version: string;
software: {
name: string;
version: string;
branch: string;
};
openRegistrations: boolean;
usage: {
users: {
total: number;
activeHalfyear: number;
activeMonth: number;
};
};
metadata: {
updatedAt: number;
lastChannelRefreshedAt: number;
};
};
cors: boolean | null;
api: boolean | null;
type: "https" | "http" | "onion" | "i2p";
uri: string;
monitor: null | {
monitorId: number;
createdAt: number;
statusClass: string;
name: string;
url: string | null;
type: "HTTP(s)";
dailyRatios: ratio[];
"90dRatio": ratio;
"30dRatio": ratio;
};
}
]

View file

@ -1 +1 @@
["inv.bp.projectsegfau.lt","inv.zzls.xyz","invidious.0011.lt","invidious.baczek.me","invidious.lunar.icu","invidious.privacydev.net","invidious.tiekoetter.com","iv.ggtyler.dev","iv.melmac.space","vid.puffyan.us","y.com.sb","yewtu.be","yt.artemislena.eu"] ["www.youtubekids.com","inv.bp.projectsegfau.lt","inv.tux.pizza","inv.zzls.xyz","invidious.0011.lt","invidious.lunar.icu","invidious.privacydev.net","invidious.tiekoetter.com","iv.ggtyler.dev","iv.melmac.space","vid.priv.au","vid.puffyan.us","yewtu.be","yt.artemislena.eu"]