Merge pull request #146 from absidue/misc-improvements

Miscellaneous improvements
This commit is contained in:
Killer069 2021-10-29 15:06:18 +05:30 committed by GitHub
commit 76ab060d57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 28 additions and 27 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "play-dl", "name": "play-dl",
"version": "1.2.3", "version": "1.2.5",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "play-dl", "name": "play-dl",
"version": "1.2.3", "version": "1.2.5",
"license": "GPL-3.0", "license": "GPL-3.0",
"devDependencies": { "devDependencies": {
"@types/node": "^16.9.4", "@types/node": "^16.9.4",

View File

@ -1,6 +1,6 @@
{ {
"name": "play-dl", "name": "play-dl",
"version": "1.2.3", "version": "1.2.5",
"description": "YouTube, SoundCloud, Spotify streaming for discord.js bots", "description": "YouTube, SoundCloud, Spotify streaming for discord.js bots",
"main": "dist/index.js", "main": "dist/index.js",
"typings": "dist/index.d.ts", "typings": "dist/index.d.ts",

View File

@ -1,5 +1,5 @@
import tls, { TLSSocket } from 'tls'; import tls, { TLSSocket } from 'node:tls';
import { URL } from 'url'; import { URL } from 'node:url';
interface ProxyOptions extends tls.ConnectionOptions { interface ProxyOptions extends tls.ConnectionOptions {
method: 'GET'; method: 'GET';
@ -69,6 +69,7 @@ export class Proxy {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.socket.setEncoding('utf-8'); this.socket.setEncoding('utf-8');
this.socket.once('error', (err) => reject(err)); this.socket.once('error', (err) => reject(err));
const parts: string[] = [];
this.socket.on('data', (chunk: string) => { this.socket.on('data', (chunk: string) => {
if (this.rawHeaders.length === 0) { if (this.rawHeaders.length === 0) {
this.rawHeaders = chunk; this.rawHeaders = chunk;
@ -76,10 +77,11 @@ export class Proxy {
} else { } else {
const arr = chunk.split('\r\n'); const arr = chunk.split('\r\n');
if (arr.length > 1 && arr[0].length < 5) arr.shift(); if (arr.length > 1 && arr[0].length < 5) arr.shift();
this.body += arr.join(''); parts.push(...arr);
} }
}); });
this.socket.on('end', () => { this.socket.on('end', () => {
this.body = parts.join('');
resolve(this); resolve(this);
}); });
}); });

View File

@ -1,6 +1,6 @@
import http, { ClientRequest, IncomingMessage } from 'http'; import http, { ClientRequest, IncomingMessage } from 'node:http';
import https, { RequestOptions } from 'https'; import https, { RequestOptions } from 'node:https';
import { URL } from 'url'; import { URL } from 'node:url';
import { getCookies, setCookie, uploadCookie } from '../YouTube/utils/cookie'; import { getCookies, setCookie, uploadCookie } from '../YouTube/utils/cookie';
import { Proxy } from './classes'; import { Proxy } from './classes';
@ -49,7 +49,6 @@ export function request_stream(req_url: string, options: RequestOpts = { method:
export function request(req_url: string, options: RequestOpts = { method: 'GET' }): Promise<string> { export function request(req_url: string, options: RequestOpts = { method: 'GET' }): Promise<string> {
return new Promise(async (resolve, reject) => { return new Promise(async (resolve, reject) => {
if (!options?.proxies || options.proxies.length === 0) { if (!options?.proxies || options.proxies.length === 0) {
let data = '';
let cookies_added = false; let cookies_added = false;
if (options.cookies) { if (options.cookies) {
let cook = getCookies(); let cook = getCookies();
@ -80,9 +79,10 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
} else if (Number(res.statusCode) > 400) { } else if (Number(res.statusCode) > 400) {
reject(new Error(`Got ${res.statusCode} from the request`)); reject(new Error(`Got ${res.statusCode} from the request`));
} }
const data: string[] = [];
res.setEncoding('utf-8'); res.setEncoding('utf-8');
res.on('data', (c) => (data += c)); res.on('data', (c) => data.push(c));
res.on('end', () => resolve(data)); res.on('end', () => resolve(data.join('')));
} else { } else {
let cookies_added = false; let cookies_added = false;
if (options.cookies) { if (options.cookies) {

View File

@ -1,6 +1,6 @@
import { request, request_stream } from '../Request'; import { request, request_stream } from '../Request';
import { Readable } from 'stream'; import { Readable } from 'node:stream';
import { IncomingMessage } from 'http'; import { IncomingMessage } from 'node:http';
import { StreamType } from '../YouTube/stream'; import { StreamType } from '../YouTube/stream';
import { Timer } from '../YouTube/classes/LiveStream'; import { Timer } from '../YouTube/classes/LiveStream';

View File

@ -1,4 +1,4 @@
import fs from 'fs'; import fs from 'node:fs';
import { StreamType } from '../YouTube/stream'; import { StreamType } from '../YouTube/stream';
import { request } from '../Request'; import { request } from '../Request';
import { SoundCloudPlaylist, SoundCloudTrack, SoundCloudTrackFormat, Stream } from './classes'; import { SoundCloudPlaylist, SoundCloudTrack, SoundCloudTrackFormat, Stream } from './classes';

View File

@ -1,6 +1,6 @@
import { request } from '../Request'; import { request } from '../Request';
import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './classes'; import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './classes';
import fs from 'fs'; import fs from 'node:fs';
let spotifyData: SpotifyDataOptions; let spotifyData: SpotifyDataOptions;
if (fs.existsSync('.data/spotify.data')) { if (fs.existsSync('.data/spotify.data')) {

View File

@ -1,5 +1,5 @@
import { Readable } from 'stream'; import { Readable } from 'node:stream';
import { IncomingMessage } from 'http'; import { IncomingMessage } from 'node:http';
import { parseAudioFormats, StreamOptions, StreamType } from '../stream'; import { parseAudioFormats, StreamOptions, StreamType } from '../stream';
import { ProxyOptions as Proxy, request, request_stream } from '../../Request'; import { ProxyOptions as Proxy, request, request_stream } from '../../Request';
import { video_info } from '..'; import { video_info } from '..';

View File

@ -1,6 +1,5 @@
import { URL } from 'url'; import { URL, URLSearchParams } from 'node:url';
import { request } from './../../Request'; import { request } from './../../Request';
import querystring from 'querystring';
interface formatOptions { interface formatOptions {
url?: string; url?: string;
@ -164,7 +163,8 @@ export async function format_decipher(formats: formatOptions[], html5player: str
formats.forEach((format) => { formats.forEach((format) => {
const cipher = format.signatureCipher || format.cipher; const cipher = format.signatureCipher || format.cipher;
if (cipher) { if (cipher) {
Object.assign(format, querystring.parse(cipher)); const params = Object.fromEntries(new URLSearchParams(cipher));
Object.assign(format, params);
delete format.signatureCipher; delete format.signatureCipher;
delete format.cipher; delete format.cipher;
} }

View File

@ -1,4 +1,4 @@
import fs from 'fs'; import fs from 'node:fs';
let youtubeData: youtubeDataOptions; let youtubeData: youtubeDataOptions;
if (fs.existsSync('.data/youtube.data')) { if (fs.existsSync('.data/youtube.data')) {

View File

@ -31,8 +31,8 @@ interface SearchOptions {
}; };
} }
import readline from 'readline'; import readline from 'node:readline';
import fs from 'fs'; import fs from 'node:fs';
import { import {
sp_validate, sp_validate,
yt_validate, yt_validate,
@ -50,7 +50,6 @@ import { SoundCloudTrack } from './SoundCloud/classes';
import { yt_search } from './YouTube/search'; import { yt_search } from './YouTube/search';
import { EventEmitter } from 'stream'; import { EventEmitter } from 'stream';
import { Deezer, dz_search, dz_validate } from './Deezer'; import { Deezer, dz_search, dz_validate } from './Deezer';
/** /**
* Main stream Command for streaming through various sources * Main stream Command for streaming through various sources
* @param url The video / track url to make stream of * @param url The video / track url to make stream of

View File

@ -5,8 +5,8 @@
"removeComments": false, "removeComments": false,
"alwaysStrict": true, "alwaysStrict": true,
"pretty": true, "pretty": true,
"target": "es2019", "target": "es2021",
"lib": ["ESNext"], "lib": ["ES2021"],
"sourceMap": true, "sourceMap": true,
"inlineSources": true, "inlineSources": true,
"module": "commonjs", "module": "commonjs",