From 16aa5a4ee52e80e8e0279785e8110cde5dbaa123 Mon Sep 17 00:00:00 2001 From: aritrakarak <86865279+tr1ckydev@users.noreply.github.com> Date: Sun, 26 Sep 2021 14:09:07 +0530 Subject: [PATCH 1/2] Improved authorization setup messages Made the interaction messages more user friendly, fixed few typos. --- play-dl/index.ts | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/play-dl/index.ts b/play-dl/index.ts index b975fa1..52289d0 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -43,33 +43,31 @@ export function authorization(): void { input: process.stdin, output: process.stdout }); - ask.question('SoundCloud/ Spotify (so/sp) : ', (msg) => { + ask.question('Choose your service - so (for SoundCloud) / sp (for Spotify) : ', (msg) => { if (msg.toLowerCase().startsWith('sp')) { let client_id: string, client_secret: string, redirect_url: string, market: string; - ask.question('Client ID : ', (id) => { + ask.question('Start by entering your Client ID : ', (id) => { client_id = id; - ask.question('Client Secret : ', (secret) => { + ask.question('Now enter your Client Secret : ', (secret) => { client_secret = secret; - ask.question('Redirect URL : ', (url) => { + ask.question('Enter your Redirect URL now : ', (url) => { redirect_url = url; - console.log( - '\nMarket Selection URL : \nhttps://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements \n' - ); - ask.question('Market : ', (mar) => { + console.log('\nIf you would like to know your region code visit : \nhttps://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements \n'); + ask.question('Enter your region code (2-letter country code) : ', (mar) => { if (mar.length === 2) market = mar; else { - console.log('Invalid Market, Selecting IN as market'); + console.log('That doesn\'t look like a valid region code, IN will be selected as default.'); market = 'IN'; } console.log( - '\nNow Go to your browser and Paste this url. Authroize it and paste the redirected url here. \n' + '\nNow open your browser and paste the below url, then authorize it and copy the redirected url. \n' ); console.log( `https://accounts.spotify.com/authorize?client_id=${client_id}&response_type=code&redirect_uri=${encodeURI( redirect_url )} \n` ); - ask.question('Redirected URL : ', async (url) => { + ask.question('Paste the url which you just copied : ', async (url) => { if (!fs.existsSync('.data')) fs.mkdirSync('.data'); const spotifyData = { client_id, @@ -79,7 +77,7 @@ export function authorization(): void { market }; const check = await SpotifyAuthorize(spotifyData); - if (check === false) throw new Error('Failed to get access Token.'); + if (check === false) throw new Error('Failed to get access token.'); ask.close(); }); }); @@ -91,21 +89,20 @@ export function authorization(): void { ask.question('Client ID : ', async (id) => { client_id = id; if (!client_id) { - console.log("You didn't provided Client ID. Try again"); + console.log("You didn't provide a client ID. Try again..."); ask.close(); return; } if (!fs.existsSync('.data')) fs.mkdirSync('.data'); - console.log('Checking Client ID...................'); + console.log('Validating your client ID, hold on...'); if (await check_id(client_id)) { - console.log('Congratulations! Client ID is correct'); + console.log('Client ID has been validated successfully.'); fs.writeFileSync('.data/soundcloud.data', JSON.stringify({ client_id }, undefined, 4)); - } else console.log('Client ID is incorrect. Try to run this again with correct client ID.'); - + } else console.log('That doesn\'t look like a valid client ID. Retry with a correct client ID.'); ask.close(); }); } else { - console.log('Invalid Option, Please Try again'); + console.log('That option doesn\'t exist. Try again...'); ask.close(); } }); From fb3cd2e40f59cb3e9e35994b5c86d022179d4458 Mon Sep 17 00:00:00 2001 From: aritrakarak <86865279+tr1ckydev@users.noreply.github.com> Date: Tue, 28 Sep 2021 11:03:15 +0530 Subject: [PATCH 2/2] Changed so to sc --- package-lock.json | 2 +- play-dl/index.ts | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6815000..ca70e24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "play-dl", - "version": "1.0.2", + "version": "1.0.3", "license": "MIT", "devDependencies": { "@types/node": "^16.9.4", diff --git a/play-dl/index.ts b/play-dl/index.ts index c3d86a4..d446b14 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -43,17 +43,19 @@ export async function stream_from_info( else return await yt_stream_info(info, { cookie: options.cookie }); } -export async function validate(url: string): Promise<"so_playlist" | "so_track" | "sp_track" | "sp_album" | "sp_playlist" | "yt_video" | "yt_playlist" | false> { +export async function validate( + url: string +): Promise<'so_playlist' | 'so_track' | 'sp_track' | 'sp_album' | 'sp_playlist' | 'yt_video' | 'yt_playlist' | false> { let check; if (url.indexOf('spotify') !== -1) { check = sp_validate(url); - return check !== false ? 'sp_' + check as "sp_track" | "sp_album" | "sp_playlist" : false; + return check !== false ? (('sp_' + check) as 'sp_track' | 'sp_album' | 'sp_playlist') : false; } else if (url.indexOf('soundcloud') !== -1) { check = await so_validate(url); - return check !== false ? 'so_' + check as "so_playlist" | "so_track" : false; + return check !== false ? (('so_' + check) as 'so_playlist' | 'so_track') : false; } else { check = yt_validate(url); - return check !== false ? 'yt_' + check as "yt_video" | "yt_playlist" : false; + return check !== false ? (('yt_' + check) as 'yt_video' | 'yt_playlist') : false; } } @@ -62,7 +64,7 @@ export function authorization(): void { input: process.stdin, output: process.stdout }); - ask.question('Choose your service - so (for SoundCloud) / sp (for Spotify) : ', (msg) => { + ask.question('Choose your service - sc (for SoundCloud) / sp (for Spotify) : ', (msg) => { if (msg.toLowerCase().startsWith('sp')) { let client_id: string, client_secret: string, redirect_url: string, market: string; ask.question('Start by entering your Client ID : ', (id) => { @@ -71,11 +73,15 @@ export function authorization(): void { client_secret = secret; ask.question('Enter your Redirect URL now : ', (url) => { redirect_url = url; - console.log('\nIf you would like to know your region code visit : \nhttps://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements \n'); + console.log( + '\nIf you would like to know your region code visit : \nhttps://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements \n' + ); ask.question('Enter your region code (2-letter country code) : ', (mar) => { if (mar.length === 2) market = mar; else { - console.log('That doesn\'t look like a valid region code, IN will be selected as default.'); + console.log( + "That doesn't look like a valid region code, IN will be selected as default." + ); market = 'IN'; } console.log( @@ -103,7 +109,7 @@ export function authorization(): void { }); }); }); - } else if (msg.toLowerCase().startsWith('so')) { + } else if (msg.toLowerCase().startsWith('sc')) { let client_id: string; ask.question('Client ID : ', async (id) => { client_id = id; @@ -117,11 +123,11 @@ export function authorization(): void { 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)); - } else console.log('That doesn\'t look like a valid client ID. Retry with a correct client ID.'); + } else console.log("That doesn't look like a valid client ID. Retry with a correct client ID."); ask.close(); }); } else { - console.log('That option doesn\'t exist. Try again...'); + console.log("That option doesn't exist. Try again..."); ask.close(); } });