add code to parse and filter

This commit is contained in:
Michael C 2021-11-30 15:55:26 -05:00
parent 2209c230e7
commit e4e453a11c
No known key found for this signature in database
GPG key ID: FFB04FB3B878B7B4
5 changed files with 56 additions and 2 deletions

1
.gitignore vendored
View file

@ -7,3 +7,4 @@ web-ext-artifacts
dist/ dist/
tmp/ tmp/
.DS_Store .DS_Store
src/ci/data.json

View file

@ -52,6 +52,7 @@
"build:watch": "npm run build:watch:chrome", "build:watch": "npm run build:watch:chrome",
"build:watch:chrome": "webpack --env.browser=chrome --config webpack/webpack.dev.js --watch", "build:watch:chrome": "webpack --env.browser=chrome --config webpack/webpack.dev.js --watch",
"build:watch:firefox": "webpack --env.browser=firefox --config webpack/webpack.dev.js --watch", "build:watch:firefox": "webpack --env.browser=firefox --config webpack/webpack.dev.js --watch",
"ci:invidious": "ts-node src/ci/invidiousCI.ts",
"dev": "npm run build:dev && concurrently \"npm run web-run\" \"npm run build:watch\"", "dev": "npm run build:dev && concurrently \"npm run web-run\" \"npm run build:watch\"",
"dev:firefox": "npm run build:dev:firefox && concurrently \"npm run web-run:firefox\" \"npm run build:watch:firefox\"", "dev:firefox": "npm run build:dev:firefox && concurrently \"npm run web-run:firefox\" \"npm run build:watch:firefox\"",
"dev:firefox-android": "npm run build:dev:firefox && concurrently \"npm run web-run:firefox-android\" \"npm run build:watch:firefox\"", "dev:firefox-android": "npm run build:dev:firefox && concurrently \"npm run web-run:firefox-android\" \"npm run build:watch:firefox\"",

50
src/ci/invidiousCI.ts Normal file
View file

@ -0,0 +1,50 @@
/*
This file is only ran by GitHub Actions in order to populate the Invidious instances list
This file should not be shipped with the extension
*/
import { writeFile } from 'fs';
import { join } from 'path';
// import file downloade from https://api.invidious.io/instances.json
import * as data from "./data.json";
type instanceMap = {
name: string,
url: string,
dailyRatios: {ratio: string, label: string }[],
thirtyDayUptime: string
}[]
// 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) => {
return {
name: instance[0],
url: instance[1].uri,
dailyRatios: instance[1].monitor.dailyRatios,
thirtyDayUptime: instance[1]?.monitor['30dRatio'].ratio,
}
})
// reliability and sanity checks
const reliableCheck = mapped
.filter((instance) => {
// 30d uptime >= 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)
})
// url includes name
.filter(instance => instance.url.includes(instance.name))
// finally map to array
const result: string[] = reliableCheck.map(instance => instance.name)
writeFile(join(__dirname, "./invidiouslist.json"), JSON.stringify(result), (err) => {
if (err) return console.log(err);
})

View file

@ -0,0 +1 @@
["yewtu.be","invidious.snopyta.org","vid.puffyan.us","invidious.kavin.rocks","invidio.xamh.de","invidious-us.kavin.rocks","inv.riverside.rocks","vid.mint.lgbt","youtube.076.ne.jp","invidious.namazso.eu"]

View file

@ -1,4 +1,5 @@
import * as CompileConfig from "../config.json"; import * as CompileConfig from "../config.json";
import * as invidiousList from "../src/ci/invidiouslist.json";
import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, PreviewBarOption, SponsorTime, StorageChangesObject, UnEncodedSegmentTimes as UnencodedSegmentTimes } from "./types"; import { Category, CategorySelection, CategorySkipOption, NoticeVisbilityMode, PreviewBarOption, SponsorTime, StorageChangesObject, UnEncodedSegmentTimes as UnencodedSegmentTimes } from "./types";
interface SBConfig { interface SBConfig {
@ -188,7 +189,7 @@ const Config: SBObject = {
hideSkipButtonPlayerControls: false, hideSkipButtonPlayerControls: false,
hideDiscordLaunches: 0, hideDiscordLaunches: 0,
hideDiscordLink: false, hideDiscordLink: false,
invidiousInstances: ["invidious.snopyta.org"], invidiousInstances: invidiousList,
supportInvidious: false, supportInvidious: false,
serverAddress: CompileConfig.serverAddress, serverAddress: CompileConfig.serverAddress,
minDuration: 0, minDuration: 0,