Skip to content

Commit

Permalink
Merge pull request #4 from rombat/fix/new-plugin-version
Browse files Browse the repository at this point in the history
fix: newer versions of plugin have new headers and rating system
  • Loading branch information
rombat authored Mar 24, 2023
2 parents 30d07b6 + 64e5007 commit 9d845d6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 30 deletions.
60 changes: 33 additions & 27 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
const { program } = require('commander');
const { MBNDSynchronizer } = require('./lib/handlers/MBNDSynchronizer.js');
const packageJson = require('./package.json');

const runAction = async (options, command) => {
const synchronizer = new MBNDSynchronizer(options);
await synchronizer.run(command._name);
};

const commandLinesOptions = {
csv: {
flags: '--csv <path>',
description: 'MusicBee CSV source file path. Default: MusicBee_Export.csv, in the same folder as MBNDS',
defaultValue: 'MusicBee_Export.csv'
},
db: {
flags: '--db <path>',
description: 'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS',
defaultValue: 'navidrome.db'
},
user: {
flags: '-u, --user <user_name>',
description: 'choose Navidrome username (by default if not used, the first user will be used)'
},
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('1.0.4', '-v, --version', 'output the current version');
.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')
.option('-u, --user <user_name>', 'choose Navidrome username (by default if not used, the first user will be used)')
.option(commandLinesOptions.user.flags, commandLinesOptions.user.description)
.option('-f, --first', 'run sync for the first time: add MB playcount to ND playcount')
.option('--verbose', 'verbose debugging')
.option(
'--csv <path>',
'MusicBee CSV source file path. Default: MusicBee_Export.csv, in the same folder as MBNDS',
'MusicBee_Export.csv'
)
.option(
'--db <path>',
'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS',
'navidrome.db'
)
.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)
.action(runAction);

program
.command('albumsSync')
.description('update all albums playcounts and ratings based on existing Navidrome DB')
.option('-u, --user <user_name>', 'choose Navidrome username (by default if not used, the first user will be used)')
.option('--verbose', 'verbose debugging')
.option(
'--db <path>',
'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS',
'navidrome.db'
)
.option(commandLinesOptions.user.flags, commandLinesOptions.user.description)
.option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description)
.option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue)
.action(runAction);

program
.command('artistsSync')
.description('update all artists playcounts and ratings based on existing Navidrome DB')
.option('-u, --user <user_name>', 'choose Navidrome username (by default if not used, the first user will be used)')
.option('--verbose', 'verbose debugging')
.option(
'--db <path>',
'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS',
'navidrome.db'
)
.option(commandLinesOptions.user.flags, commandLinesOptions.user.description)
.option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description)
.option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue)
.action(runAction);

program.parse();
15 changes: 13 additions & 2 deletions lib/handlers/MBNDSynchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,17 @@ class MBNDSynchronizer {
albumRating: 'number',
playCount: 'number',
skipCount: 'number',
rating: item => parseInt(item) || 0,
rating: item => {
let rating = parseInt(item);
if (!rating) {
return 0;
}
// handling Additional Tagging & Reporting Tools new rating system
if (rating > 5 && rating <= 100) {
rating = Math.round(rating / 20);
}
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),
Expand All @@ -162,7 +172,8 @@ class MBNDSynchronizer {
.preFileLine((fileLineString, lineIdx) => {
if (lineIdx === 0) {
this.REQUIRED_HEADERS.map(header => {
if (!fileLineString.includes(header)) {
// camelCase: handling Additional Tagging & Reporting Tools new headers
if (!camelCase(fileLineString).includes(camelCase(header))) {
throw new Error(`${header} missing in your CSV headers`);
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "musicbee-navidrome-sync",
"version": "1.0.4",
"version": "1.0.5",
"description": "sync ratings and playcount from musicbee db to navidrome db",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 9d845d6

Please sign in to comment.