aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMichael C <[email protected]>2021-11-30 15:55:26 -0500
committerMichael C <[email protected]>2021-11-30 15:55:26 -0500
commite4e453a11c776bb4127e07252f868c3e54e3e386 (patch)
tree98900cd9c8d746781576b9ec672d9874cb72ab41
parent2209c230e7d41476e4da8a78f87dbec2740a6dc1 (diff)
downloadSponsorBlock-e4e453a11c776bb4127e07252f868c3e54e3e386.tar.gz
SponsorBlock-e4e453a11c776bb4127e07252f868c3e54e3e386.zip
add code to parse and filter
-rw-r--r--.gitignore3
-rw-r--r--package.json1
-rw-r--r--src/ci/invidiousCI.ts50
-rw-r--r--src/ci/invidiouslist.json1
-rw-r--r--src/config.ts3
5 files changed, 56 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 2833884c..3dcdb226 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,4 +6,5 @@ web-ext-artifacts
.vscode/
dist/
tmp/
-.DS_Store \ No newline at end of file
+.DS_Store
+src/ci/data.json \ No newline at end of file
diff --git a/package.json b/package.json
index 2f59a888..963c1203 100644
--- a/package.json
+++ b/package.json
@@ -52,6 +52,7 @@
"build:watch": "npm run build:watch:chrome",
"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",
+ "ci:invidious": "ts-node src/ci/invidiousCI.ts",
"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-android": "npm run build:dev:firefox && concurrently \"npm run web-run:firefox-android\" \"npm run build:watch:firefox\"",
diff --git a/src/ci/invidiousCI.ts b/src/ci/invidiousCI.ts
new file mode 100644
index 00000000..2c4a8089
--- /dev/null
+++ b/src/ci/invidiousCI.ts
@@ -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);
+}) \ No newline at end of file
diff --git a/src/ci/invidiouslist.json b/src/ci/invidiouslist.json
new file mode 100644
index 00000000..905605d8
--- /dev/null
+++ b/src/ci/invidiouslist.json
@@ -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"] \ No newline at end of file
diff --git a/src/config.ts b/src/config.ts
index 344a7b62..912f87dc 100644
--- a/src/config.ts
+++ b/src/config.ts
@@ -1,4 +1,5 @@
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";
interface SBConfig {
@@ -188,7 +189,7 @@ const Config: SBObject = {
hideSkipButtonPlayerControls: false,
hideDiscordLaunches: 0,
hideDiscordLink: false,
- invidiousInstances: ["invidious.snopyta.org"],
+ invidiousInstances: invidiousList,
supportInvidious: false,
serverAddress: CompileConfig.serverAddress,
minDuration: 0,