making it switch thru platforms & retries
This commit is contained in:
		
							parent
							
								
									593c155fdf
								
							
						
					
					
						commit
						b2154ea8d2
					
				| 
						 | 
					@ -1,7 +1,9 @@
 | 
				
			||||||
const { Innertube } = require('youtubei.js');
 | 
					const { Innertube } = require('youtubei.js');
 | 
				
			||||||
const fetch = require('node-fetch')
 | 
					const fetch = require('node-fetch')
 | 
				
			||||||
const https = require('https')
 | 
					const https = require('https')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const maxRetries = 5
 | 
					const maxRetries = 5
 | 
				
			||||||
 | 
					const platforms = ['WEB', 'ANDROID', 'iOS']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const ignoreSsl = new https.Agent({
 | 
					const ignoreSsl = new https.Agent({
 | 
				
			||||||
    rejectUnauthorized: false,
 | 
					    rejectUnauthorized: false,
 | 
				
			||||||
| 
						 | 
					@ -28,36 +30,56 @@ async function getPipedInstance() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getVideoMetadata(id) {
 | 
					async function getVideoMetadata(id) {
 | 
				
			||||||
 | 
					    let error = ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (let retries = 0; retries < maxRetries; retries++) {
 | 
					    for (let retries = 0; retries < maxRetries; retries++) {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					            const platform = platforms[retries % platforms.length];
 | 
				
			||||||
 | 
					            console.log(platform)
 | 
				
			||||||
            const yt = await Innertube.create();
 | 
					            const yt = await Innertube.create();
 | 
				
			||||||
            const info = await yt.getInfo(id, 'WEB');
 | 
					            const info = await yt.getInfo(id, platform);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!info) return { error: 'ErrorCantConnectToServiceAPI' }; // stolen from cobalt :)
 | 
					            if (!info) {
 | 
				
			||||||
            if (info.playability_status.status !== 'OK') return { error: 'ErrorYTUnavailable' };
 | 
					                error = 'ErrorCantConnectToServiceAPI'
 | 
				
			||||||
            if (info.basic_info.is_live) return { error: 'ErrorLiveVideo' };
 | 
					                continue; 
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (info.playability_status.status !== 'OK') {
 | 
				
			||||||
 | 
					                error = 'ErrorYTUnavailable'
 | 
				
			||||||
 | 
					                continue; 
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if (info.basic_info.is_live) {
 | 
				
			||||||
 | 
					                error = 'ErrorLiveVideo'
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            return info
 | 
					            return info
 | 
				
			||||||
        } catch (error) {
 | 
					        } catch (error) {
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return false
 | 
					    return { error: error || 'ErrorUnknown' }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getChannel(id) {
 | 
					async function getChannel(id) {
 | 
				
			||||||
 | 
					    let error = ''
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (let retries = 0; retries < maxRetries; retries++) {
 | 
					    for (let retries = 0; retries < maxRetries; retries++) {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
 | 
					            const platform = platforms[retries % platforms.length];
 | 
				
			||||||
            const yt = await Innertube.create();
 | 
					            const yt = await Innertube.create();
 | 
				
			||||||
            const info = await yt.getChannel(id, 'WEB');
 | 
					            const info = await yt.getChannel(id, platform);
 | 
				
			||||||
            if (!info) return { error: 'ErrorCantConnectToServiceAPI' }; // stolen from cobalt :)
 | 
					
 | 
				
			||||||
 | 
					            if (!info) {
 | 
				
			||||||
 | 
					                error = 'ErrorCantConnectToServiceAPI'
 | 
				
			||||||
 | 
					                continue; 
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
            return info
 | 
					            return info
 | 
				
			||||||
        } catch (error) {
 | 
					        } catch (error) {
 | 
				
			||||||
            continue
 | 
					            continue
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return false
 | 
					    return { error: error || 'ErrorUnknown' }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getChannelVideos(id) {
 | 
					async function getChannelVideos(id) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue