Skip to content

Commit

Permalink
Merge pull request #10 from rombat/fix/datetime-format
Browse files Browse the repository at this point in the history
feat: datetime format added as an option
  • Loading branch information
rombat authored Apr 6, 2024
2 parents 2aa8c28 + 92761ff commit 8727efa
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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`
* `--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`


### albumsSync

Expand Down
24 changes: 17 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ const commandLinesOptions = {
flags: '-u, --user <user_name>',
description: 'choose Navidrome username (by default if not used, the first user will be used)'
},
datetimeFormat: {
flags: '--datetime-format <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')
Expand All @@ -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')
Expand Down
14 changes: 10 additions & 4 deletions lib/handlers/MBNDSynchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -163,10 +169,10 @@ 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),
love: item => (!!item.trim() ? 1 : 0)
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)
}
})
.preFileLine((fileLineString, lineIdx) => {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "musicbee-navidrome-sync",
"version": "1.0.6",
"version": "1.1.0",
"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",
Expand All @@ -28,6 +29,7 @@
"pkg": {
"assets": ["node_modules/**/*"],
"targets": [ "node16-win-x64"],
"outputPath": "dist"
"outputPath": "dist",
"outputName": "musicbee-navidrome-sync"
}
}

0 comments on commit 8727efa

Please sign in to comment.