fix: preserve existing cover art when editing metadata without new image
-map 0:v? copies the embedded cover stream from the original file when no new artwork is supplied, preventing it from being silently stripped. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
c9fe1da1b0
commit
e4cdbe44e7
1 file changed
+7
-2
@@ -483,7 +483,12 @@ app.post('/api/edit-metadata', async (req, res) => {
|
||||
const ffArgs = ['-i', filePath];
|
||||
if (artFile) ffArgs.push('-i', artFile);
|
||||
ffArgs.push('-map', '0:a');
|
||||
if (artFile) ffArgs.push('-map', '1:v');
|
||||
// Always carry cover art: new file if provided, otherwise preserve existing embedded art
|
||||
if (artFile) {
|
||||
ffArgs.push('-map', '1:v');
|
||||
} else {
|
||||
ffArgs.push('-map', '0:v?'); // '?' = optional, no error if file has no cover
|
||||
}
|
||||
ffArgs.push('-c', 'copy', '-map_metadata', '-1', '-id3v2_version', '3');
|
||||
if (title) ffArgs.push('-metadata', `title=${title}`);
|
||||
if (artist) ffArgs.push('-metadata', `artist=${artist}`, '-metadata', `album_artist=${artist.split(';')[0].trim()}`);
|
||||
@@ -493,7 +498,7 @@ app.post('/api/edit-metadata', async (req, res) => {
|
||||
if (totalTracks) ffArgs.push('-metadata', `totaltracks=${String(totalTracks)}`);
|
||||
if (discNum) ffArgs.push('-metadata', `disc=${discTotal ? `${discNum}/${discTotal}` : String(discNum)}`);
|
||||
if (genre) ffArgs.push('-metadata', `genre=${genre}`);
|
||||
if (artFile) ffArgs.push('-metadata:s:v', 'title=Album cover', '-metadata:s:v', 'comment=Cover (front)');
|
||||
ffArgs.push('-metadata:s:v', 'title=Album cover', '-metadata:s:v', 'comment=Cover (front)');
|
||||
ffArgs.push(tmpFile, '-y', '-loglevel', 'error');
|
||||
|
||||
const ff = spawn('ffmpeg', ffArgs);
|
||||
|
||||
Reference in new issue
Block a user