fml
This commit is contained in:
parent
cfe48bcb0a
commit
0083081fbd
|
@ -4,6 +4,7 @@ const https = require('https')
|
|||
|
||||
const maxRetries = 5
|
||||
const platforms = ['WEB', 'ANDROID', 'iOS']
|
||||
const cobalt = ['http://cobalt-api:9000', 'https://co.wuk.sh', 'http://cobalt-api:9000']
|
||||
|
||||
const ignoreSsl = new https.Agent({
|
||||
rejectUnauthorized: false,
|
||||
|
@ -125,7 +126,12 @@ async function getPlaylistVideos(id) {
|
|||
}
|
||||
|
||||
async function getVideoDownload(url, quality) {
|
||||
const json = await (await fetch('http://cobalt-api:9000/api/json', {
|
||||
let json
|
||||
|
||||
for (let retries = 0; retries < maxRetries; retries++) {
|
||||
try {
|
||||
const instance = cobalt[retries % cobalt.length];
|
||||
json = await (await fetch(`${instance}/api/json`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
|
@ -137,6 +143,13 @@ async function getVideoDownload(url, quality) {
|
|||
})
|
||||
})).json()
|
||||
|
||||
if (json.error) continue
|
||||
return json
|
||||
} catch (error) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return json
|
||||
}
|
||||
|
||||
|
|
|
@ -8,17 +8,16 @@ async function downloadVideo(url, ws, id) {
|
|||
let quality = '720p'
|
||||
const video = await metadata.getVideoMetadata(id)
|
||||
if (video.error) {
|
||||
resolve({
|
||||
return resolve({
|
||||
message: `Failed to request Youtube with error ${video.error}. Please retry...`,
|
||||
fail: true
|
||||
})
|
||||
}
|
||||
if (video.basic_info.duration >= 900) quality = '360p' // 15 minutes
|
||||
|
||||
if (video.basic_info.duration > 1200) quality = '480p' // 20 minutes
|
||||
if (video.basic_info.duration > 2100) quality = '360p' // 35 minutes
|
||||
const downloadJson = await metadata.getVideoDownload(url, quality)
|
||||
if (downloadJson.status == 'error') {
|
||||
resolve({
|
||||
return resolve({
|
||||
message: 'Failed to request Youtube. Please retry...',
|
||||
fail: true
|
||||
})
|
||||
|
@ -61,11 +60,11 @@ async function downloadVideo(url, ws, id) {
|
|||
download.on('end', output => {
|
||||
if (output == 'Finished writing to disk') {
|
||||
ws.send(`DATA - Download has finished`)
|
||||
resolve({
|
||||
return resolve({
|
||||
fail: false
|
||||
})
|
||||
} else {
|
||||
resolve({
|
||||
return resolve({
|
||||
fail: true
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue