Skip to content

Commit 8727efa

Browse files
authored
Merge pull request #10 from rombat/fix/datetime-format
feat: datetime format added as an option
2 parents 2aa8c28 + 92761ff commit 8727efa

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ Syncs playcounts, track ratings, loved tracks and last played date from MusicBee
5858

5959
* `-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)).
6060
* `--csv <path>` : 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`
61+
* `--datetime-format <format>` : MusicBee CSV datetime format. Default: `"DD/MM/YYYY HH:mm"`. Use available formats from https://day.js.org/docs/en/display/format`
62+
6163

6264
### albumsSync
6365

index.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,17 @@ const commandLinesOptions = {
2222
flags: '-u, --user <user_name>',
2323
description: 'choose Navidrome username (by default if not used, the first user will be used)'
2424
},
25+
datetimeFormat: {
26+
flags: '--datetime-format <format>',
27+
description: 'MusicBee CSV datetime format. Default: "DD/MM/YYYY HH:mm"',
28+
defaultValue: 'DD/MM/YYYY HH:mm'
29+
},
2530
verbose: {
2631
flags: '--verbose',
2732
description: 'verbose debugging'
2833
}
2934
};
3035

31-
program
32-
.name('musicbee-navidrome-sync')
33-
.description(
34-
'MusicBee to Navidrome Sync (MBNDS) : Tools to sync MusicBee DB to Navidrome DB\nhttps://github.com/rombat/musicbee-navidrome-sync'
35-
)
36-
.version(packageJson.version, '-v, --version', 'output the current version');
37-
3836
program
3937
.command('fullSync')
4038
.description('sync playcounts, track ratings, loved tracks and last played from MusicBee DB to Navidrome DB')
@@ -43,8 +41,20 @@ program
4341
.option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description)
4442
.option(commandLinesOptions.csv.flags, commandLinesOptions.description, commandLinesOptions.defaultValue)
4543
.option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue)
44+
.option(
45+
commandLinesOptions.datetimeFormat.flags,
46+
commandLinesOptions.datetimeFormat.description,
47+
commandLinesOptions.datetimeFormat.defaultValue
48+
)
4649
.action(runAction);
4750

51+
program
52+
.name('musicbee-navidrome-sync')
53+
.description(
54+
'MusicBee to Navidrome Sync (MBNDS) : Tools to sync MusicBee DB to Navidrome DB\nhttps://github.com/rombat/musicbee-navidrome-sync'
55+
)
56+
.version(packageJson.version, '-v, --version', 'output the current version');
57+
4858
program
4959
.command('albumsSync')
5060
.description('update all albums playcounts and ratings based on existing Navidrome DB')

lib/handlers/MBNDSynchronizer.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ class MBNDSynchronizer {
7171
throw new Error('DB file not found');
7272
}
7373

74+
if (options.datetimeFormat && !dayjs(dayjs().format(options.datetimeFormat), options.datetimeFormat).isValid()) {
75+
throw new Error(
76+
`Invalid datetime format : ${options.datetimeFormat}. Please use available formats from https://day.js.org/docs/en/display/format`
77+
);
78+
}
79+
7480
this.backupDbFile();
7581

7682
this.sequelize = await dbManager.init(paths.dbFilePath);
@@ -163,10 +169,10 @@ class MBNDSynchronizer {
163169
}
164170
return rating;
165171
},
166-
dateAdded: item => (dayjs(item, 'DD/MM/YYYY HH:mm').isValid() ? dayjs(item, 'DD/MM/YYYY HH:mm').utc() : null),
167-
lastPlayed: item => (dayjs(item, 'DD/MM/YYYY HH:mm').isValid() ? dayjs(item, 'DD/MM/YYYY HH:mm').utc() : null),
168-
dateModified: item => (dayjs(item, 'DD/MM/YYYY HH:mm').isValid() ? dayjs(item, 'DD/MM/YYYY HH:mm').utc() : null),
169-
love: item => (!!item.trim() ? 1 : 0)
172+
dateAdded: item => (dayjs(item, options.datetimeFormat).isValid() ? dayjs(item, options.datetimeFormat).utc() : null),
173+
lastPlayed: item => (dayjs(item, options.datetimeFormat).isValid() ? dayjs(item, options.datetimeFormat).utc() : null),
174+
dateModified: item => (dayjs(item, options.datetimeFormat).isValid() ? dayjs(item, options.datetimeFormat).utc() : null),
175+
love: item => (!!item?.trim() ? 1 : 0)
170176
}
171177
})
172178
.preFileLine((fileLineString, lineIdx) => {

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "musicbee-navidrome-sync",
3-
"version": "1.0.6",
3+
"version": "1.1.0",
44
"description": "sync ratings and playcount from musicbee db to navidrome db",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"fullSync": "node index.js fullSync",
99
"albumsSync": "node index.js albumsSync",
10-
"artistsSync": "node index.js artistsSync"
10+
"artistsSync": "node index.js artistsSync",
11+
"build": "pkg ."
1112
},
1213
"author": "rombat",
1314
"license": "GNU GPL V3.0",
@@ -28,6 +29,7 @@
2829
"pkg": {
2930
"assets": ["node_modules/**/*"],
3031
"targets": [ "node16-win-x64"],
31-
"outputPath": "dist"
32+
"outputPath": "dist",
33+
"outputName": "musicbee-navidrome-sync"
3234
}
3335
}

0 commit comments

Comments
 (0)