mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
YouTube is closing soon.....
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { URL } from 'node:url'
|
||||
import { url_get } from './extractor'
|
||||
import { url_get } from './request'
|
||||
import querystring from 'node:querystring'
|
||||
|
||||
interface formatOptions {
|
||||
@@ -102,7 +102,7 @@ export function js_tokens( body:string ) {
|
||||
return tokens
|
||||
}
|
||||
|
||||
export function deciper_signature(tokens : string[], signature :string){
|
||||
function deciper_signature(tokens : string[], signature :string){
|
||||
let sig = signature.split('')
|
||||
let len = tokens.length
|
||||
for(let i = 0; i < len; i++ ){
|
||||
@@ -137,7 +137,7 @@ function swappositions(array : string[], position : number){
|
||||
return array
|
||||
}
|
||||
|
||||
export function download_url(format: formatOptions, sig : string){
|
||||
function download_url(format: formatOptions, sig : string){
|
||||
let decoded_url;
|
||||
if(!format.url) return;
|
||||
decoded_url = format.url
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
import fetch from 'node-fetch'
|
||||
import { url_get } from './request'
|
||||
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)(\/|\?))/
|
||||
if(url.search(valid_url) !== -1) return true
|
||||
else return false
|
||||
}
|
||||
|
||||
export async function yt_initial_data(url : string){
|
||||
if(valid_url(url)){
|
||||
let body = await url_get(url)
|
||||
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])
|
||||
@@ -45,10 +39,6 @@ export async function yt_initial_data(url : string){
|
||||
video_details
|
||||
}
|
||||
return final
|
||||
}
|
||||
else {
|
||||
throw 'Not a Valid YouTube URL'
|
||||
}
|
||||
}
|
||||
|
||||
export async function yt_deciphered_data(url : string) {
|
||||
@@ -61,14 +51,3 @@ export async function yt_deciphered_data(url : string) {
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
export async function url_get (url : string) : Promise<string>{
|
||||
return new Promise(async(resolve, reject) => {
|
||||
let response = await fetch(url)
|
||||
|
||||
if(response.status === 200) {
|
||||
resolve(await response.text())
|
||||
}
|
||||
else reject(`Got ${response.status} from ${url}`)
|
||||
})
|
||||
}
|
||||
|
||||
1
node-youtube-dl/YouTube/utils/index.ts
Normal file
1
node-youtube-dl/YouTube/utils/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export { yt_initial_data, yt_deciphered_data } from './extractor'
|
||||
6
node-youtube-dl/YouTube/utils/parser.ts
Normal file
6
node-youtube-dl/YouTube/utils/parser.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { Video } from "../classes/Video";
|
||||
|
||||
|
||||
export function ParseSearchResult(html:string) {
|
||||
|
||||
}
|
||||
12
node-youtube-dl/YouTube/utils/request.ts
Normal file
12
node-youtube-dl/YouTube/utils/request.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import fetch, { RequestInit } from 'node-fetch'
|
||||
|
||||
export async function url_get (url : string, options? : RequestInit) : Promise<string>{
|
||||
return new Promise(async(resolve, reject) => {
|
||||
let response = await fetch(url, options)
|
||||
|
||||
if(response.status === 200) {
|
||||
resolve(await response.text())
|
||||
}
|
||||
else reject(`Got ${response.status} from ${url}`)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user