From 533aebc2ff50688083ebfce2a76a7a2280c12f21 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 28 Oct 2021 18:55:35 +0200 Subject: [PATCH 1/6] Bump typescript output version to es2021, to be inline with node 16 --- tsconfig.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index e8aeba8..4e30ca8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,8 +5,8 @@ "removeComments": false, "alwaysStrict": true, "pretty": true, - "target": "es2019", - "lib": ["ESNext"], + "target": "es2021", + "lib": ["ES2021"], "sourceMap": true, "inlineSources": true, "module": "commonjs", From a13e588246e6fdb221833ecec9b5e45b40fe3626 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 28 Oct 2021 18:57:44 +0200 Subject: [PATCH 2/6] Use array + join, instead of append for request body strings --- play-dl/Request/classes.ts | 4 +++- play-dl/Request/index.ts | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/play-dl/Request/classes.ts b/play-dl/Request/classes.ts index 423e434..74621c6 100644 --- a/play-dl/Request/classes.ts +++ b/play-dl/Request/classes.ts @@ -69,6 +69,7 @@ export class Proxy { return new Promise((resolve, reject) => { this.socket.setEncoding('utf-8'); this.socket.once('error', (err) => reject(err)); + const parts: string[] = []; this.socket.on('data', (chunk: string) => { if (this.rawHeaders.length === 0) { this.rawHeaders = chunk; @@ -76,10 +77,11 @@ export class Proxy { } else { const arr = chunk.split('\r\n'); if (arr.length > 1 && arr[0].length < 5) arr.shift(); - this.body += arr.join(''); + parts.push(...arr); } }); this.socket.on('end', () => { + this.body = parts.join(''); resolve(this); }); }); diff --git a/play-dl/Request/index.ts b/play-dl/Request/index.ts index 381bc81..6145884 100644 --- a/play-dl/Request/index.ts +++ b/play-dl/Request/index.ts @@ -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 { return new Promise(async (resolve, reject) => { if (!options?.proxies || options.proxies.length === 0) { - let data = ''; let cookies_added = false; if (options.cookies) { let cook = getCookies(); @@ -80,9 +79,10 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET' } else if (Number(res.statusCode) > 400) { reject(new Error(`Got ${res.statusCode} from the request`)); } + const data: string[] = []; res.setEncoding('utf-8'); - res.on('data', (c) => (data += c)); - res.on('end', () => resolve(data)); + res.on('data', (c) => data.push(c)); + res.on('end', () => resolve(data.join(''))); } else { let cookies_added = false; if (options.cookies) { From 90867b9430e2fe62a69acbfd6cce76b13ee99f8c Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 28 Oct 2021 19:40:19 +0200 Subject: [PATCH 3/6] Prefix core module imports with node: --- play-dl/Request/classes.ts | 4 ++-- play-dl/Request/index.ts | 6 +++--- play-dl/SoundCloud/classes.ts | 4 ++-- play-dl/SoundCloud/index.ts | 2 +- play-dl/Spotify/index.ts | 2 +- play-dl/YouTube/classes/LiveStream.ts | 4 ++-- play-dl/YouTube/utils/cipher.ts | 4 ++-- play-dl/YouTube/utils/cookie.ts | 2 +- play-dl/index.ts | 6 +++--- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/play-dl/Request/classes.ts b/play-dl/Request/classes.ts index 74621c6..b61f307 100644 --- a/play-dl/Request/classes.ts +++ b/play-dl/Request/classes.ts @@ -1,5 +1,5 @@ -import tls, { TLSSocket } from 'tls'; -import { URL } from 'url'; +import tls, { TLSSocket } from 'node:tls'; +import { URL } from 'node:url'; interface ProxyOptions extends tls.ConnectionOptions { method: 'GET'; diff --git a/play-dl/Request/index.ts b/play-dl/Request/index.ts index 6145884..088ce6c 100644 --- a/play-dl/Request/index.ts +++ b/play-dl/Request/index.ts @@ -1,6 +1,6 @@ -import http, { ClientRequest, IncomingMessage } from 'http'; -import https, { RequestOptions } from 'https'; -import { URL } from 'url'; +import http, { ClientRequest, IncomingMessage } from 'node:http'; +import https, { RequestOptions } from 'node:https'; +import { URL } from 'node:url'; import { getCookies, setCookie, uploadCookie } from '../YouTube/utils/cookie'; import { Proxy } from './classes'; diff --git a/play-dl/SoundCloud/classes.ts b/play-dl/SoundCloud/classes.ts index c7278f7..22e59ba 100644 --- a/play-dl/SoundCloud/classes.ts +++ b/play-dl/SoundCloud/classes.ts @@ -1,6 +1,6 @@ import { request, request_stream } from '../Request'; -import { Readable } from 'stream'; -import { IncomingMessage } from 'http'; +import { Readable } from 'node:stream'; +import { IncomingMessage } from 'node:http'; import { StreamType } from '../YouTube/stream'; import { Timer } from '../YouTube/classes/LiveStream'; diff --git a/play-dl/SoundCloud/index.ts b/play-dl/SoundCloud/index.ts index adb83f6..7226b04 100644 --- a/play-dl/SoundCloud/index.ts +++ b/play-dl/SoundCloud/index.ts @@ -1,4 +1,4 @@ -import fs from 'fs'; +import fs from 'node:fs'; import { StreamType } from '../YouTube/stream'; import { request } from '../Request'; import { SoundCloudPlaylist, SoundCloudTrack, SoundCloudTrackFormat, Stream } from './classes'; diff --git a/play-dl/Spotify/index.ts b/play-dl/Spotify/index.ts index 64eca61..ef3cc00 100644 --- a/play-dl/Spotify/index.ts +++ b/play-dl/Spotify/index.ts @@ -1,6 +1,6 @@ import { request } from '../Request'; import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './classes'; -import fs from 'fs'; +import fs from 'node:fs'; let spotifyData: SpotifyDataOptions; if (fs.existsSync('.data/spotify.data')) { diff --git a/play-dl/YouTube/classes/LiveStream.ts b/play-dl/YouTube/classes/LiveStream.ts index ae63860..ce29889 100644 --- a/play-dl/YouTube/classes/LiveStream.ts +++ b/play-dl/YouTube/classes/LiveStream.ts @@ -1,5 +1,5 @@ -import { Readable } from 'stream'; -import { IncomingMessage } from 'http'; +import { Readable } from 'node:stream'; +import { IncomingMessage } from 'node:http'; import { parseAudioFormats, StreamOptions, StreamType } from '../stream'; import { ProxyOptions as Proxy, request, request_stream } from '../../Request'; import { video_info } from '..'; diff --git a/play-dl/YouTube/utils/cipher.ts b/play-dl/YouTube/utils/cipher.ts index 77296d6..c1e7f94 100644 --- a/play-dl/YouTube/utils/cipher.ts +++ b/play-dl/YouTube/utils/cipher.ts @@ -1,6 +1,6 @@ -import { URL } from 'url'; +import { URL } from 'node:url'; import { request } from './../../Request'; -import querystring from 'querystring'; +import querystring from 'node:querystring'; interface formatOptions { url?: string; diff --git a/play-dl/YouTube/utils/cookie.ts b/play-dl/YouTube/utils/cookie.ts index 82f5cf4..e4cf712 100644 --- a/play-dl/YouTube/utils/cookie.ts +++ b/play-dl/YouTube/utils/cookie.ts @@ -1,4 +1,4 @@ -import fs from 'fs'; +import fs from 'node:fs'; let youtubeData: youtubeDataOptions; if (fs.existsSync('.data/youtube.data')) { diff --git a/play-dl/index.ts b/play-dl/index.ts index 063c6a6..9cf4922 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -29,8 +29,8 @@ interface SearchOptions { }; } -import readline from 'readline'; -import fs from 'fs'; +import readline from 'node:readline'; +import fs from 'node:fs'; import { sp_validate, yt_validate, @@ -46,7 +46,7 @@ import { check_id, so_search, stream as so_stream, stream_from_info as so_stream import { InfoData, stream as yt_stream, StreamOptions, stream_from_info as yt_stream_info } from './YouTube/stream'; import { SoundCloudTrack } from './SoundCloud/classes'; import { yt_search } from './YouTube/search'; -import { EventEmitter } from 'stream'; +import { EventEmitter } from 'node:stream'; /** * Main stream Command for streaming through various sources From 6d5de7463db8b0136275ecb547aa1a607ab6976b Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 28 Oct 2021 21:09:13 +0200 Subject: [PATCH 4/6] Replace deprecated querystring with URLSearchParams --- play-dl/YouTube/utils/cipher.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/play-dl/YouTube/utils/cipher.ts b/play-dl/YouTube/utils/cipher.ts index c1e7f94..b2bf2f7 100644 --- a/play-dl/YouTube/utils/cipher.ts +++ b/play-dl/YouTube/utils/cipher.ts @@ -1,6 +1,5 @@ -import { URL } from 'node:url'; +import { URL, URLSearchParams } from 'node:url'; import { request } from './../../Request'; -import querystring from 'node:querystring'; interface formatOptions { url?: string; @@ -164,7 +163,8 @@ export async function format_decipher(formats: formatOptions[], html5player: str formats.forEach((format) => { const cipher = format.signatureCipher || format.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.cipher; } From 3e96233cdfbf1d1a61abe085c85f6203d2631056 Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Fri, 29 Oct 2021 15:03:19 +0530 Subject: [PATCH 5/6] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ece8c92..5d37ece 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "play-dl", - "version": "1.2.3", + "version": "1.2.5", "description": "YouTube, SoundCloud, Spotify streaming for discord.js bots", "main": "dist/index.js", "typings": "dist/index.d.ts", From 3848d750520033691d535ba493e7eaf788a2a8a4 Mon Sep 17 00:00:00 2001 From: Killer069 <65385476+killer069@users.noreply.github.com> Date: Fri, 29 Oct 2021 15:03:36 +0530 Subject: [PATCH 6/6] Update package-lock.json --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0db2220..bee2f35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "play-dl", - "version": "1.2.3", + "version": "1.2.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "play-dl", - "version": "1.2.3", + "version": "1.2.5", "license": "GPL-3.0", "devDependencies": { "@types/node": "^16.9.4",