feat: rename song file artist segment when applying romaji override fix
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
ff3bb782d3
commit
59120fd7b6
1 file changed
+24
@@ -704,6 +704,30 @@ app.post('/api/fix-artist-sort', async (req, res) => {
|
||||
});
|
||||
fs.renameSync(tmpFile, filePath);
|
||||
|
||||
// Rename the file itself: keep track prefix + title, replace artist segment.
|
||||
// Convention: {NN - }Artist - Title.ext (separator may be " - " or " – ")
|
||||
const oldBasename = path.basename(filePath);
|
||||
const oldStem = oldBasename.slice(0, -fileExt.length);
|
||||
// Extract leading track prefix (e.g. "01 - " or "01-15 – ")
|
||||
const trackPrefixMatch = oldStem.match(/^(\d[\d\-]*\s*[-–—]\s*)/);
|
||||
const trackPrefix = trackPrefixMatch ? trackPrefixMatch[1] : '';
|
||||
// Everything after the track prefix: "OldArtist - Title" or just "Title"
|
||||
const afterPrefix = oldStem.slice(trackPrefix.length);
|
||||
// Split on first " - " or " – ": if 2+ segments, first is old artist, rest is title
|
||||
const segments = afterPrefix.split(/\s+[-–—]\s+/);
|
||||
const titlePart = segments.length >= 2 ? segments.slice(1).join(' - ') : afterPrefix;
|
||||
const safeArtistFile = sanitize(artistSort.split(/[,;&]/)[0].trim());
|
||||
const safeTitlePart = sanitize(titlePart);
|
||||
const newBasename = `${trackPrefix}${safeArtistFile} - ${safeTitlePart}${fileExt}`;
|
||||
|
||||
if (newBasename !== oldBasename) {
|
||||
const renamedPath = path.join(path.dirname(filePath), newBasename);
|
||||
if (!fs.existsSync(renamedPath)) {
|
||||
fs.renameSync(filePath, renamedPath);
|
||||
filePath = renamedPath;
|
||||
}
|
||||
}
|
||||
|
||||
// Move to correct artist/album folder: {musicPath}/{safeArtistDir}/{albumName}/
|
||||
const oldAlbumDir = path.dirname(filePath);
|
||||
const oldArtistDir = path.dirname(oldAlbumDir);
|
||||
|
||||
Reference in new issue
Block a user