mirror of https://github.com/preservetube/auto.git
multiple tried before quitting to get metadata
This commit is contained in:
parent
246bd8e4d2
commit
32d7451ef4
|
@ -1,4 +1,5 @@
|
||||||
const fetch = require('node-fetch')
|
const fetch = require('node-fetch')
|
||||||
|
const maxRetries = 5
|
||||||
|
|
||||||
async function getInstance() {
|
async function getInstance() {
|
||||||
const instances = await (await fetch('https://api.invidious.io/instances.json?pretty=1')).json()
|
const instances = await (await fetch('https://api.invidious.io/instances.json?pretty=1')).json()
|
||||||
|
@ -12,15 +13,43 @@ async function getPipedInstance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getVideoMetadata(id) {
|
async function getVideoMetadata(id) {
|
||||||
|
for (let retries = 0; retries < maxRetries; retries++) {
|
||||||
|
try {
|
||||||
const instance = await getInstance()
|
const instance = await getInstance()
|
||||||
const json = await (await fetch(`${instance}/api/v1/videos/${id}?fields=videoId,title,descriptionHtml,videoThumbnails,published,authorId&pretty=1`)).json()
|
const response = await fetch(`${instance}/api/v1/videos/${id}?fields=videoId,title,descriptionHtml,videoThumbnails,published,authorId&pretty=1`)
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const json = await response.json()
|
||||||
return json
|
return json
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChannel(id) {
|
async function getChannel(id) {
|
||||||
|
for (let retries = 0; retries < maxRetries; retries++) {
|
||||||
|
try {
|
||||||
const instance = await getInstance()
|
const instance = await getInstance()
|
||||||
const json = await (await fetch(`${instance}/api/v1/channels/${id}?pretty=1`)).json()
|
const response = await fetch(`${instance}/api/v1/channels/${id}?pretty=1`)
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
const json = await response.json()
|
||||||
return json
|
return json
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChannelVideos(id) {
|
async function getChannelVideos(id) {
|
||||||
|
|
Loading…
Reference in New Issue