putting a list of instances. hoping to host my own soon

This commit is contained in:
localhost 2023-07-22 13:39:47 +03:00
parent 3804b519ba
commit 3302de2430
1 changed files with 19 additions and 33 deletions

View File

@ -1,40 +1,26 @@
const fetch = require('node-fetch') const fetch = require('node-fetch')
async function getInstance() { async function getInstance() {
for (let i = 0; i < 5; i++) { const instances = [
const test = await actualRequest() 'https://pipedapi.kavin.rocks',
if (test) return test 'https://pipedapi-libre.kavin.rocks',
} 'https://piped-api.privacy.com.de',
'https://api.piped.projectsegfau.lt',
async function getActualInstance() { 'https://pipedapi.in.projectsegfau.lt',
const instances = await (await fetch('https://piped-instances.kavin.rocks/')).json() 'https://pipedapi.us.projectsegfau.lt',
return (instances[Math.floor(Math.random() * instances.length)]).api_url 'https://watchapi.whatever.social',
} 'https://api.piped.privacydev.net',
'https://pipedapi.palveluntarjoaja.eu',
async function testInstance(instance) { 'https://pipedapi.smnz.de',
try { 'https://pipedapi.adminforge.de',
const videoRequest = await fetch(`${instance}/streams/dQw4w9WgXcQ`) 'https://pipedapi.qdi.fi',
const videoJson = await videoRequest.json() 'https://piped-api.hostux.net',
const thumbnailRequest = await fetch(videoJson.thumbnailUrl) 'https://api.piped.yt',
'https://pipedapi.osphost.fi',
return (videoRequest.status == 200) && (thumbnailRequest.status == 200) 'https://pipedapi.simpleprivacy.fr'
} catch (e) { ]
return false
}
}
async function actualRequest() {
try {
const instance = await getActualInstance()
const instanceTest = await testInstance(instance)
if (instanceTest) return instance
else return false
} catch (e) {
return false
}
}
return instances[Math.floor(Math.random() * instances.length)]
} }
async function getVideoMetadata(id) { async function getVideoMetadata(id) {