Improve example JavaScript example and README section

This commit is contained in:
Martchus 2023-08-08 01:05:09 +02:00
parent 5222082635
commit 023b25e44b
3 changed files with 21 additions and 11 deletions

View File

@ -349,14 +349,16 @@ Here are some Bash examples which illustrate getting and setting tag information
tageditor set --pedantic debug --java-script path/to/script.js -f foo.mp3 tageditor set --pedantic debug --java-script path/to/script.js -f foo.mp3
``` ```
- This feature is still experimental. The script API is still very limited and subject to change. - This feature is still experimental. The script API is still subject to change.
- The script needs to be ECMAScript as supported by the Qt framework. - The script needs to be ECMAScript as supported by the Qt framework.
- This feature requires the tag editor to be configured with Qt QML as JavaScript provider at - This feature requires the tag editor to be configured with Qt QML as JavaScript provider at
compile time. Checkout the build instructions under "Building with Qt GUI" for details. compile time. Checkout the build instructions under "Building with Qt GUI" for details.
- It needs to export a `main()` function. This function gets executed for every file and passed - The script needs to export a `main()` function. This function gets executed for every file and
and object representing this file as first argument. passed an object representing this file as first argument.
- The option `--pedantic debug` is not required but useful for debugging. - Checkout the file `testfiles/set-tags.js` directory in this repository for an example that
- Checkout the file `testfiles/set-tags.js` directory in this repository for a basic example. applies basic fixes and tries to fetch lyrics and cover art.
- The option `--pedantic debug` is not required but useful for debugging. You may also add
`--script-settings dryRun=1` and use that setting within the script as shown in the example.
- Common tag fields are exposed as object properties as shown in the mentioned example. - Common tag fields are exposed as object properties as shown in the mentioned example.
- Only properties for fields that are supported by the tag are added to the "fields" object. - Only properties for fields that are supported by the tag are added to the "fields" object.
- Adding properties of unsupported fields manually does not work; those will just be ignored. - Adding properties of unsupported fields manually does not work; those will just be ignored.
@ -364,9 +366,9 @@ Here are some Bash examples which illustrate getting and setting tag information
also assign an empty array to fields to delete them. also assign an empty array to fields to delete them.
- The content of binary fields is exposed as `ArrayBuffer`. Use must also use an `ArrayBuffer` - The content of binary fields is exposed as `ArrayBuffer`. Use must also use an `ArrayBuffer`
to set the value of binary fields such as the cover. to set the value of binary fields such as the cover.
- The content of other fields is mostly exposed as `String` or `Number`. Use must also use - The content of other fields is mostly exposed as `String` or `Number`. You must also use
these types to set the value of those fields. The string-representation of the assigned one of those types to set the value of those fields. The string-representation of the
content will then be converted automatically to what's needed internally. assigned content will then be converted automatically to what's needed internally.
- The `utility` object exposes useful methods, e.g. for logging and controlling the event loop. - The `utility` object exposes useful methods, e.g. for logging and controlling the event loop.
- Checkout the file `testfiles/http.js` in this repository for an example of using XHR and - Checkout the file `testfiles/http.js` in this repository for an example of using XHR and
controlling the event loop. controlling the event loop.

View File

@ -4,19 +4,21 @@ const albumColumn = 1;
export function queryLyrics(searchCriteria) { export function queryLyrics(searchCriteria) {
return cacheValue(lyricsCache, searchCriteria.title + "_" + searchCriteria.artist, () => { return cacheValue(lyricsCache, searchCriteria.title + "_" + searchCriteria.artist, () => {
utility.log(" - Querying lyrics for '" + searchCriteria.title + "' from '" + searchCriteria.artist + "' ...");
return queryLyricsFromProviders(["Tekstowo", "MakeItPersonal"], searchCriteria) return queryLyricsFromProviders(["Tekstowo", "MakeItPersonal"], searchCriteria)
}); });
} }
export function queryCover(searchCriteria) { export function queryCover(searchCriteria) {
return cacheValue(coverCache, searchCriteria.album + "_" + searchCriteria.artist, () => { return cacheValue(coverCache, searchCriteria.album + "_" + searchCriteria.artist, () => {
utility.log(" - Querying cover art for '" + searchCriteria.album + "' from '" + searchCriteria.artist + "' ...");
return queryCoverFromProvider("MusicBrainz", searchCriteria); return queryCoverFromProvider("MusicBrainz", searchCriteria);
}); });
} }
function cacheValue(cache, key, generator) { function cacheValue(cache, key, generator) {
const cachedValue = cache[key]; const cachedValue = cache[key];
return cachedValue ? cachedValue : cache[key] = generator(); return cachedValue ? cachedValue : (cache[key] = generator());
} }
function waitFor(signal) { function waitFor(signal) {

View File

@ -13,7 +13,7 @@ export function main(file) {
return !isTruthy(settings.dryRun); return !isTruthy(settings.dryRun);
} }
const mainTextFields = ["title", "artist", "album"]; const mainTextFields = ["title", "artist", "album", "genre"];
const personalFields = ["comment", "rating"]; const personalFields = ["comment", "rating"];
function isString(value) { function isString(value) {
@ -105,6 +105,12 @@ function addMiscFields(file, tag) {
if (!fields.disk.length) { if (!fields.disk.length) {
fields.disk = "1/1"; fields.disk = "1/1";
} }
const dir = file.containingDirectory.toLowerCase();
if (dir.includes("bootleg")) {
fields.comment = "bootleg";
} else if (dir.includes("singles")) {
fields.comment = "single";
}
} }
function changeTagFields(file, tag) { function changeTagFields(file, tag) {
@ -114,5 +120,5 @@ function changeTagFields(file, tag) {
addTotalNumberOfTracks(file, tag); addTotalNumberOfTracks(file, tag);
addMiscFields(file, tag); addMiscFields(file, tag);
addLyrics(file, tag); addLyrics(file, tag);
addCover(file, tag); //addCover(file, tag);
} }