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