create config

This commit is contained in:
Jill 2021-10-21 19:27:00 +03:00
parent 68242f137d
commit 31c1fb8a11
7 changed files with 117 additions and 13 deletions

3
.gitignore vendored
View File

@ -144,4 +144,5 @@ dist
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
data/**
data/**
config.json

View File

@ -16,7 +16,7 @@ it's intended use is for small groups of people to self-host, and as such there'
your arl can be found in the local storage for deezer, as a value conviniently named `arl`
2. (optionally) set a `PORT` value in your `.env` file. (if unset, this will fall back to 4500)
2. (optionally) copy the config.example.json to config.json in the same folder, and modify it
3. `npm install`

36
config.example.toml Normal file
View File

@ -0,0 +1,36 @@
[timer]
# the time before a downloaded file is cleaned off the data folder
deleteTimer = 1500000 # 25 minutes
[server]
port = 4500
# location of the zip utility binary
zipBinaryLocation = "zip"
zipArguments = "-0rD"
[limits]
# the max amount of search results to send to the client
searchLimit = 15
[deemix]
# the format of the song to download
# can be "FLAC", "MP3_320", "MP3_128" or "DEFAULT"
trackFormat = "FLAC"
# templates for the folder and file names
trackNameTemplate = "%artist% - %title%"
albumTrackNameTemplate = "%tracknumber%. %artist% - %title%"
albumNameTemplate = "%artist% - %album%"
# create a m3u8 playlist file or not
createM3U8File = false
# cover art settings
# embed cover art in the music files themselves
embeddedArtworkPNG = true
embeddedArtworkSize = 800
# put the cover art file inside of the folder
saveArtwork = true
localArtworkSize = 1200
localArtworkFormat = "jpg"
jpegImageQuality = 80
removeDuplicateArtists = true

33
config.toml Normal file
View File

@ -0,0 +1,33 @@
[timer]
# the time before a downloaded file is cleaned off the data folder
deleteTimer = 1500000 # 25 minutes
[server]
port = 4500
[limits]
# the max amount of search results to send to the client
searchLimit = 15
[deemix]
# the format of the song to download
# can be "FLAC", "MP3_320", "MP3_128" or "DEFAULT"
trackFormat = "FLAC"
# templates for the folder and file names
trackNameTemplate = "%artist% - %title%"
albumTrackNameTemplate = "%tracknumber%. %artist% - %title%"
albumNameTemplate = "%artist% - %album%"
# create a m3u8 playlist file or not
createM3U8File = false
# cover art settings
# embed cover art in the music files themselves
embeddedArtworkPNG = true
embeddedArtworkSize = 800
# put the cover art file inside of the folder
saveArtwork = true
localArtworkSize = 1200
localArtworkFormat = "jpg"
jpegImageQuality = 80
removeDuplicateArtists = true

11
package-lock.json generated
View File

@ -15,6 +15,7 @@
"express": "^4.17.1",
"express-ws": "^5.0.2",
"timeago.js": "^4.0.2",
"toml": "^3.0.0",
"ws": "^8.2.3"
},
"optionalDependencies": {
@ -1275,6 +1276,11 @@
"node": ">=0.6"
}
},
"node_modules/toml": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz",
"integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w=="
},
"node_modules/tough-cookie": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz",
@ -2358,6 +2364,11 @@
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
},
"toml": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz",
"integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w=="
},
"tough-cookie": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-4.0.0.tgz",

View File

@ -23,6 +23,7 @@
"express": "^4.17.1",
"express-ws": "^5.0.2",
"timeago.js": "^4.0.2",
"toml": "^3.0.0",
"ws": "^8.2.3"
},
"optionalDependencies": {

View File

@ -2,15 +2,25 @@ const express = require('express');
const deezer = require('deezer-js');
const deemix = require('deemix');
const path = require('path');
const { inspect, promisify } = require('util');
const { promisify } = require('util');
const fs = require('fs');
const { exec } = require('child_process');
const timeago = require('timeago.js');
const toml = require('toml');
const port = process.env.PORT || 4500;
// const deleteTimer = 1000 * 60 * 60; // 1 hour
const deleteTimer = 1000 * 60 * 25; // 25 minutes
// const deleteTimer = 16000;
if (!fs.existsSync('./config.toml')) {
if (!fs.existsSync('./config.example.toml')) {
console.error('!! no config.toml OR config.example.toml found!!! what the hell are you up to!!!');
process.exit(1);
}
console.log('! copying config.example.toml to config.toml as it was not found. the default config may not be preferable!');
fs.copyFileSync('./config.example.toml', './config.toml');
}
const config = toml.parse(fs.readFileSync('./config.toml'));
console.log('loaded config');
const port = config.server.port || 4500;
const deleteTimer = config.timer.deleteTimer || 1000 * 60 * 25;
require('dotenv').config();
@ -21,8 +31,20 @@ let deemixDownloader;
let deemixSettings = deemix.settings.DEFAULTS
deemixSettings.downloadLocation = path.join(process.cwd(), 'data/');
deemixSettings.maxBitrate = String(deezer.TrackFormats.FLAC);
deemixSettings.overwriteFile = deemix.settings.OverwriteOption.OVERWRITE;
deemixSettings.overwriteFile = deemix.settings.OverwriteOption.ONLY_TAGS;
deemixSettings.maxBitrate = String(deezer.TrackFormats[config.deemix.trackFormat]);
deemixSettings.tracknameTemplate = config.deemix.trackNameTemplate || '%artist% - %title%';
deemixSettings.albumTracknameTemplate = config.deemix.albumTrackNameTemplate || '%tracknumber%. %artist% - %title%';
deemixSettings.albumNameTemplate = config.deemix.albumNameTemplate || '%artist% - %album%'
deemixSettings.createM3U8File = config.deemix.createM3U8File !== undefined ? config.deemix.createM3U8File : false;
deemixSettings.embeddedArtworkPNG = config.deemix.embeddedArtworkPNG !== undefined ? config.deemix.embeddedArtworkPNG : true;
deemixSettings.embeddedArtworkSize = config.deemix.embeddedArtworkSize || 800;
deemixSettings.saveArtwork = config.deemix.saveArtwork !== undefined ? config.deemix.saveArtwork : true;
deemixSettings.localArtworkSize = deemixSettings.localArtworkSize || 1200;
deemixSettings.localArtworkFormat = deemixSettings.localArtworkFormat || 'jpg';
deemixSettings.jpegImageQuality = deemixSettings.jpegImageQuality || 80;
deemixSettings.removeDuplicateArtists = config.deemix.removeDuplicateArtists !== undefined ? config.deemix.removeDuplicateArtists : true;
const toDeleteLocation = './data/toDelete.json';
@ -90,7 +112,7 @@ app.get('/api/search', async (req, res) => {
if (!req.query.search) return res.sendStatus(400);
let s = await deezerInstance.api.search_album(req.query.search, {
limit: 15,
limit: config.limits.searchLimit || 15,
});
let format = s.data.map(s => {
@ -170,13 +192,13 @@ app.ws('/api/album', async (ws, req) => {
const folderName = trackpaths[0].split('/').slice(-2)[0];
try {
await promisify(exec)(`zip -0rD "data/${folderName}.zip" "data/${folderName}"`);
await promisify(exec)(`${config.server.zipBinaryLocation} ${config.server.zipArguments} "data/${folderName}.zip" "data/${folderName}"`);
} catch(err) {
return ws.close(1011, 'Zipping album failed');
}
await ws.send(JSON.stringify({key: 'download', data: `data/${folderName}.zip`}));
queueDeletion('./data/' + folderName + '.zip');
} else {
await ws.send(JSON.stringify({key: 'download', data: trackpaths[0].replace(process.cwd(), '')}));