Compare commits
4 Commits
a3cbe956d7
...
8490b2d16c
| Author | SHA1 | Date | |
|---|---|---|---|
| 8490b2d16c | |||
| 48bbec8830 | |||
| 27a4043095 | |||
| 8c7ec8e968 |
1
.env
1
.env
@@ -0,0 +1 @@
|
|||||||
|
AUTHTOKEN=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJmWVlwNF8ybmRaTmxEM1UweWU1eGciLCJleHAiOjE3NjExMjAxNTIuODYzLCJpYXQiOjE3NjExMTkyNTJ9.UDf9OZqqC8uXnkKXnqdXJDrVGbSPo_Q9IT9x2tf8mcJEu9qm3twTcfqNetbLlsw9b4bERyoh1waXIzCJj8hCIWK-oRMenbzdjbSqMl29_36tNV204fnuGXhEMo8-NXS6k9DCQ74-1xd1IOGcACP4rHyDcKvEY46D_ccfJL-TR_TGFIxJrt05SGrBWNr4I2AFQ4I-uq23jInphIkOggw356dNIRvfinhoGYkju8IUiUIGUFTMgXom9rBm-RR2k9MhHm9d0FqMuGGrB5dlFzvGXc7LUIabC4-MIc17g6U2aqPGCuyTSHkmCsWJQE9y4wZZ2m6px7wkyIOtYjbhDnzFhw
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
songs/
|
songs/
|
||||||
json-data/
|
json-data/
|
||||||
node_modules/
|
node_modules/
|
||||||
|
dist
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import https from 'https';
|
import * as https from 'https';
|
||||||
import fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
||||||
async function downloadSong(downloadLink, folder, filename, songCount) {
|
async function downloadSong(downloadLink: string, folder: string, filename: string, songCount: number): Promise<void> {
|
||||||
console.log(`Downloading song #${songCount} ...`)
|
console.log(`Downloading song #${songCount} ...`)
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
https.get(downloadLink, (response) => {
|
https.get(downloadLink, (response) => {
|
||||||
@@ -10,7 +10,7 @@ async function downloadSong(downloadLink, folder, filename, songCount) {
|
|||||||
console.log(`${songCount} songs downloaded successfully`);
|
console.log(`${songCount} songs downloaded successfully`);
|
||||||
resolve();
|
resolve();
|
||||||
})
|
})
|
||||||
.on('error', (error) => {
|
.on('error', (error: Error) => {
|
||||||
console.error('Error downloading song:', error);
|
console.error('Error downloading song:', error);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
@@ -18,8 +18,8 @@ async function downloadSong(downloadLink, folder, filename, songCount) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('message', async (message) => {
|
process.on('message', async (message: any) => {
|
||||||
const { downloadLink, folder, filename, songCount } = message;
|
const { downloadLink, folder, filename, songCount } = message;
|
||||||
await downloadSong(downloadLink, folder, filename, songCount);
|
await downloadSong(downloadLink, folder, filename, songCount);
|
||||||
process.send(`Song #${songCount} downloaded successfully`);
|
process.send && process.send(`Song #${songCount} downloaded successfully`);
|
||||||
});
|
});
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
GET https://api.brain.fm/v2/mental-states/6042a1bad80ae028b821e958/genres/
|
|
||||||
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJGYmd3dndBT1JCTjlibVJmRUxLcHciLCJleHAiOjE2ODE5ODg5MTUuMzU2LCJpYXQiOjE2ODE5ODgwMTV9.hCs0U5Iv5bgaU9oYi9kmSl0A_gt3V9svL0NiCEvtZFr4DXiNQwkt30fUtwOofMmHUnoEKiRt8ER-K8n5vsXKc23gvvcKaYEzY1kipwlAkK_JiYslE1FXDGXBBN1VrunACWLY5sWyRt1og6WP20BaoD0gIvBr0iazN323mlpU_Ls4yOrid2J_veXAwmCkW_26Q2NbhJeEV2rlwnV95CtxmogYHkoDrDz65UncU5AUvl4ae96il9IN7MSI0DvFl3NutVnD3B2wPaNHNAIoMC1_nLwWl5Q5GMbgC2AW3B1U0pozg78ePFVWq-mKYY8IbgjESNKWg1gRF5oknsFq8shxjw
|
|
||||||
16
jsconfig.json
Normal file
16
jsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"target": "ES2024",
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"strictFunctionTypes": true,
|
||||||
|
"strict": true
|
||||||
|
},
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"**/node_modules/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
157
main.js
157
main.js
@@ -1,157 +0,0 @@
|
|||||||
import fs from 'fs';
|
|
||||||
import https from 'https';
|
|
||||||
import chalk from 'chalk';
|
|
||||||
import load from 'dotenv';
|
|
||||||
load()
|
|
||||||
|
|
||||||
let songCount = 1;
|
|
||||||
|
|
||||||
const AUTHTOKEN = process.env.AUTHTOKEN;
|
|
||||||
const TOKEN = process.env.TOKEN;
|
|
||||||
const USERID = process.env.USERID;
|
|
||||||
|
|
||||||
if(!AUTHTOKEN || !TOKEN || !USERID) {
|
|
||||||
console.error('Please enter all the required information');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let genres = [
|
|
||||||
"Beach",
|
|
||||||
"Chimes & Bowls",
|
|
||||||
"Forest",
|
|
||||||
"Nightsounds",
|
|
||||||
"Rain",
|
|
||||||
"Rainforest",
|
|
||||||
"River",
|
|
||||||
"Thunder",
|
|
||||||
"Underwater",
|
|
||||||
"Wind",
|
|
||||||
"Acoustic",
|
|
||||||
"Atmospheric",
|
|
||||||
"Cinematic",
|
|
||||||
"Classical",
|
|
||||||
"Drone",
|
|
||||||
"Electronic",
|
|
||||||
"Grooves",
|
|
||||||
"Lofi",
|
|
||||||
"Piano",
|
|
||||||
"Post Rock",
|
|
||||||
];
|
|
||||||
|
|
||||||
let mentalStateIDs = {
|
|
||||||
focus: "6042a1bad80ae028b821e954",
|
|
||||||
sleep: "6042a1bad80ae028b821e95c",
|
|
||||||
relax: "6042a1bad80ae028b821e958"
|
|
||||||
}
|
|
||||||
|
|
||||||
class DownloadQueue {
|
|
||||||
constructor(maxConcurrency) {
|
|
||||||
this.queue = [];
|
|
||||||
this.activeDownloads = 0;
|
|
||||||
this.maxConcurrency = maxConcurrency;
|
|
||||||
}
|
|
||||||
|
|
||||||
enqueue(url, folder, filename) {
|
|
||||||
this.queue.push({url, folder, filename});
|
|
||||||
this.processQueue();
|
|
||||||
}
|
|
||||||
|
|
||||||
async processQueue() {
|
|
||||||
if (this.activeDownloads < this.maxConcurrency && this.queue.length > 0) {
|
|
||||||
const {url, folder, filename} = this.queue.shift();
|
|
||||||
this.activeDownloads++;
|
|
||||||
await downloadSong(url, folder, filename);
|
|
||||||
console.log(`${songCount} songs downloaded successfully \n${this.queue.length} remaining`)
|
|
||||||
this.activeDownloads--;
|
|
||||||
this.processQueue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const downloadQueue = new DownloadQueue(3)
|
|
||||||
|
|
||||||
for(const genre of genres) {
|
|
||||||
console.log(chalk.red(`Starting genre ${genre}`))
|
|
||||||
for(const mentalState of Object.keys(mentalStateIDs)) {
|
|
||||||
console.log(chalk.yellow(`Starting mental state ${mentalState}`))
|
|
||||||
|
|
||||||
//
|
|
||||||
// Phase 1 : Fetch all song data
|
|
||||||
//
|
|
||||||
let data = await fetch(`https://api.brain.fm/v2/genres/${genre}/tracks?mentalStateId=${mentalStateIDs[mentalState]}&version=3`, {
|
|
||||||
headers: {
|
|
||||||
authorization: `Bearer ${AUTHTOKEN}`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
data = await data.json();
|
|
||||||
|
|
||||||
data = formatAudioData(data.result);
|
|
||||||
|
|
||||||
if (checkIfJsonExists(`./json-data/${mentalState}/${genre}.json`)) continue;
|
|
||||||
ensureDirectory(`./json-data/${mentalState}`);
|
|
||||||
let file = fs.createWriteStream(`./json-data/${mentalState}/${genre}.json`);
|
|
||||||
|
|
||||||
file.write(JSON.stringify(data));
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Phase 2 : Download songs to device
|
|
||||||
//
|
|
||||||
|
|
||||||
console.log(chalk.green(`Started downloading ${genre} ${mentalState}`))
|
|
||||||
for (const song of data) {
|
|
||||||
let activity = song.serving.track.tags.find(tag => tag.type === "activity").value;
|
|
||||||
let NEL = song.neuralEffectLevel;
|
|
||||||
let level = (NEL > 0.66 ? "high" : NEL > 0.33 ? "medium" : "low");
|
|
||||||
let hasMultipleNELs = song.hasMultipleNELs;
|
|
||||||
|
|
||||||
let folder = `./songs/${genre}/${mentalState}/${activity}/${hasMultipleNELs ? "mixed" : level}`
|
|
||||||
let filename = `${song.name.replace(' ', '_')}`;
|
|
||||||
let downloadLink = `https://audio.brain.fm/${song.url}?userId=${USERID}&token=${TOKEN}`;
|
|
||||||
|
|
||||||
downloadQueue.enqueue(downloadLink, folder, filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function downloadSong(downloadLink, folder, filename) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
ensureDirectory(folder)
|
|
||||||
https.get(downloadLink, (response) => {
|
|
||||||
response.pipe(fs.createWriteStream(`${folder}/${filename}.mp3`))
|
|
||||||
.on('finish', () => {
|
|
||||||
songCount++
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.on('error', (error) => {
|
|
||||||
console.error('Error downloading song:', error);
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatAudioData(arr) {
|
|
||||||
return arr.map(item => {
|
|
||||||
delete item.serving.track.similarTracks;
|
|
||||||
return item;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function ensureDirectory(directory) {
|
|
||||||
if (!fs.existsSync(directory)) {
|
|
||||||
fs.mkdirSync(directory, { recursive: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkIfJsonExists(mentalState, genre) {
|
|
||||||
const filePath = `./json-data/${mentalState}/${genre}.json`;
|
|
||||||
return fs.existsSync(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
327
main.ts
Normal file
327
main.ts
Normal file
@@ -0,0 +1,327 @@
|
|||||||
|
import * as fs from 'fs';
|
||||||
|
import * as https from 'https';
|
||||||
|
import chalk from 'chalk';
|
||||||
|
import * as dotenv from 'dotenv';
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
let songCount = 1;
|
||||||
|
|
||||||
|
const AUTHTOKEN = process.env.AUTHTOKEN;
|
||||||
|
|
||||||
|
if (!AUTHTOKEN) {
|
||||||
|
console.error('Please enter all the required information');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
type MentalState = "focus" | "relax" | "sleep" | "meditate";
|
||||||
|
|
||||||
|
type MentalStateArray = MentalState[];
|
||||||
|
|
||||||
|
let mentalStates: MentalStateArray = ["focus", "relax", "sleep", "meditate"];
|
||||||
|
|
||||||
|
type GenreStructure = {
|
||||||
|
base: string[];
|
||||||
|
nature: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type GenresMap = Record<MentalState, GenreStructure>;
|
||||||
|
|
||||||
|
let genres: GenresMap = {
|
||||||
|
"focus": {
|
||||||
|
base: [
|
||||||
|
"Acoustic",
|
||||||
|
"Atmospheric",
|
||||||
|
"Cinematic",
|
||||||
|
"Classical",
|
||||||
|
"Drone",
|
||||||
|
"Electronic",
|
||||||
|
"Grooves",
|
||||||
|
"Lofi",
|
||||||
|
"Piano",
|
||||||
|
"Post Rock"
|
||||||
|
],
|
||||||
|
nature: [
|
||||||
|
"Beach",
|
||||||
|
"Chimes & Bowls",
|
||||||
|
"Forest",
|
||||||
|
"Nightsounds",
|
||||||
|
"Rain",
|
||||||
|
"Rainforest",
|
||||||
|
"River",
|
||||||
|
"Thunder",
|
||||||
|
"Underwater",
|
||||||
|
"Wind"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"relax": {
|
||||||
|
base: [
|
||||||
|
"Atmospheric",
|
||||||
|
"Electronic"
|
||||||
|
],
|
||||||
|
nature: [
|
||||||
|
"Beach",
|
||||||
|
"Chimes & Bowls",
|
||||||
|
"Forest",
|
||||||
|
"Nightsounds",
|
||||||
|
"Rain",
|
||||||
|
"Rainforest",
|
||||||
|
"River",
|
||||||
|
"Thunder",
|
||||||
|
"Underwater",
|
||||||
|
"Wind"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"sleep": {
|
||||||
|
base: [
|
||||||
|
"Atmospheric"
|
||||||
|
],
|
||||||
|
nature: [
|
||||||
|
"Beach",
|
||||||
|
"Forest",
|
||||||
|
"Nightsounds",
|
||||||
|
"Rain",
|
||||||
|
"Rainforest",
|
||||||
|
"River",
|
||||||
|
"Thunder",
|
||||||
|
"Underwater",
|
||||||
|
"Wind"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"meditate": {
|
||||||
|
base: [
|
||||||
|
"Atmospheric",
|
||||||
|
"Electronic"
|
||||||
|
],
|
||||||
|
nature: [
|
||||||
|
"Beach",
|
||||||
|
"Chimes & Bowls",
|
||||||
|
"Forest",
|
||||||
|
"Nightsounds",
|
||||||
|
"Rain",
|
||||||
|
"Rainforest",
|
||||||
|
"River",
|
||||||
|
"Thunder",
|
||||||
|
"Underwater",
|
||||||
|
"Wind"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Commenting out moods since it's not used in the code
|
||||||
|
/*
|
||||||
|
type MoodsMap = Record<MentalState, string[]>;
|
||||||
|
|
||||||
|
let moods: MoodsMap = {
|
||||||
|
"focus": [
|
||||||
|
"Brooding",
|
||||||
|
"Calm",
|
||||||
|
"Chill",
|
||||||
|
"Dark",
|
||||||
|
"Downtempo",
|
||||||
|
"Dreamlike",
|
||||||
|
"Driving",
|
||||||
|
"Energizing",
|
||||||
|
"Epic",
|
||||||
|
"Floating",
|
||||||
|
"Heavy",
|
||||||
|
"Hopeful",
|
||||||
|
"Inspiring",
|
||||||
|
"Meditative",
|
||||||
|
"Mysterious",
|
||||||
|
"Ominous",
|
||||||
|
"Optimistic",
|
||||||
|
"Playful",
|
||||||
|
"Ponderous",
|
||||||
|
"Serene",
|
||||||
|
"Strong",
|
||||||
|
"Upbeat",
|
||||||
|
"Uplifting"
|
||||||
|
],
|
||||||
|
"relax": [
|
||||||
|
"Brooding",
|
||||||
|
"Calm",
|
||||||
|
"Chill",
|
||||||
|
"Dark",
|
||||||
|
"Downtempo",
|
||||||
|
"Dreamlike",
|
||||||
|
"Driving",
|
||||||
|
"Energizing",
|
||||||
|
"Epic",
|
||||||
|
"Floating",
|
||||||
|
"Hopeful",
|
||||||
|
"Inspiring",
|
||||||
|
"Meditative",
|
||||||
|
"Mysterious",
|
||||||
|
"Optimistic",
|
||||||
|
"Playful",
|
||||||
|
"Ponderous",
|
||||||
|
"Serene",
|
||||||
|
"Strong",
|
||||||
|
"Upbeat",
|
||||||
|
"Uplifting"
|
||||||
|
],
|
||||||
|
"sleep": [
|
||||||
|
"Brooding",
|
||||||
|
"Calm",
|
||||||
|
"Chill",
|
||||||
|
"Dark",
|
||||||
|
"Dreamlike",
|
||||||
|
"Epic",
|
||||||
|
"Floating",
|
||||||
|
"Heavy",
|
||||||
|
"Meditative",
|
||||||
|
"Mysterious",
|
||||||
|
"Optimistic",
|
||||||
|
"Ponderous",
|
||||||
|
"Serene",
|
||||||
|
"Strong"
|
||||||
|
],
|
||||||
|
"meditate": [
|
||||||
|
"Brooding",
|
||||||
|
"Calm",
|
||||||
|
"Chill",
|
||||||
|
"Dark",
|
||||||
|
"Downtempo",
|
||||||
|
"Dreamlike",
|
||||||
|
"Driving",
|
||||||
|
"Energizing",
|
||||||
|
"Epic",
|
||||||
|
"Floating",
|
||||||
|
"Heavy",
|
||||||
|
"Hopeful",
|
||||||
|
"Inspiring",
|
||||||
|
"Meditative",
|
||||||
|
"Mysterious",
|
||||||
|
"Optimistic",
|
||||||
|
"Playful",
|
||||||
|
"Ponderous",
|
||||||
|
"Serene",
|
||||||
|
"Strong",
|
||||||
|
"Upbeat",
|
||||||
|
"Uplifting"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
type QueueEntry = {
|
||||||
|
url: string;
|
||||||
|
folder: string;
|
||||||
|
filename: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DownloadQueue {
|
||||||
|
private queue: QueueEntry[] = [];
|
||||||
|
private activeDownloads = 0;
|
||||||
|
private maxConcurrency: number
|
||||||
|
|
||||||
|
constructor(maxConcurrency: number) {
|
||||||
|
this.maxConcurrency = maxConcurrency
|
||||||
|
}
|
||||||
|
|
||||||
|
public enqueue(url: string, folder: string, filename: string) {
|
||||||
|
this.queue.push({ url, folder, filename });
|
||||||
|
this.processQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async processQueue(): Promise<void> {
|
||||||
|
while (this.activeDownloads < this.maxConcurrency && this.queue.length > 0) {
|
||||||
|
const { url, folder, filename } = this.queue.shift()!;
|
||||||
|
this.activeDownloads++;
|
||||||
|
|
||||||
|
this.processDownload(url, folder, filename).then(() => {
|
||||||
|
this.activeDownloads--;
|
||||||
|
this.processQueue();
|
||||||
|
}).catch((error) => {
|
||||||
|
console.error('Error downloading song:', error);
|
||||||
|
this.activeDownloads--;
|
||||||
|
this.processQueue();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async processDownload(url: string, folder: string, filename: string): Promise<void> {
|
||||||
|
await downloadSong(url, folder, filename);
|
||||||
|
songCount++;
|
||||||
|
console.log(`${songCount} songs downloaded successfully \n${this.queue.length} remaining`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const downloadQueue = new DownloadQueue(3)
|
||||||
|
|
||||||
|
for (const mentalState of mentalStates) {
|
||||||
|
console.log(chalk.red(`Starting mental state ${mentalState}`))
|
||||||
|
for (const genre of [...genres[mentalState].base, ...genres[mentalState].nature]) {
|
||||||
|
console.log(chalk.yellow(`Starting genre ${genre}`))
|
||||||
|
|
||||||
|
//
|
||||||
|
// Phase 1 : Fetch all song data
|
||||||
|
//
|
||||||
|
const response = await fetch(`https://api.brain.fm/v3/servings/search?genre=${genre}&dynamicMentalStateId=${mentalState}`, {
|
||||||
|
headers: {
|
||||||
|
authorization: `Bearer ${AUTHTOKEN}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const responseData = await response.json();
|
||||||
|
const data = formatAudioData(responseData.result);
|
||||||
|
|
||||||
|
if (checkIfJsonExists(`./json-data/${mentalState}/${genre}.json`)) continue;
|
||||||
|
ensureDirectory(`./json-data/${mentalState}`);
|
||||||
|
let file = fs.createWriteStream(`./json-data/${mentalState}/${genre}.json`);
|
||||||
|
|
||||||
|
file.write(JSON.stringify(data));
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
//
|
||||||
|
// Phase 2 : Download songs to device
|
||||||
|
//
|
||||||
|
|
||||||
|
console.log(chalk.green(`Started queuing ${genre} ${mentalState}`))
|
||||||
|
for (const song of data) {
|
||||||
|
let activity = song.track.tags.filter((x: any) => x.type == 'activity').map((x: any) => x.value).join('/');
|
||||||
|
let NEL = song.trackVariation.neuralEffectLevel;
|
||||||
|
let level = (NEL > 0.66 ? "high" : NEL > 0.33 ? "medium" : "low");
|
||||||
|
|
||||||
|
let folder = `./songs/${genre}/${mentalState}/${activity}/${level}`
|
||||||
|
let filename = song.trackVariation.baseUrl;
|
||||||
|
let downloadLink = song.trackVariation.tokenedUrl;
|
||||||
|
|
||||||
|
downloadQueue.enqueue(downloadLink, folder, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function downloadSong(downloadLink: string, folder: string, filename: string): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
ensureDirectory(folder)
|
||||||
|
https.get(downloadLink, (response) => {
|
||||||
|
response.pipe(fs.createWriteStream(`${folder}/${filename}.mp3`))
|
||||||
|
.on('finish', () => {
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.on('error', (error: Error) => {
|
||||||
|
console.error('Error downloading song:', error);
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatAudioData(arr: any[]) {
|
||||||
|
return arr.map(item => {
|
||||||
|
delete item.track.similarTracks;
|
||||||
|
return item;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureDirectory(directory: string) {
|
||||||
|
if (!fs.existsSync(directory)) {
|
||||||
|
fs.mkdirSync(directory, { recursive: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkIfJsonExists(filePath: string) {
|
||||||
|
return fs.existsSync(filePath);
|
||||||
|
}
|
||||||
231
package-lock.json
generated
231
package-lock.json
generated
@@ -11,8 +11,133 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^5.2.0",
|
"chalk": "^5.2.0",
|
||||||
"dotenv": "^16.0.3"
|
"dotenv": "^16.0.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/chalk": "^0.4.31",
|
||||||
|
"@types/node": "^24.9.1",
|
||||||
|
"ts-node": "^10.9.2",
|
||||||
|
"typescript": "^5.9.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@cspotcode/source-map-support": {
|
||||||
|
"version": "0.8.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
|
||||||
|
"integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@jridgewell/trace-mapping": "0.3.9"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/resolve-uri": {
|
||||||
|
"version": "3.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
|
||||||
|
"integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/sourcemap-codec": {
|
||||||
|
"version": "1.5.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz",
|
||||||
|
"integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/trace-mapping": {
|
||||||
|
"version": "0.3.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz",
|
||||||
|
"integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@jridgewell/resolve-uri": "^3.0.3",
|
||||||
|
"@jridgewell/sourcemap-codec": "^1.4.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tsconfig/node10": {
|
||||||
|
"version": "1.0.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz",
|
||||||
|
"integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@tsconfig/node12": {
|
||||||
|
"version": "1.0.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz",
|
||||||
|
"integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@tsconfig/node14": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@tsconfig/node16": {
|
||||||
|
"version": "1.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz",
|
||||||
|
"integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/chalk": {
|
||||||
|
"version": "0.4.31",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-0.4.31.tgz",
|
||||||
|
"integrity": "sha512-nF0fisEPYMIyfrFgabFimsz9Lnuu9MwkNrrlATm2E4E46afKDyeelT+8bXfw1VSc7sLBxMxRgT7PxTC2JcqN4Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/@types/node": {
|
||||||
|
"version": "24.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.9.1.tgz",
|
||||||
|
"integrity": "sha512-QoiaXANRkSXK6p0Duvt56W208du4P9Uye9hWLWgGMDTEoKPhuenzNcC4vGUmrNkiOKTlIrBoyNQYNpSwfEZXSg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"undici-types": "~7.16.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/acorn": {
|
||||||
|
"version": "8.15.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
||||||
|
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"acorn": "bin/acorn"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/acorn-walk": {
|
||||||
|
"version": "8.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz",
|
||||||
|
"integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"acorn": "^8.11.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/arg": {
|
||||||
|
"version": "4.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
|
||||||
|
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/chalk": {
|
"node_modules/chalk": {
|
||||||
"version": "5.2.0",
|
"version": "5.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.2.0.tgz",
|
||||||
@@ -24,6 +149,23 @@
|
|||||||
"url": "https://github.com/chalk/chalk?sponsor=1"
|
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/create-require": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/diff": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.3.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/dotenv": {
|
"node_modules/dotenv": {
|
||||||
"version": "16.0.3",
|
"version": "16.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||||
@@ -31,6 +173,95 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/make-error": {
|
||||||
|
"version": "1.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||||
|
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "ISC"
|
||||||
|
},
|
||||||
|
"node_modules/ts-node": {
|
||||||
|
"version": "10.9.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz",
|
||||||
|
"integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@cspotcode/source-map-support": "^0.8.0",
|
||||||
|
"@tsconfig/node10": "^1.0.7",
|
||||||
|
"@tsconfig/node12": "^1.0.7",
|
||||||
|
"@tsconfig/node14": "^1.0.0",
|
||||||
|
"@tsconfig/node16": "^1.0.2",
|
||||||
|
"acorn": "^8.4.1",
|
||||||
|
"acorn-walk": "^8.1.1",
|
||||||
|
"arg": "^4.1.0",
|
||||||
|
"create-require": "^1.1.0",
|
||||||
|
"diff": "^4.0.1",
|
||||||
|
"make-error": "^1.1.1",
|
||||||
|
"v8-compile-cache-lib": "^3.0.1",
|
||||||
|
"yn": "3.1.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"ts-node": "dist/bin.js",
|
||||||
|
"ts-node-cwd": "dist/bin-cwd.js",
|
||||||
|
"ts-node-esm": "dist/bin-esm.js",
|
||||||
|
"ts-node-script": "dist/bin-script.js",
|
||||||
|
"ts-node-transpile-only": "dist/bin-transpile.js",
|
||||||
|
"ts-script": "dist/bin-script-deprecated.js"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@swc/core": ">=1.2.50",
|
||||||
|
"@swc/wasm": ">=1.2.50",
|
||||||
|
"@types/node": "*",
|
||||||
|
"typescript": ">=2.7"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@swc/core": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@swc/wasm": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/typescript": {
|
||||||
|
"version": "5.9.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
|
||||||
|
"integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"bin": {
|
||||||
|
"tsc": "bin/tsc",
|
||||||
|
"tsserver": "bin/tsserver"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.17"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/undici-types": {
|
||||||
|
"version": "7.16.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.16.0.tgz",
|
||||||
|
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/v8-compile-cache-lib": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
|
"node_modules/yn": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
||||||
|
"integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
package.json
11
package.json
@@ -2,9 +2,12 @@
|
|||||||
"name": "brainfm-extract",
|
"name": "brainfm-extract",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "main.js",
|
"main": "dist/main.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"start": "npm run build && node dist/main.js",
|
||||||
|
"dev": "ts-node main.ts",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
@@ -13,5 +16,11 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chalk": "^5.2.0",
|
"chalk": "^5.2.0",
|
||||||
"dotenv": "^16.0.3"
|
"dotenv": "^16.0.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/chalk": "^0.4.31",
|
||||||
|
"@types/node": "^24.9.1",
|
||||||
|
"ts-node": "^10.9.2",
|
||||||
|
"typescript": "^5.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
tsconfig.json
Normal file
32
tsconfig.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2024",
|
||||||
|
"module": "ESNext",
|
||||||
|
"moduleResolution": "Bundler",
|
||||||
|
"outDir": "./dist",
|
||||||
|
"rootDir": "./",
|
||||||
|
"strict": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"forceConsistentCasingInFileNames": true,
|
||||||
|
"declaration": true,
|
||||||
|
"declarationMap": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"removeComments": false,
|
||||||
|
"noImplicitAny": true,
|
||||||
|
"strictNullChecks": true,
|
||||||
|
"strictFunctionTypes": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"./**/*.ts"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"node_modules",
|
||||||
|
"dist",
|
||||||
|
"**/node_modules/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user