mirror of
https://git.fuwafuwa.moe/SMLoadrDev/SMLoadr
synced 2024-11-17 00:24:33 +01:00
Add NamingService
This commit is contained in:
parent
f062ed554a
commit
6e620ae599
649
SMLoadr.js
649
SMLoadr.js
File diff suppressed because it is too large
Load Diff
@ -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();
|
||||
|
72
src/service/NamingService.js
Normal file
72
src/service/NamingService.js
Normal 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
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user