改动位置
- Netease-sync/server.js:仅用 setInterval(syncIntervalSeconds * 1000)
This commit is contained in:
@@ -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}`);
|
||||
|
||||
Reference in New Issue
Block a user