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