Errors Fixes

Add unplayable video error
This commit is contained in:
Killer069 2021-09-08 11:09:41 +05:30 committed by GitHub
commit bb4f71605e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,22 +45,21 @@ export async function video_basic_info(url : string, cookie? : string){
video_id = extractID(url)
}
else video_id = url
let new_url = 'https://www.youtube.com/watch?v=' + video_id
let new_url = `https://www.youtube.com/watch?v=${video_id}`
let body = await url_get(new_url, {
headers : (cookie) ? { 'cookie' : cookie } : {}
})
let player_response = JSON.parse(body.split("var ytInitialPlayerResponse = ")[1].split("}};")[0] + '}}')
let initial_response = JSON.parse(body.split("var ytInitialData = ")[1].split("}};")[0] + '}}')
let badge = initial_response.contents.twoColumnWatchNextResults.results.results.contents[1]?.videoSecondaryInfoRenderer?.owner?.videoOwnerRenderer?.badges && initial_response.contents.twoColumnWatchNextResults.results.results.contents[1]?.videoSecondaryInfoRenderer?.owner?.videoOwnerRenderer?.badges[0]
if(player_response.playabilityStatus.status === 'ERROR') throw new Error(`While getting info from url \n ${player_response.playabilityStatus.reason}`)
if(player_response.playabilityStatus.status === 'LOGIN_REQUIRED') throw new Error(`While getting info from url \n ${ player_response.playabilityStatus.reason || player_response.playabilityStatus.messages[0]}`)
let html5player = 'https://www.youtube.com' + body.split('"jsUrl":"')[1].split('"')[0]
if(player_response.playabilityStatus.status !== 'OK') throw new Error(`While getting info from url\n${player_response.playabilityStatus.reason || player_response.playabilityStatus.messages[0]}`)
let html5player = `https://www.youtube.com${body.split('"jsUrl":"')[1].split('"')[0]}`
let format = []
let vid = player_response.videoDetails
let microformat = player_response.microformat.playerMicroformatRenderer
let video_details = {
id : vid.videoId,
url : 'https://www.youtube.com/watch?v=' + vid.videoId,
url : `https://www.youtube.com/watch?v=${vid.videoId}`,
title : vid.title,
description : vid.shortDescription,
durationInSec : vid.lengthSeconds,
@ -83,8 +82,8 @@ export async function video_basic_info(url : string, cookie? : string){
format.push(...player_response.streamingData.adaptiveFormats)
let LiveStreamData = {
isLive : video_details.live,
dashManifestUrl : (player_response.streamingData?.dashManifestUrl) ? player_response.streamingData?.dashManifestUrl : null,
hlsManifestUrl : (player_response.streamingData?.hlsManifestUrl) ? player_response.streamingData?.hlsManifestUrl : null
dashManifestUrl : player_response.streamingData?.dashManifestUrl ?? null,
hlsManifestUrl : player_response.streamingData?.hlsManifestUrl ?? null
}
return {
LiveStreamData,
@ -134,10 +133,10 @@ export async function playlist_info(url : string, parseIncomplete : boolean = fa
let response = JSON.parse(body.split("var ytInitialData = ")[1].split(";</script>")[0])
if(response.alerts){
if(response.alerts[0].alertWithButtonRenderer?.type === 'INFO') {
if(!parseIncomplete) throw new Error(`While parsing playlist url\n ${response.alerts[0].alertWithButtonRenderer.text.simpleText}`)
if(!parseIncomplete) throw new Error(`While parsing playlist url\n${response.alerts[0].alertWithButtonRenderer.text.simpleText}`)
}
else if(response.alerts[0].alertRenderer?.type === 'ERROR') throw new Error(`While parsing playlist url\n ${response.alerts[0].alertRenderer.text.runs[0].text}`)
else throw new Error('While parsing playlist url\n Unknown Playlist Error')
else if(response.alerts[0].alertRenderer?.type === 'ERROR') throw new Error(`While parsing playlist url\n${response.alerts[0].alertRenderer.text.runs[0].text}`)
else throw new Error('While parsing playlist url\nUnknown Playlist Error')
}
let rawJSON = `${body.split('{"playlistVideoListRenderer":{"contents":')[1].split('}],"playlistId"')[0]}}]`;