mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-06 04:32:40 +00:00
Build with tsup, fix warnings and cleanup imports
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { URL } from 'url';
|
||||
import { URL } from 'node:url';
|
||||
import { request, request_resolve_redirect } from '../Request';
|
||||
import { DeezerAlbum, DeezerPlaylist, DeezerTrack } from './classes';
|
||||
|
||||
@@ -265,13 +265,13 @@ export async function dz_advanced_track_search(options: DeezerAdvancedSearchOpti
|
||||
|
||||
if (options.label) metadata.push(`label:"${encodeURIComponent(options.label)}"`);
|
||||
|
||||
if (Number(options.minDurationInSec) !== NaN) metadata.push(`dur_min:${options.minDurationInSec}`);
|
||||
if (!isNaN(Number(options.minDurationInSec))) metadata.push(`dur_min:${options.minDurationInSec}`);
|
||||
|
||||
if (Number(options.maxDurationInSec) !== NaN) metadata.push(`dur_max:${options.maxDurationInSec}`);
|
||||
if (!isNaN(Number(options.maxDurationInSec))) metadata.push(`dur_max:${options.maxDurationInSec}`);
|
||||
|
||||
if (Number(options.minBPM) !== NaN) metadata.push(`bpm_min:${options.minBPM}`);
|
||||
if (!isNaN(Number(options.minBPM))) metadata.push(`bpm_min:${options.minBPM}`);
|
||||
|
||||
if (Number(options.maxBPM) !== NaN) metadata.push(`bpm_max:${options.maxBPM}`);
|
||||
if (!isNaN(Number(options.maxBPM))) metadata.push(`bpm_max:${options.maxBPM}`);
|
||||
|
||||
if (metadata.length === 0) throw new Error('At least one type of metadata is required.');
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { IncomingMessage } from 'node:http';
|
||||
import https, { RequestOptions } from 'node:https';
|
||||
import { RequestOptions, request as httpsRequest } from 'node:https';
|
||||
import { URL } from 'node:url';
|
||||
import zlib, { BrotliDecompress, Deflate, Gunzip } from 'node:zlib';
|
||||
import { BrotliDecompress, Deflate, Gunzip, createGunzip, createBrotliDecompress, createDeflate } from 'node:zlib';
|
||||
import { cookieHeaders, getCookies } from '../YouTube/utils/cookie';
|
||||
import { getRandomUserAgent } from './useragent';
|
||||
|
||||
@@ -78,9 +78,9 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
|
||||
const data: string[] = [];
|
||||
let decoder: BrotliDecompress | Gunzip | Deflate | undefined = undefined;
|
||||
const encoding = res.headers['content-encoding'];
|
||||
if (encoding === 'gzip') decoder = zlib.createGunzip();
|
||||
else if (encoding === 'br') decoder = zlib.createBrotliDecompress();
|
||||
else if (encoding === 'deflate') decoder = zlib.createDeflate();
|
||||
if (encoding === 'gzip') decoder = createGunzip();
|
||||
else if (encoding === 'br') decoder = createBrotliDecompress();
|
||||
else if (encoding === 'deflate') decoder = createDeflate();
|
||||
|
||||
if (decoder) {
|
||||
res.pipe(decoder);
|
||||
@@ -137,7 +137,7 @@ function https_getter(req_url: string, options: RequestOpts = {}): Promise<Incom
|
||||
method: options.method
|
||||
};
|
||||
|
||||
const req = https.request(req_options, resolve);
|
||||
const req = httpsRequest(req_options, resolve);
|
||||
req.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import fs from 'node:fs';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { StreamType } from '../YouTube/stream';
|
||||
import { request } from '../Request';
|
||||
import { SoundCloudPlaylist, SoundCloudTrack, SoundCloudTrackFormat, SoundCloudStream } from './classes';
|
||||
let soundData: SoundDataOptions;
|
||||
if (fs.existsSync('.data/soundcloud.data')) {
|
||||
soundData = JSON.parse(fs.readFileSync('.data/soundcloud.data').toString());
|
||||
if (existsSync('.data/soundcloud.data')) {
|
||||
soundData = JSON.parse(readFileSync('.data/soundcloud.data').toString());
|
||||
}
|
||||
|
||||
interface SoundDataOptions {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { request } from '../Request';
|
||||
import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './classes';
|
||||
import fs from 'node:fs';
|
||||
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
|
||||
let spotifyData: SpotifyDataOptions;
|
||||
if (fs.existsSync('.data/spotify.data')) {
|
||||
spotifyData = JSON.parse(fs.readFileSync('.data/spotify.data').toString());
|
||||
if (existsSync('.data/spotify.data')) {
|
||||
spotifyData = JSON.parse(readFileSync('.data/spotify.data').toString());
|
||||
spotifyData.file = true;
|
||||
}
|
||||
/**
|
||||
@@ -132,7 +132,7 @@ export async function SpotifyAuthorize(data: SpotifyDataOptions, file: boolean):
|
||||
token_type: resp_json.token_type,
|
||||
market: data.market
|
||||
};
|
||||
if (file) fs.writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4));
|
||||
if (file) writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4));
|
||||
else {
|
||||
console.log(`Client ID : ${spotifyData.client_id}`);
|
||||
console.log(`Client Secret : ${spotifyData.client_secret}`);
|
||||
@@ -233,7 +233,7 @@ export async function refreshToken(): Promise<boolean> {
|
||||
spotifyData.expires_in = Number(resp_json.expires_in);
|
||||
spotifyData.expiry = Date.now() + (resp_json.expires_in - 1) * 1000;
|
||||
spotifyData.token_type = resp_json.token_type;
|
||||
if (spotifyData.file) fs.writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4));
|
||||
if (spotifyData.file) writeFileSync('.data/spotify.data', JSON.stringify(spotifyData, undefined, 4));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import fs from 'node:fs';
|
||||
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
|
||||
let youtubeData: youtubeDataOptions;
|
||||
if (fs.existsSync('.data/youtube.data')) {
|
||||
youtubeData = JSON.parse(fs.readFileSync('.data/youtube.data').toString());
|
||||
if (existsSync('.data/youtube.data')) {
|
||||
youtubeData = JSON.parse(readFileSync('.data/youtube.data').toString());
|
||||
youtubeData.file = true;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export function setCookie(key: string, value: string): boolean {
|
||||
|
||||
export function uploadCookie() {
|
||||
if (youtubeData.cookie && youtubeData.file)
|
||||
fs.writeFileSync('.data/youtube.data', JSON.stringify(youtubeData, undefined, 4));
|
||||
writeFileSync('.data/youtube.data', JSON.stringify(youtubeData, undefined, 4));
|
||||
}
|
||||
|
||||
export function setCookieToken(options: { cookie: string }) {
|
||||
|
||||
@@ -60,8 +60,8 @@ interface SearchOptions {
|
||||
fuzzy?: boolean;
|
||||
}
|
||||
|
||||
import readline from 'node:readline';
|
||||
import fs from 'node:fs';
|
||||
import { createInterface } from 'node:readline';
|
||||
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
||||
import {
|
||||
sp_validate,
|
||||
yt_validate,
|
||||
@@ -304,7 +304,7 @@ export async function validate(
|
||||
* Just run the above command and you will get a interface asking some questions.
|
||||
*/
|
||||
export function authorization(): void {
|
||||
const ask = readline.createInterface({
|
||||
const ask = createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
@@ -346,7 +346,7 @@ export function authorization(): void {
|
||||
)} \n`
|
||||
);
|
||||
ask.question('Paste the url which you just copied : ', async (url) => {
|
||||
if (!fs.existsSync('.data')) fs.mkdirSync('.data');
|
||||
if (!existsSync('.data')) mkdirSync('.data');
|
||||
const spotifyData = {
|
||||
client_id,
|
||||
client_secret,
|
||||
@@ -375,11 +375,11 @@ export function authorization(): void {
|
||||
ask.close();
|
||||
return;
|
||||
}
|
||||
if (!fs.existsSync('.data')) fs.mkdirSync('.data');
|
||||
if (!existsSync('.data')) mkdirSync('.data');
|
||||
console.log('Validating your client ID, hold on...');
|
||||
if (await check_id(client_id)) {
|
||||
console.log('Client ID has been validated successfully.');
|
||||
fs.writeFileSync('.data/soundcloud.data', JSON.stringify({ client_id }, undefined, 4));
|
||||
writeFileSync('.data/soundcloud.data', JSON.stringify({ client_id }, undefined, 4));
|
||||
} else console.log("That doesn't look like a valid client ID. Retry with a correct client ID.");
|
||||
ask.close();
|
||||
});
|
||||
@@ -395,7 +395,7 @@ export function authorization(): void {
|
||||
ask.close();
|
||||
return;
|
||||
}
|
||||
if (!fs.existsSync('.data')) fs.mkdirSync('.data');
|
||||
if (!existsSync('.data')) mkdirSync('.data');
|
||||
console.log('Cookies has been added successfully.');
|
||||
let cookie: Object = {};
|
||||
cook.split(';').forEach((x) => {
|
||||
@@ -405,7 +405,7 @@ export function authorization(): void {
|
||||
const value = arr.join('=').trim();
|
||||
Object.assign(cookie, { [key]: value });
|
||||
});
|
||||
fs.writeFileSync('.data/youtube.data', JSON.stringify({ cookie }, undefined, 4));
|
||||
writeFileSync('.data/youtube.data', JSON.stringify({ cookie }, undefined, 4));
|
||||
ask.close();
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user