Cookies Update
This commit is contained in:
parent
382447f397
commit
379b38c363
@ -35,8 +35,8 @@ function parseAudioFormats(formats : any[]){
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function stream(url : string): Promise<Stream | LiveStreaming | LiveEnded>{
|
export async function stream(url : string, cookie? : string): Promise<Stream | LiveStreaming | LiveEnded>{
|
||||||
let info = await video_info(url)
|
let info = await video_info(url, cookie)
|
||||||
let final: any[] = [];
|
let final: any[] = [];
|
||||||
let type : StreamType;
|
let type : StreamType;
|
||||||
if(info.LiveStreamData.isLive === true && info.LiveStreamData.hlsManifestUrl !== null) {
|
if(info.LiveStreamData.isLive === true && info.LiveStreamData.hlsManifestUrl !== null) {
|
||||||
|
|||||||
@ -21,14 +21,16 @@ export function validate_playlist(url : string): boolean{
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function video_basic_info(url : string){
|
export async function video_basic_info(url : string, cookie? : string){
|
||||||
if(!url.match(video_pattern)) throw new Error('This is not a YouTube URL')
|
if(!url.match(video_pattern)) throw new Error('This is not a YouTube URL')
|
||||||
let video_id : string;
|
let video_id : string;
|
||||||
if(url.includes('youtu.be/')) video_id = url.split('youtu.be/')[1].split('/')[0]
|
if(url.includes('youtu.be/')) video_id = url.split('youtu.be/')[1].split('/')[0]
|
||||||
else if(url.includes('youtube.com/embed/')) video_id = url.split('youtube.com/embed/')[1].split('/')[0]
|
else if(url.includes('youtube.com/embed/')) video_id = url.split('youtube.com/embed/')[1].split('/')[0]
|
||||||
else video_id = url.split('watch?v=')[1].split('&')[0];
|
else video_id = url.split('watch?v=')[1].split('&')[0];
|
||||||
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)
|
let body = await url_get(new_url, {
|
||||||
|
headers : (cookie) ? { 'cookie' : cookie } : {}
|
||||||
|
})
|
||||||
let player_response = JSON.parse(body.split("var ytInitialPlayerResponse = ")[1].split("}};")[0] + '}}')
|
let player_response = JSON.parse(body.split("var ytInitialPlayerResponse = ")[1].split("}};")[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 === '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]}`)
|
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]}`)
|
||||||
@ -83,8 +85,8 @@ function parseSeconds(seconds : number): string {
|
|||||||
return hDisplay + mDisplay + sDisplay;
|
return hDisplay + mDisplay + sDisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function video_info(url : string) {
|
export async function video_info(url : string, cookie? : string) {
|
||||||
let data = await video_basic_info(url)
|
let data = await video_basic_info(url, cookie)
|
||||||
if(data.LiveStreamData.isLive === true && data.LiveStreamData.hlsManifestUrl !== null){
|
if(data.LiveStreamData.isLive === true && data.LiveStreamData.hlsManifestUrl !== null){
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user