From 79595dc9ed6de83a557966f9d357a14389782929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Tue, 13 Jan 2026 14:28:01 +0800 Subject: [PATCH] =?UTF-8?q?=20=20=E6=94=B9=E5=8A=A8=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Netease-sync/server.js:仅用 setInterval(syncIntervalSeconds * 1000) --- Netease-sync/server.js | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/Netease-sync/server.js b/Netease-sync/server.js index 908e385..78c0bd1 100644 --- a/Netease-sync/server.js +++ b/Netease-sync/server.js @@ -481,6 +481,17 @@ async function resolveTuneHubAudioUrl(apiUrl) { function writeMetadata(inputPath, outputPath, metadata) { return new Promise((resolve, reject) => { const args = ['-i', inputPath]; + const sanitizeTag = (value) => { + if (!value) return ''; + return value + .toString() + .normalize('NFC') + .replace(/[\x00-\x1f\x7f]/g, '') + .trim(); + }; + const title = sanitizeTag(metadata.title); + const artist = sanitizeTag(metadata.artist); + const album = sanitizeTag(metadata.album); // Add cover input if available if (metadata.cover) { @@ -492,6 +503,7 @@ function writeMetadata(inputPath, outputPath, metadata) { // ID3v2 metadata for MP3 (cover art) if (outputPath.endsWith('.mp3')) { args.push('-id3v2_version', '3'); + args.push('-write_id3v1', '1'); args.push('-metadata:s:v', 'title="Album cover"'); args.push('-metadata:s:v', 'comment="Cover (front)"'); } else if (outputPath.endsWith('.flac')) { @@ -501,11 +513,19 @@ function writeMetadata(inputPath, outputPath, metadata) { args.push('-c', 'copy'); } + // Clear existing tags to avoid garbled metadata inheritance + args.push('-map_metadata', '-1'); + + if (outputPath.endsWith('.mp3')) { + args.push('-id3v2_version', '3'); + args.push('-write_id3v1', '1'); + } + // Add metadata tags args.push( - '-metadata', `title=${metadata.title}`, - '-metadata', `artist=${metadata.artist}`, - '-metadata', `album=${metadata.album}` + '-metadata', `title=${title}`, + '-metadata', `artist=${artist}`, + '-metadata', `album=${album}` ); // Required for FLAC + Cover to work properly without re-encoding audio @@ -1174,13 +1194,20 @@ app.get('/api/status/:id', (req, res) => { res.json(playlist); }); -cron.schedule(`*/${SYNC_INTERVAL} * * * *`, () => { +function runScheduledSync() { console.log('[Cron] Starting scheduled sync...'); - for (const playlist of playlists.playlists) { syncPlaylist(playlist); } -}); +} + +const syncIntervalSeconds = Number.parseInt(SYNC_INTERVAL, 10); +if (Number.isFinite(syncIntervalSeconds) && syncIntervalSeconds > 0) { + setInterval(runScheduledSync, syncIntervalSeconds * 1000); + console.log(`[Cron] Scheduled sync every ${syncIntervalSeconds} seconds`); +} else { + console.warn(`[Cron] Invalid SYNC_INTERVAL=${SYNC_INTERVAL}, auto sync disabled`); +} app.listen(PORT, () => { console.log(`Netease-sync server running on port ${PORT}`);