改动位置
- 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) {
|
function writeMetadata(inputPath, outputPath, metadata) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const args = ['-i', inputPath];
|
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
|
// Add cover input if available
|
||||||
if (metadata.cover) {
|
if (metadata.cover) {
|
||||||
@@ -492,6 +503,7 @@ function writeMetadata(inputPath, outputPath, metadata) {
|
|||||||
// ID3v2 metadata for MP3 (cover art)
|
// ID3v2 metadata for MP3 (cover art)
|
||||||
if (outputPath.endsWith('.mp3')) {
|
if (outputPath.endsWith('.mp3')) {
|
||||||
args.push('-id3v2_version', '3');
|
args.push('-id3v2_version', '3');
|
||||||
|
args.push('-write_id3v1', '1');
|
||||||
args.push('-metadata:s:v', 'title="Album cover"');
|
args.push('-metadata:s:v', 'title="Album cover"');
|
||||||
args.push('-metadata:s:v', 'comment="Cover (front)"');
|
args.push('-metadata:s:v', 'comment="Cover (front)"');
|
||||||
} else if (outputPath.endsWith('.flac')) {
|
} else if (outputPath.endsWith('.flac')) {
|
||||||
@@ -501,11 +513,19 @@ function writeMetadata(inputPath, outputPath, metadata) {
|
|||||||
args.push('-c', 'copy');
|
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
|
// Add metadata tags
|
||||||
args.push(
|
args.push(
|
||||||
'-metadata', `title=${metadata.title}`,
|
'-metadata', `title=${title}`,
|
||||||
'-metadata', `artist=${metadata.artist}`,
|
'-metadata', `artist=${artist}`,
|
||||||
'-metadata', `album=${metadata.album}`
|
'-metadata', `album=${album}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// Required for FLAC + Cover to work properly without re-encoding audio
|
// 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);
|
res.json(playlist);
|
||||||
});
|
});
|
||||||
|
|
||||||
cron.schedule(`*/${SYNC_INTERVAL} * * * *`, () => {
|
function runScheduledSync() {
|
||||||
console.log('[Cron] Starting scheduled sync...');
|
console.log('[Cron] Starting scheduled sync...');
|
||||||
|
|
||||||
for (const playlist of playlists.playlists) {
|
for (const playlist of playlists.playlists) {
|
||||||
syncPlaylist(playlist);
|
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, () => {
|
app.listen(PORT, () => {
|
||||||
console.log(`Netease-sync server running on port ${PORT}`);
|
console.log(`Netease-sync server running on port ${PORT}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user