From 023b25e44b265934e69661f25d3d556b9bbcc3d6 Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 8 Aug 2023 01:05:09 +0200 Subject: [PATCH] Improve example JavaScript example and README section --- README.md | 18 ++++++++++-------- testfiles/metadatasearch.js | 4 +++- testfiles/set-tags.js | 10 ++++++++-- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d7924fa..b1e32c9 100644 --- a/README.md +++ b/README.md @@ -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 ``` - - 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. - 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. - - It needs to export a `main()` function. This function gets executed for every file and passed - and 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 a basic example. + - The script needs to export a `main()` function. This function gets executed for every file and + passed an object representing this file as first argument. + - Checkout the file `testfiles/set-tags.js` directory in this repository for an example that + 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. - 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. @@ -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. - 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. - - The content of other fields is mostly exposed as `String` or `Number`. Use must also use - these types to set the value of those fields. The string-representation of the assigned - content will then be converted automatically to what's needed internally. + - The content of other fields is mostly exposed as `String` or `Number`. You must also use + one of those types to set the value of those fields. The string-representation of the + 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. - Checkout the file `testfiles/http.js` in this repository for an example of using XHR and controlling the event loop. diff --git a/testfiles/metadatasearch.js b/testfiles/metadatasearch.js index 8d3308e..395fd25 100644 --- a/testfiles/metadatasearch.js +++ b/testfiles/metadatasearch.js @@ -4,19 +4,21 @@ const albumColumn = 1; export function queryLyrics(searchCriteria) { return cacheValue(lyricsCache, searchCriteria.title + "_" + searchCriteria.artist, () => { + utility.log(" - Querying lyrics for '" + searchCriteria.title + "' from '" + searchCriteria.artist + "' ..."); return queryLyricsFromProviders(["Tekstowo", "MakeItPersonal"], searchCriteria) }); } export function queryCover(searchCriteria) { return cacheValue(coverCache, searchCriteria.album + "_" + searchCriteria.artist, () => { + utility.log(" - Querying cover art for '" + searchCriteria.album + "' from '" + searchCriteria.artist + "' ..."); return queryCoverFromProvider("MusicBrainz", searchCriteria); }); } function cacheValue(cache, key, generator) { const cachedValue = cache[key]; - return cachedValue ? cachedValue : cache[key] = generator(); + return cachedValue ? cachedValue : (cache[key] = generator()); } function waitFor(signal) { diff --git a/testfiles/set-tags.js b/testfiles/set-tags.js index bdc62da..6ff839e 100644 --- a/testfiles/set-tags.js +++ b/testfiles/set-tags.js @@ -13,7 +13,7 @@ export function main(file) { return !isTruthy(settings.dryRun); } -const mainTextFields = ["title", "artist", "album"]; +const mainTextFields = ["title", "artist", "album", "genre"]; const personalFields = ["comment", "rating"]; function isString(value) { @@ -105,6 +105,12 @@ function addMiscFields(file, tag) { if (!fields.disk.length) { 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) { @@ -114,5 +120,5 @@ function changeTagFields(file, tag) { addTotalNumberOfTracks(file, tag); addMiscFields(file, tag); addLyrics(file, tag); - addCover(file, tag); + //addCover(file, tag); }