mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
https Feature added
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { URL } from 'url'
|
||||
import { url_get } from './request'
|
||||
import { request } from './request'
|
||||
import querystring from 'querystring'
|
||||
|
||||
interface formatOptions {
|
||||
@@ -131,7 +131,6 @@ function deciper_signature(tokens : string[], signature :string){
|
||||
|
||||
function swappositions(array : string[], position : number){
|
||||
let first = array[0]
|
||||
let pos_args = array[position]
|
||||
array[0] = array[position]
|
||||
array[position] = first
|
||||
return array
|
||||
@@ -154,7 +153,7 @@ function download_url(format: formatOptions, sig : string){
|
||||
}
|
||||
|
||||
export async function format_decipher(formats: formatOptions[], html5player : string){
|
||||
let body = await url_get(html5player)
|
||||
let body = await request(html5player)
|
||||
let tokens = js_tokens(body)
|
||||
formats.forEach((format) => {
|
||||
let cipher = format.signatureCipher || format.cipher;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { url_get } from './request'
|
||||
import { request } from './request'
|
||||
import { format_decipher, js_tokens } from './cipher'
|
||||
import { Video } from '../classes/Video'
|
||||
import { PlayList } from '../classes/Playlist'
|
||||
@@ -46,7 +46,7 @@ export async function video_basic_info(url : string, cookie? : string){
|
||||
}
|
||||
else video_id = url
|
||||
let new_url = `https://www.youtube.com/watch?v=${video_id}`
|
||||
let body = await url_get(new_url, {
|
||||
let body = await request(new_url, {
|
||||
headers : (cookie) ? { 'cookie' : cookie, 'accept-language' : 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7' } : {'accept-language' : 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7'}
|
||||
})
|
||||
let player_response = JSON.parse(body.split("var ytInitialPlayerResponse = ")[1].split("}};")[0] + '}}')
|
||||
@@ -129,7 +129,7 @@ export async function playlist_info(url : string, parseIncomplete : boolean = fa
|
||||
else Playlist_id = url
|
||||
let new_url = `https://www.youtube.com/playlist?list=${Playlist_id}`
|
||||
|
||||
let body = await url_get(new_url, {
|
||||
let body = await request(new_url, {
|
||||
headers : {'accept-language' : 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7'}
|
||||
})
|
||||
let response = JSON.parse(body.split("var ytInitialData = ")[1].split(";</script>")[0])
|
||||
|
||||
@@ -1,9 +1,56 @@
|
||||
import got, { OptionsOfTextResponseBody } from 'got/dist/source'
|
||||
import https, { RequestOptions } from 'https'
|
||||
import {IncomingMessage } from 'http'
|
||||
import { URL } from 'url'
|
||||
|
||||
export async function url_get (url : string, options? : OptionsOfTextResponseBody) : Promise<string>{
|
||||
let response = await got(url, options)
|
||||
if(response.statusCode === 200) {
|
||||
return response.body
|
||||
}
|
||||
else throw new Error(`Got ${response.statusCode} from ${url}`)
|
||||
interface RequestOpts extends RequestOptions{
|
||||
body? : string;
|
||||
method? : "GET" | "POST"
|
||||
}
|
||||
|
||||
async function https_getter(req_url : string, options : RequestOpts = {}): Promise<IncomingMessage>{
|
||||
return new Promise((resolve, reject) => {
|
||||
let s = new URL(req_url)
|
||||
if(!options.method) options.method = "GET"
|
||||
let req_options : RequestOptions = {
|
||||
host : s.hostname,
|
||||
path : s.pathname + s.search,
|
||||
headers : (options.headers) ? options.headers : {}
|
||||
}
|
||||
|
||||
let req = https.request(req_options, (response) => {
|
||||
resolve(response)
|
||||
})
|
||||
if(options.method === "POST") req.write(options.body)
|
||||
req.end()
|
||||
})
|
||||
}
|
||||
|
||||
export async function request(url : string, options? : RequestOpts): Promise<string>{
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let data = ''
|
||||
let res = await https_getter(url, options)
|
||||
if(Number(res.statusCode) >= 300 && Number(res.statusCode) < 400){
|
||||
res = await https_getter(res.headers.location as string , options)
|
||||
}
|
||||
else if(Number(res.statusCode) > 400){
|
||||
reject(`Got ${res.statusCode} from the request`)
|
||||
}
|
||||
res.setEncoding('utf-8')
|
||||
res.on('data', (c) => data+=c)
|
||||
res.on('end', () => resolve(data))
|
||||
})
|
||||
}
|
||||
|
||||
export async function request_stream(url : string, options? : RequestOpts): Promise<IncomingMessage>{
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let data = ''
|
||||
let res = await https_getter(url, options)
|
||||
if(Number(res.statusCode) >= 300 && Number(res.statusCode) < 400){
|
||||
res = await https_getter(res.headers.location as string, options)
|
||||
}
|
||||
else if(Number(res.statusCode) > 400){
|
||||
reject(`Got ${res.statusCode} from the request`)
|
||||
}
|
||||
resolve(res)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user