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