mirror of https://git.fuwafuwa.moe/SMLoadrDev/SMLoadr synced 2024-11-17 00:24:33 +01:00

Add NamingService

This commit is contained in:
magicalunicorn 2019-09-15 16:22:27 +02:00
parent f062ed554a
commit 6e620ae599
3 changed files with 410 additions and 320 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,8 +6,13 @@ module.exports = class ConfigService {
this.configFile = configFile;
this.config = {
saveLayout: "",
arl: ""
"naming": {
"path": "DOWNLOADS/%artist%/%albumName%",
"discPath": "%path%/Disc %disc%",
"albumName": "%album% (%type%)",
"fileName": "%number% %title%"
},
"arl": ""
};
this.loadConfig();

View File

@ -0,0 +1,72 @@
module.exports = class NamingService {
configService;
/**
* @param {ConfigService} configService
*/
constructor(configService) {
this.configService = configService;
}
getConfig(type) {
return this.configService.get('naming')[type];
}
/**
* @param variables
* @returns {string}
*/
getPath(variables) {
let name = this.getConfig('path');
variables['albumName'] = this.getAlbumName(variables);
for (let variableKey in variables) {
name = name.replace('%' + variableKey + '%', variables[variableKey])
}
return name
}
/**
* @param variables
* @returns {string}
*/
getDiscPath(variables) {
let name = this.getConfig('discPath');
variables['path'] = this.getPath(variables);
for (let variableKey in variables) {
name = name.replace('%' + variableKey + '%', variables[variableKey])
}
return name
}
/**
* @param variables
* @returns {string}
*/
getAlbumName(variables) {
let name = this.getConfig('albumName');
for (let variableKey in variables) {
name = name.replace('%' + variableKey + '%', variables[variableKey])
}
return name
}
/**
* @param variables
* @returns {string}
*/
getFileName(variables) {
let name = this.getConfig('fileName');
for (let variableKey in variables) {
name = name.replace('%' + variableKey + '%', variables[variableKey])
}
return name
}
};