multiple tried before quitting to get metadata
This commit is contained in:
		
							parent
							
								
									19247ce30d
								
							
						
					
					
						commit
						3a5a086cee
					
				| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
const fetch = require('node-fetch')
 | 
					const fetch = require('node-fetch')
 | 
				
			||||||
 | 
					const maxRetries = 5
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getInstance() {
 | 
					async function getInstance() {
 | 
				
			||||||
    const instances = await (await fetch('https://api.invidious.io/instances.json?pretty=1')).json()
 | 
					    const instances = await (await fetch('https://api.invidious.io/instances.json?pretty=1')).json()
 | 
				
			||||||
| 
						 | 
					@ -12,15 +13,43 @@ async function getPipedInstance() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getVideoMetadata(id) {
 | 
					async function getVideoMetadata(id) {
 | 
				
			||||||
 | 
					    for (let retries = 0; retries < maxRetries; retries++) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
            const instance = await getInstance()
 | 
					            const instance = await getInstance()
 | 
				
			||||||
    const json = await (await fetch(`${instance}/api/v1/videos/${id}?fields=videoId,title,descriptionHtml,videoThumbnails,published,authorId,error&pretty=1`)).json()
 | 
					            const response = await fetch(`${instance}/api/v1/videos/${id}?fields=videoId,title,descriptionHtml,videoThumbnails,published,authorId,error&pretty=1`)
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            if (response.ok) {
 | 
				
			||||||
 | 
					                const json = await response.json()
 | 
				
			||||||
                return json
 | 
					                return json
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } catch (error) {
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getChannel(id) {
 | 
					async function getChannel(id) {
 | 
				
			||||||
 | 
					    for (let retries = 0; retries < maxRetries; retries++) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
            const instance = await getInstance()
 | 
					            const instance = await getInstance()
 | 
				
			||||||
    const json = await (await fetch(`${instance}/api/v1/channels/${id}?pretty=1`)).json()
 | 
					            const response = await fetch(`${instance}/api/v1/channels/${id}?pretty=1`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (response.ok) {
 | 
				
			||||||
 | 
					                const json = await response.json()
 | 
				
			||||||
                return json
 | 
					                return json
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } catch (error) {
 | 
				
			||||||
 | 
					            continue
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function getChannelVideos(id) {
 | 
					async function getChannelVideos(id) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue