From ccbf7e21551bc03ca92746530e70acb2c6535551 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Sat, 20 May 2023 09:07:04 -0400 Subject: [PATCH] Use script to create Invidious instance list file (#3545) * Use script to create static instance list * save cors, filter out cors when not electron --- _scripts/getInstances.js | 16 ++++ package.json | 1 + src/renderer/store/modules/invidious.js | 6 +- static/invidious-instances.json | 121 +++++++++++++++++++----- 4 files changed, 118 insertions(+), 26 deletions(-) create mode 100644 _scripts/getInstances.js diff --git a/_scripts/getInstances.js b/_scripts/getInstances.js new file mode 100644 index 000000000..d1b5bdb9b --- /dev/null +++ b/_scripts/getInstances.js @@ -0,0 +1,16 @@ +const fs = require('fs/promises') +const invidiousApiUrl = 'https://api.invidious.io/instances.json' + +fetch(invidiousApiUrl).then(e => e.json()).then(res => { + const data = res.filter((instance) => { + return !(instance[0].includes('.onion') || + instance[0].includes('.i2p') || + !instance[1].api) + }).map((instance) => { + return { + url: instance[1].uri.replace(/\/$/, ''), + cors: instance[1].cors + } + }) + fs.writeFile('././static/invidious-instances.json', JSON.stringify(data, null, 2)) +}) diff --git a/package.json b/package.json index 31205e985..aa28d89b8 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "dev": "run-s rebuild:electron dev-runner", "dev:web": "node _scripts/dev-runner.js --web", "dev-runner": "node _scripts/dev-runner.js", + "get-instances": "node _scripts/getInstances.js", "lint-all": "run-p lint lint-json lint-style", "lint-fix": "eslint --fix --ext .js,.vue ./", "lint": "eslint --ext .js,.vue ./", diff --git a/src/renderer/store/modules/invidious.js b/src/renderer/store/modules/invidious.js index c188b90cc..f6a456366 100644 --- a/src/renderer/store/modules/invidious.js +++ b/src/renderer/store/modules/invidious.js @@ -44,8 +44,10 @@ const actions = { if (await pathExists(`${fileLocation}${fileName}`)) { console.warn('reading static file for invidious instances') const fileData = await fs.readFile(`${fileLocation}${fileName}`) - instances = JSON.parse(fileData).map((entry) => { - return entry.url + instances = JSON.parse(fileData).filter(e => { + return process.env.IS_ELECTRON || e.cors + }).map(e => { + return e.url }) } } diff --git a/static/invidious-instances.json b/static/invidious-instances.json index c1803061c..f5c1792ec 100644 --- a/static/invidious-instances.json +++ b/static/invidious-instances.json @@ -1,25 +1,98 @@ [ - { "url": "https://vid.puffyan.us" }, - { "url": "https://inv.riverside.rocks" }, - { "url": "https://watch.thekitty.zone" }, - { "url": "https://y.com.sb" }, - { "url": "https://invidious.nerdvpn.de" }, - { "url": "https://invidious.tiekoetter.com" }, - { "url": "https://yt.artemislena.eu" }, - { "url": "https://invidious.flokinet.to" }, - { "url": "https://inv.bp.projectsegfau.lt" }, - { "url": "https://inv.odyssey346.dev" }, - { "url": "https://invidious.sethforprivacy.com" }, - { "url": "https://invidious.projectsegfau.lt" }, - { "url": "https://invidious.baczek.me" }, - { "url": "https://yt.funami.tech" }, - { "url": "https://iv.ggtyler.dev" }, - { "url": "https://invidious.lunar.icu" }, - { "url": "https://invidious.privacydev.net" }, - { "url": "https://vid.priv.au" }, - { "url": "https://invidious.0011.lt" }, - { "url": "https://iv.melmac.space" }, - { "url": "https://invidious.esmailelbob.xyz" }, - { "url": "https://invidious.vpsburti.com" }, - { "url": "https://invidious.snopyta.org" } -] + { + "url": "https://vid.puffyan.us", + "cors": true + }, + { + "url": "https://inv.riverside.rocks", + "cors": true + }, + { + "url": "https://invidious.nerdvpn.de", + "cors": true + }, + { + "url": "https://invidious.tiekoetter.com", + "cors": true + }, + { + "url": "https://inv.bp.projectsegfau.lt", + "cors": true + }, + { + "url": "https://invidious.flokinet.to", + "cors": true + }, + { + "url": "https://yt.artemislena.eu", + "cors": true + }, + { + "url": "https://inv.pistasjis.net", + "cors": true + }, + { + "url": "https://invidious.sethforprivacy.com", + "cors": true + }, + { + "url": "https://invidious.projectsegfau.lt", + "cors": true + }, + { + "url": "https://invidious.baczek.me", + "cors": true + }, + { + "url": "https://yt.funami.tech", + "cors": true + }, + { + "url": "https://iv.ggtyler.dev", + "cors": true + }, + { + "url": "https://invidious.lunar.icu", + "cors": true + }, + { + "url": "https://invidious.privacydev.net", + "cors": true + }, + { + "url": "https://vid.priv.au", + "cors": true + }, + { + "url": "https://invidious.0011.lt", + "cors": true + }, + { + "url": "https://inv.zzls.xyz", + "cors": true + }, + { + "url": "https://invidious.slipfox.xyz", + "cors": true + }, + { + "url": "https://yt.floss.media", + "cors": false + }, + { + "url": "https://invidious.nogafa.org", + "cors": true + }, + { + "url": "https://iv.melmac.space", + "cors": true + }, + { + "url": "https://invidious.esmailelbob.xyz", + "cors": true + }, + { + "url": "https://invidious.snopyta.org", + "cors": true + } +] \ No newline at end of file