2023-07-05 01:47:26 +02:00
|
|
|
// import another module as an example how imports work
|
|
|
|
import * as http from "http.js"
|
|
|
|
|
|
|
|
export function main(file) {
|
|
|
|
// iterate though all tags of the file to change fields in all of them
|
|
|
|
for (const tag of file.tags) {
|
|
|
|
changeTagFields(tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
// submit changes from the JavaScript-context to the tag editor application; does not save changes to disk yet
|
|
|
|
file.applyChanges();
|
|
|
|
|
|
|
|
// return a falsy value to skip the file after all
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-07-30 17:20:23 +02:00
|
|
|
const mainTextFields = ["title", "artist", "album"];
|
|
|
|
const personalFields = ["comment", "rating"];
|
|
|
|
|
|
|
|
function isString(value) {
|
|
|
|
return typeof(value) === "string" || value instanceof String;
|
|
|
|
}
|
|
|
|
|
2023-07-05 01:47:26 +02:00
|
|
|
function changeTagFields(tag) {
|
2023-07-30 17:20:23 +02:00
|
|
|
// log tag type and supported fields
|
2023-07-05 01:47:26 +02:00
|
|
|
const fields = tag.fields;
|
|
|
|
utility.diag("debug", tag.type, "tag");
|
|
|
|
utility.diag("debug", Object.keys(fields).join(", "), "supported fields");
|
|
|
|
|
2023-07-30 17:20:23 +02:00
|
|
|
// log fields for debugging purposes
|
2023-07-05 01:47:26 +02:00
|
|
|
for (const [key, value] of Object.entries(fields)) {
|
|
|
|
const content = value.content;
|
|
|
|
if (content !== undefined && content != null && !(content instanceof ArrayBuffer)) {
|
|
|
|
utility.diag("debug", content, key + " (" + value.type + ")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-30 17:20:23 +02:00
|
|
|
// apply fixes to main text fields
|
|
|
|
for (const key of mainTextFields) {
|
|
|
|
for (const value of fields[key]) {
|
|
|
|
if (isString(value.content)) {
|
|
|
|
value.content = value.content.trim();
|
|
|
|
value.content = utility.fixUmlauts(value.content);
|
|
|
|
value.content = utility.formatName(value.content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensure personal fields are cleared
|
|
|
|
for (const key of personalFields) {
|
|
|
|
fields[key] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
// set some other fields
|
2023-08-01 00:50:21 +02:00
|
|
|
fields.track = "4/17";
|
2023-07-05 01:47:26 +02:00
|
|
|
}
|