2023-03-03 16:44:40 +00:00
|
|
|
const fetch = require('node-fetch')
|
|
|
|
|
|
|
|
async function getInstance() {
|
2023-07-22 11:39:47 +01:00
|
|
|
const instances = [
|
|
|
|
'https://pipedapi.kavin.rocks',
|
|
|
|
'https://pipedapi-libre.kavin.rocks',
|
|
|
|
'https://piped-api.privacy.com.de',
|
|
|
|
'https://api.piped.projectsegfau.lt',
|
|
|
|
'https://pipedapi.in.projectsegfau.lt',
|
|
|
|
'https://pipedapi.us.projectsegfau.lt',
|
|
|
|
'https://watchapi.whatever.social',
|
|
|
|
'https://api.piped.privacydev.net',
|
|
|
|
'https://pipedapi.palveluntarjoaja.eu',
|
|
|
|
'https://pipedapi.smnz.de',
|
|
|
|
'https://pipedapi.adminforge.de',
|
|
|
|
'https://pipedapi.qdi.fi',
|
|
|
|
'https://piped-api.hostux.net',
|
|
|
|
'https://api.piped.yt',
|
|
|
|
'https://pipedapi.osphost.fi',
|
|
|
|
'https://pipedapi.simpleprivacy.fr'
|
|
|
|
]
|
|
|
|
|
|
|
|
return instances[Math.floor(Math.random() * instances.length)]
|
2023-06-22 12:15:02 +01:00
|
|
|
}
|
2023-03-24 15:07:31 +00:00
|
|
|
|
2023-06-22 12:15:02 +01:00
|
|
|
async function getVideoMetadata(id) {
|
|
|
|
const instance = await getInstance()
|
|
|
|
const json = await (await fetch(`${instance}/streams/${id}`)).json()
|
|
|
|
return json
|
2023-03-23 16:01:46 +00:00
|
|
|
}
|
|
|
|
|
2023-06-22 12:15:02 +01:00
|
|
|
async function getChannel(id) {
|
|
|
|
const instance = await getInstance()
|
|
|
|
const json = await (await fetch(`${instance}/channel/${id}`)).json()
|
|
|
|
return json
|
|
|
|
}
|
2023-03-24 14:20:06 +00:00
|
|
|
|
2023-06-22 12:15:02 +01:00
|
|
|
async function getChannelVideos(id) {
|
|
|
|
return new Promise(async (resolve, reject) => {
|
2023-03-24 14:20:06 +00:00
|
|
|
try {
|
2023-06-22 12:15:02 +01:00
|
|
|
const videos = []
|
2023-03-24 14:20:06 +00:00
|
|
|
const instance = await getInstance()
|
2023-06-22 12:15:02 +01:00
|
|
|
const json = await (await fetch(`${instance}/channel/${id}`)).json()
|
|
|
|
videos.push(...json.relatedStreams)
|
|
|
|
if (json.nextpage) await getNextPage(json.nextpage)
|
|
|
|
else resolve(videos)
|
|
|
|
|
|
|
|
async function getNextPage(payload) {
|
|
|
|
const page = await (await fetch(`${instance}/nextpage/channel/${id}?nextpage=${encodeURIComponent(payload)}`)).json()
|
|
|
|
videos.push(...page.relatedStreams)
|
|
|
|
|
2023-07-06 15:19:36 +01:00
|
|
|
if (videos.length >= 60) resolve(videos)
|
2023-06-22 12:15:02 +01:00
|
|
|
if (page.nextpage) await getNextPage(page.nextpage)
|
|
|
|
else resolve(videos)
|
|
|
|
}
|
|
|
|
|
2023-03-24 14:20:06 +00:00
|
|
|
} catch (e) {
|
2023-06-22 12:15:02 +01:00
|
|
|
resolve(false)
|
2023-03-24 14:20:06 +00:00
|
|
|
}
|
2023-06-22 12:15:02 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getPlaylistVideos(id) {
|
|
|
|
const instance = await getInstance()
|
|
|
|
const json = await (await fetch(`${instance}/playlists/${id}`)).json()
|
|
|
|
return json
|
2023-03-03 16:44:40 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 16:01:46 +00:00
|
|
|
module.exports = { getInstance, getVideoMetadata, getChannel, getChannelVideos, getPlaylistVideos }
|