mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-03-31 06:34:05 +00:00
signature added. Almost Completed YouTube
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import fetch from 'node-fetch'
|
||||
import fs from 'fs'
|
||||
import got from 'got'
|
||||
import { format_decipher, js_tokens } from './cipher'
|
||||
|
||||
export function valid_url(url : string): boolean{
|
||||
let valid_url = /^https?:\/\/(youtu\.be\/|(www\.)?youtube\.com\/(embed|watch|v|shorts)(\/|\?))/
|
||||
@@ -8,30 +7,59 @@ export function valid_url(url : string): boolean{
|
||||
else return false
|
||||
}
|
||||
|
||||
export async function getBasicInfo(url : string){
|
||||
export async function yt_initial_data(url : string){
|
||||
if(valid_url(url)){
|
||||
let body = await url_get(url)
|
||||
let final = {
|
||||
player_response : get_ytPlayerResponse(body),
|
||||
response : get_ytInitialData(body),
|
||||
js_url : js_url(body)
|
||||
let player_response = JSON.parse(body.split("var ytInitialPlayerResponse = ")[1].split(";</script>")[0])
|
||||
let response = JSON.parse(body.split("var ytInitialData = ")[1].split(";</script>")[0])
|
||||
let html5player = 'https://www.youtube.com' + body.split('"jsUrl":"')[1].split('"')[0]
|
||||
let format = []
|
||||
format.push(player_response.streamingData.formats[0])
|
||||
format.push(...player_response.streamingData.adaptiveFormats)
|
||||
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,
|
||||
title : vid.title,
|
||||
description : vid.shortDescription,
|
||||
duration : vid.lengthSeconds,
|
||||
uploadedDate : microformat.publishDate,
|
||||
thumbnail : `https://i.ytimg.com/vi/${vid.videoId}/maxresdefault.jpg`,
|
||||
channel : {
|
||||
name : vid.author,
|
||||
id : vid.channelId,
|
||||
url : `https://www.youtube.com/channel/${vid.channelId}`
|
||||
},
|
||||
views : vid.viewCount,
|
||||
tags : vid.keywords,
|
||||
averageRating : vid.averageRating,
|
||||
live : vid.isLiveContent,
|
||||
private : vid.isPrivate
|
||||
}
|
||||
let final = {
|
||||
player_response,
|
||||
response,
|
||||
html5player,
|
||||
format,
|
||||
video_details
|
||||
}
|
||||
return final
|
||||
}
|
||||
else {
|
||||
throw 'Not a Valid YouTube URL'
|
||||
}
|
||||
}
|
||||
|
||||
function js_url(data:string): string {
|
||||
return data.split('"jsUrl":"')[1].split('"')[0]
|
||||
}
|
||||
|
||||
function get_ytPlayerResponse(data : string): JSON {
|
||||
return JSON.parse(data.split("var ytInitialPlayerResponse = ")[1].split(";</script>")[0])
|
||||
}
|
||||
|
||||
function get_ytInitialData(data:string): JSON {
|
||||
return JSON.parse(data.split("var ytInitialData = ")[1].split(";</script>")[0])
|
||||
export async function yt_deciphered_data(url : string) {
|
||||
let data = await yt_initial_data(url)
|
||||
if(data.format[0].signatureCipher || data.format[0].cipher){
|
||||
data.format = await format_decipher(data.format, data.html5player)
|
||||
return data
|
||||
}
|
||||
else {
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
export async function url_get (url : string) : Promise<string>{
|
||||
|
||||
Reference in New Issue
Block a user