Hi Paul,
Sorry… it’s been a few months !! Had other stuff to take care of then completely forgot about all that… but here i am, trying to get my head around all this again ! This time not on testing mode but paid the app.
Back at the Renaming folders and file masks issue. I’ve tried looking for clear information again (maybe i did the job poorly the first time) but still can’t find anything easily understandable, except for in this forum topic requesting for help.
You previously said
We dont write separate subfolder and filename mask, we write a single mask that defines what subfolder and filename should be. We then apply that to file and when we run Correct Metadata from Filename it uses the result to the right of the last ‘/’ which is the folder separator, whereas Correct SubFolders from Metadata uses the result to the left of the last ‘/’ .
Here are the 2 parts of the mask i’d like to use (created with the help of AI to help tackling every situations). They both work individually, so i’ve combined them and seperated with a last "+ ’ / ’ " yet, if Correct Metadata from Filename will work, Correct SubFolders from Metadata won’t.
A1- SUBFOLDER_From_Label:
/*-----------------------------------------------------------------------------------------*/
/* CATALOG */
var cat = (catalogno && catalogno.length ? catalogno
: (discogs_catno && discogs_catno.length ? discogs_catno : 'UNCAT')).toUpperCase();
/* YEAR (4 chiffres si possible) */
var ysrc = (originalyear && originalyear.length ? originalyear : year);
var m = (''+ysrc).match(/\d{4}/);
var y4 = m ? m[0] : '0000';
/* ALBUM ARTISTS -> ‘ / ’ (slash plein-chasse sûr) */
var arts = (albumartists && albumartists.length ? albumartists
: (albumartist && albumartist.length ? albumartist
: (artist && artist.length ? artist : 'Unknown Artist')));
arts = arts.replace(/;\s*/g,' / ');
/* Renvoie la fréquence en kHz sans unité, formatée proprement (ex: "44.1") */
function toKhz(audiosamplerate) {
if (audiosamplerate == null) return '';
var s = ('' + audiosamplerate).trim().toLowerCase();
// Si déjà exprimé en kHz (ex: "44.1 kHz", "48khz")
if (/\bkhz\b/.test(s) || /khz$/.test(s) || /khz/.test(s)) {
var k = parseFloat(s.replace(/[^0-9.]/g, ''));
return formatKhz(k);
}
// Extraire un nombre quel qu'il soit (peut être entier en Hz ou décimal déjà en kHz)
var raw = parseFloat(s.replace(/[^0-9.]/g, ''));
if (!isFinite(raw)) return '';
// Candidats possibles:
// - raw déjà en kHz
// - raw en Hz (÷1000)
// - raw en Hz avec un zéro en trop (÷10000), ex: 441000 -> 44.1
var candidates = [
{ k: raw, scale: 'kHz' }, // déjà en kHz
{ k: raw / 1000, scale: 'Hz' }, // Hz classique
{ k: raw / 10000, scale: 'Hzx10' } // Hz avec un zéro en trop
];
// Liste des fréquences audio usuelles en kHz
var standardKhz = [8, 11.025, 12, 16, 22.05, 24, 32, 44.1, 48, 88.2, 96, 176.4, 192];
// Choisir le candidat le plus proche d’une valeur standard
var best = candidates[0], bestErr = Infinity;
for (var i = 0; i < candidates.length; i++) {
var khz = candidates[i].k;
for (var j = 0; j < standardKhz.length; j++) {
var err = Math.abs(khz - standardKhz[j]);
if (err < bestErr) {
bestErr = err;
best = candidates[i];
}
}
}
return formatKhz(best.k);
}
function formatKhz(x) {
if (!isFinite(x)) return '';
// Arrondi à 3 décimales pour couvrir 11.025 / 22.05 / 44.1, puis on nettoie les zéros
var s = x.toFixed(3);
s = s.replace(/\.?0+$/, ''); // supprime .000 / .00 / .0
return s;
}
var fmtBase = (audioformat && audioformat.length
? audioformat.trim().split(/\s+/)[0].toUpperCase()
: 'UNK');
// Utilise la nouvelle fonction toKhz() avec audiosamplerate, fallback sur samplerate
var srStr = toKhz(typeof audiosamplerate !== 'undefined' ? audiosamplerate
: (typeof samplerate !== 'undefined' ? samplerate : ''));
var bpsRaw = (typeof audiobitspersample !== 'undefined' ? audiobitspersample
: (typeof bitdepth !== 'undefined' ? bitdepth : ''));
var bps = parseInt((''+bpsRaw).replace(/\D+/g,''),10);
var fmtExtra = '';
if (srStr && bps) fmtExtra = ' ' + srStr + '/' + bps; // slash sûr pour dossiers
else if (srStr) fmtExtra = ' ' + srStr;
else if (bps) fmtExtra = ' ' + bps;
var fmt = fmtBase + fmtExtra;
/* ALBUM (nettoyé) */
var alb = (album && album.length ? album : 'Unknown Album')
.replace(/[\\/*?"<>|:]/g,' ')
.replace(/\s{2,}/g,' ')
.trim();
/* Dossier feuille + ‘/’ obligatoire pour Sub Folder */
'[' + cat + '] (' + y4 + ') ' + arts + ' - ' + alb + ' [' + fmt + ']/'
+ ifmultidisc('Disc ' + pad(discno,2))
/*-----------------------------------------------------------------------------------------*/
+ ' / '
A2- FILENAME_From_AlbumGroups
/*-----------------------------------------------------------------------------------------*/
/* trackno -> mb_trackno -> discogs_trackno */
var tn = ('' + (trackno || mb_trackno || discogs_trackno || '')).replace(/\D+/g,'');
tn = tn ? (tn.length===1 ? '0'+tn : tn) : '00'; // padding 2 chiffres
/* title -> mb_title -> discogs_title */
var t = (title || mb_title || discogs_title || '').toString().trim();
/* nettoyage pour un nom de fichier sûr */
t = t
.replace(/[\\/]/g, function(ch){ return ch==='/' ? '/' : '\'; })
.replace(/[*?"<>|:]/g, ' ')
.replace(/\s{2,}/g,' ')
.trim();
if (!t) t = 'Track ' + tn;
/* sortie finale */
tn + ' - ' + t
/*-----------------------------------------------------------------------------------------*/
Would you mind letting me know what i’ve got wrong ?
Also just wondering, wouldn’t it be less confusing to implement 2 different boxes in the Preferences > File and Folder Correct > Filename masks editing window ; 1 for Subfolder, 1 for Filename, hard-code de last folder separator in between and prevent the use of ‘/’ in the filename mask window ?
Many thanks !
Asch