piped instances suck

This commit is contained in:
localhost 2023-08-04 11:25:18 +02:00
parent a451e0ca17
commit 7d3c7a64d3
1 changed files with 9 additions and 3 deletions

View File

@ -1,7 +1,13 @@
const fetch = require('node-fetch') const fetch = require('node-fetch')
async function getInstance() { async function getInstance() {
return 'https://invidious.lain.la' const instances = await (await fetch('https://api.invidious.io/instances.json?pretty=1')).json()
return `https://${instances[Math.floor(Math.random() * instances.length)][0]}`
}
async function getPipedInstance() {
const instances = await (await fetch('https://piped-instances.kavin.rocks/')).json()
return (instances[Math.floor(Math.random() * instances.length)]).api_url
} }
async function getVideoMetadata(id) { async function getVideoMetadata(id) {
@ -20,7 +26,7 @@ async function getChannelVideos(id) {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
try { try {
const videos = [] const videos = []
const instance = 'https://pipedapi.kavin.rocks' const instance = await getPipedInstance()
const json = await (await fetch(`${instance}/channel/${id}`)).json() const json = await (await fetch(`${instance}/channel/${id}`)).json()
videos.push(...json.relatedStreams) videos.push(...json.relatedStreams)
if (json.nextpage) await getNextPage(json.nextpage) if (json.nextpage) await getNextPage(json.nextpage)
@ -42,7 +48,7 @@ async function getChannelVideos(id) {
} }
async function getPlaylistVideos(id) { async function getPlaylistVideos(id) {
const instance ='https://pipedapi.kavin.rocks' const instance = await getPipedInstance()
const json = await (await fetch(`${instance}/playlists/${id}`)).json() const json = await (await fetch(`${instance}/playlists/${id}`)).json()
return json return json
} }