From 6d311b7781f24968fb49480ac6f1d6ccf89392da Mon Sep 17 00:00:00 2001 From: Romain Batigne Date: Sat, 6 Apr 2024 15:10:00 +0200 Subject: [PATCH 1/4] fix: datetime format from MusicBee may vary => explicit format removed --- lib/handlers/MBNDSynchronizer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/handlers/MBNDSynchronizer.js b/lib/handlers/MBNDSynchronizer.js index 172eab2..c875600 100644 --- a/lib/handlers/MBNDSynchronizer.js +++ b/lib/handlers/MBNDSynchronizer.js @@ -163,9 +163,9 @@ class MBNDSynchronizer { } return rating; }, - dateAdded: item => (dayjs(item, 'DD/MM/YYYY HH:mm').isValid() ? dayjs(item, 'DD/MM/YYYY HH:mm').utc() : null), - lastPlayed: item => (dayjs(item, 'DD/MM/YYYY HH:mm').isValid() ? dayjs(item, 'DD/MM/YYYY HH:mm').utc() : null), - dateModified: item => (dayjs(item, 'DD/MM/YYYY HH:mm').isValid() ? dayjs(item, 'DD/MM/YYYY HH:mm').utc() : null), + dateAdded: item => (dayjs(item).isValid() ? dayjs(item).utc() : null), + lastPlayed: item => (dayjs(item).isValid() ? dayjs(item).utc() : null), + dateModified: item => (dayjs(item).isValid() ? dayjs(item).utc() : null), love: item => (!!item.trim() ? 1 : 0) } }) From 7473f69727dd29028de9ea7bd64a7719a82ca807 Mon Sep 17 00:00:00 2001 From: Romain Batigne Date: Sat, 6 Apr 2024 15:24:20 +0200 Subject: [PATCH 2/4] chore: build cmd added --- package.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a84feb3..f385189 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,14 @@ { "name": "musicbee-navidrome-sync", - "version": "1.0.6", + "version": "1.0.7", "description": "sync ratings and playcount from musicbee db to navidrome db", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "fullSync": "node index.js fullSync", "albumsSync": "node index.js albumsSync", - "artistsSync": "node index.js artistsSync" + "artistsSync": "node index.js artistsSync", + "build": "pkg ." }, "author": "rombat", "license": "GNU GPL V3.0", @@ -28,6 +29,7 @@ "pkg": { "assets": ["node_modules/**/*"], "targets": [ "node16-win-x64"], - "outputPath": "dist" + "outputPath": "dist", + "outputName": "musicbee-navidrome-sync" } } From 5dfce3d1db98a41d82e791fefd6ab51d3bfdecfa Mon Sep 17 00:00:00 2001 From: Romain Batigne Date: Sat, 6 Apr 2024 16:14:17 +0200 Subject: [PATCH 3/4] feat: slight adjustment to date parsing --- lib/handlers/MBNDSynchronizer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/handlers/MBNDSynchronizer.js b/lib/handlers/MBNDSynchronizer.js index c875600..e69b9ff 100644 --- a/lib/handlers/MBNDSynchronizer.js +++ b/lib/handlers/MBNDSynchronizer.js @@ -163,10 +163,10 @@ class MBNDSynchronizer { } return rating; }, - dateAdded: item => (dayjs(item).isValid() ? dayjs(item).utc() : null), - lastPlayed: item => (dayjs(item).isValid() ? dayjs(item).utc() : null), - dateModified: item => (dayjs(item).isValid() ? dayjs(item).utc() : null), - love: item => (!!item.trim() ? 1 : 0) + dateAdded: item => (!!item?.trim() && dayjs(item).isValid() ? dayjs(item).utc() : null), + lastPlayed: item => (!!item?.trim() && dayjs(item).isValid() ? dayjs(item).utc() : null), + dateModified: item => (!!item?.trim() && dayjs(item).isValid() ? dayjs(item).utc() : null), + love: item => (!!item?.trim() ? 1 : 0) } }) .preFileLine((fileLineString, lineIdx) => { From 92761ffbd0e993e1b2263a8a96d66f323d02bd7d Mon Sep 17 00:00:00 2001 From: Romain Batigne Date: Sat, 6 Apr 2024 17:07:05 +0200 Subject: [PATCH 4/4] feat: datetime format added as option --- README.md | 2 ++ index.js | 24 +++++++++++++++++------- lib/handlers/MBNDSynchronizer.js | 12 +++++++++--- package.json | 2 +- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1dcb5f1..961f092 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ Syncs playcounts, track ratings, loved tracks and last played date from MusicBee * `-f, --first` : runs sync for the first time: **add** MusicBee playcount to Navidrome playcount. If not used, playcount will be updated only if greater than Navidrome's one (see [Notes](#-notes)). * `--csv ` : MusicBee CSV source file path. By default if not passed, will look for a file named `MusicBee_Export.csv` in the same folder as `musicbee-navidrome-sync.exe` +* `--datetime-format ` : MusicBee CSV datetime format. Default: `"DD/MM/YYYY HH:mm"`. Use available formats from https://day.js.org/docs/en/display/format` + ### albumsSync diff --git a/index.js b/index.js index 842fd1d..46a6e0b 100644 --- a/index.js +++ b/index.js @@ -22,19 +22,17 @@ const commandLinesOptions = { flags: '-u, --user ', description: 'choose Navidrome username (by default if not used, the first user will be used)' }, + datetimeFormat: { + flags: '--datetime-format ', + description: 'MusicBee CSV datetime format. Default: "DD/MM/YYYY HH:mm"', + defaultValue: 'DD/MM/YYYY HH:mm' + }, verbose: { flags: '--verbose', description: 'verbose debugging' } }; -program - .name('musicbee-navidrome-sync') - .description( - 'MusicBee to Navidrome Sync (MBNDS) : Tools to sync MusicBee DB to Navidrome DB\nhttps://github.com/rombat/musicbee-navidrome-sync' - ) - .version(packageJson.version, '-v, --version', 'output the current version'); - program .command('fullSync') .description('sync playcounts, track ratings, loved tracks and last played from MusicBee DB to Navidrome DB') @@ -43,8 +41,20 @@ program .option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description) .option(commandLinesOptions.csv.flags, commandLinesOptions.description, commandLinesOptions.defaultValue) .option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue) + .option( + commandLinesOptions.datetimeFormat.flags, + commandLinesOptions.datetimeFormat.description, + commandLinesOptions.datetimeFormat.defaultValue + ) .action(runAction); +program + .name('musicbee-navidrome-sync') + .description( + 'MusicBee to Navidrome Sync (MBNDS) : Tools to sync MusicBee DB to Navidrome DB\nhttps://github.com/rombat/musicbee-navidrome-sync' + ) + .version(packageJson.version, '-v, --version', 'output the current version'); + program .command('albumsSync') .description('update all albums playcounts and ratings based on existing Navidrome DB') diff --git a/lib/handlers/MBNDSynchronizer.js b/lib/handlers/MBNDSynchronizer.js index e69b9ff..d9e1cee 100644 --- a/lib/handlers/MBNDSynchronizer.js +++ b/lib/handlers/MBNDSynchronizer.js @@ -71,6 +71,12 @@ class MBNDSynchronizer { throw new Error('DB file not found'); } + if (options.datetimeFormat && !dayjs(dayjs().format(options.datetimeFormat), options.datetimeFormat).isValid()) { + throw new Error( + `Invalid datetime format : ${options.datetimeFormat}. Please use available formats from https://day.js.org/docs/en/display/format` + ); + } + this.backupDbFile(); this.sequelize = await dbManager.init(paths.dbFilePath); @@ -163,9 +169,9 @@ class MBNDSynchronizer { } return rating; }, - dateAdded: item => (!!item?.trim() && dayjs(item).isValid() ? dayjs(item).utc() : null), - lastPlayed: item => (!!item?.trim() && dayjs(item).isValid() ? dayjs(item).utc() : null), - dateModified: item => (!!item?.trim() && dayjs(item).isValid() ? dayjs(item).utc() : null), + dateAdded: item => (dayjs(item, options.datetimeFormat).isValid() ? dayjs(item, options.datetimeFormat).utc() : null), + lastPlayed: item => (dayjs(item, options.datetimeFormat).isValid() ? dayjs(item, options.datetimeFormat).utc() : null), + dateModified: item => (dayjs(item, options.datetimeFormat).isValid() ? dayjs(item, options.datetimeFormat).utc() : null), love: item => (!!item?.trim() ? 1 : 0) } }) diff --git a/package.json b/package.json index f385189..f087ec8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "musicbee-navidrome-sync", - "version": "1.0.7", + "version": "1.1.0", "description": "sync ratings and playcount from musicbee db to navidrome db", "main": "index.js", "scripts": {