removing need for cobalt
This commit is contained in:
parent
1640db9d23
commit
7a0089d3e6
|
@ -1,5 +1,4 @@
|
|||
const fetch = require('node-fetch')
|
||||
const maxRetries = 5
|
||||
|
||||
async function getPipedInstance() {
|
||||
const instances = await (await fetch('https://piped-instances.kavin.rocks/', {
|
||||
|
@ -32,31 +31,27 @@ async function getPlaylistVideos(id) {
|
|||
return json
|
||||
}
|
||||
|
||||
async function getVideoDownload(url, quality) {
|
||||
let json
|
||||
|
||||
for (let retries = 0; retries < maxRetries; retries++) {
|
||||
try {
|
||||
json = await (await fetch('http://gluetun:9000/api/json', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
'url': url,
|
||||
'vQuality': quality
|
||||
})
|
||||
})).json()
|
||||
|
||||
if (json.error) continue
|
||||
return json
|
||||
} catch (error) {
|
||||
continue
|
||||
async function getVideoDownload(json, quality) {
|
||||
const adaptiveFormats = json['streaming_data']['adaptive_formats'];
|
||||
let video = adaptiveFormats.find(f => f.quality_label === `${quality}p` && !f.has_audio);
|
||||
if (!video) { // stupid bullshit. basically finding the lowest quality if the quality specified isnt there
|
||||
video = adaptiveFormats.filter(f => !f.has_audio).reduce((prev, current) => {
|
||||
if (!prev || parseInt(current.quality_label) < parseInt(prev.quality_label)) {
|
||||
return current;
|
||||
}
|
||||
return prev;
|
||||
}, null);
|
||||
}
|
||||
|
||||
return json
|
||||
const audio = adaptiveFormats.find(f => f.has_audio);
|
||||
|
||||
return {
|
||||
url: [
|
||||
video.url,
|
||||
audio.url
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
module.exports = { getVideoMetadata, getChannel, getChannelVideos, getPlaylistVideos, getVideoDownload }
|
|
@ -5,7 +5,6 @@ const hr = require('@tsmx/human-readable')
|
|||
|
||||
const ffmpeg = require('fluent-ffmpeg')
|
||||
const ffmpegStatic = require('ffmpeg-static')
|
||||
const path = require('node:path')
|
||||
const fs = require('node:fs')
|
||||
|
||||
ffmpeg.setFfmpegPath(ffmpegStatic)
|
||||
|
@ -22,13 +21,7 @@ async function downloadVideo(url, ws, id) {
|
|||
}
|
||||
if (video.basic_info.duration >= 900) quality = '360' // 15 minutes
|
||||
|
||||
const downloadJson = await metadata.getVideoDownload(url, quality)
|
||||
if (downloadJson.status == 'error') {
|
||||
return resolve({
|
||||
message: `Failed to request Youtube with error ${downloadJson.text}. Please retry...`,
|
||||
fail: true
|
||||
})
|
||||
}
|
||||
const downloadJson = await metadata.getVideoDownload(video, quality)
|
||||
|
||||
let size = ''
|
||||
let startTime = Date.now()
|
||||
|
|
Loading…
Reference in New Issue