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", 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", diff --git a/play-dl/Request/classes.ts b/play-dl/Request/classes.ts index 423e434..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'; @@ -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 a592df9..af4a20b 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'; @@ -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) { 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..b2bf2f7 100644 --- a/play-dl/YouTube/utils/cipher.ts +++ b/play-dl/YouTube/utils/cipher.ts @@ -1,6 +1,5 @@ -import { URL } from 'url'; +import { URL, URLSearchParams } from 'node:url'; import { request } from './../../Request'; -import querystring from '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; } 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 ad9074b..85d3312 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -31,8 +31,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, @@ -50,7 +50,6 @@ import { SoundCloudTrack } from './SoundCloud/classes'; import { yt_search } from './YouTube/search'; import { EventEmitter } from 'stream'; import { Deezer, dz_search, dz_validate } from './Deezer'; - /** * Main stream Command for streaming through various sources * @param url The video / track url to make stream of 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",