Skip to content

Commit 9d845d6

Browse files
authored
Merge pull request #4 from rombat/fix/new-plugin-version
fix: newer versions of plugin have new headers and rating system
2 parents 30d07b6 + 64e5007 commit 9d845d6

File tree

3 files changed

+47
-30
lines changed

3 files changed

+47
-30
lines changed

index.js

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,64 @@
11
const { program } = require('commander');
22
const { MBNDSynchronizer } = require('./lib/handlers/MBNDSynchronizer.js');
3+
const packageJson = require('./package.json');
34

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

10+
const commandLinesOptions = {
11+
csv: {
12+
flags: '--csv <path>',
13+
description: 'MusicBee CSV source file path. Default: MusicBee_Export.csv, in the same folder as MBNDS',
14+
defaultValue: 'MusicBee_Export.csv'
15+
},
16+
db: {
17+
flags: '--db <path>',
18+
description: 'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS',
19+
defaultValue: 'navidrome.db'
20+
},
21+
user: {
22+
flags: '-u, --user <user_name>',
23+
description: 'choose Navidrome username (by default if not used, the first user will be used)'
24+
},
25+
verbose: {
26+
flags: '--verbose',
27+
description: 'verbose debugging'
28+
}
29+
};
30+
931
program
1032
.name('musicbee-navidrome-sync')
1133
.description(
1234
'MusicBee to Navidrome Sync (MBNDS) : Tools to sync MusicBee DB to Navidrome DB\nhttps://github.com/rombat/musicbee-navidrome-sync'
1335
)
14-
.version('1.0.4', '-v, --version', 'output the current version');
36+
.version(packageJson.version, '-v, --version', 'output the current version');
1537

1638
program
1739
.command('fullSync')
1840
.description('sync playcounts, track ratings, loved tracks and last played from MusicBee DB to Navidrome DB')
19-
.option('-u, --user <user_name>', 'choose Navidrome username (by default if not used, the first user will be used)')
41+
.option(commandLinesOptions.user.flags, commandLinesOptions.user.description)
2042
.option('-f, --first', 'run sync for the first time: add MB playcount to ND playcount')
21-
.option('--verbose', 'verbose debugging')
22-
.option(
23-
'--csv <path>',
24-
'MusicBee CSV source file path. Default: MusicBee_Export.csv, in the same folder as MBNDS',
25-
'MusicBee_Export.csv'
26-
)
27-
.option(
28-
'--db <path>',
29-
'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS',
30-
'navidrome.db'
31-
)
43+
.option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description)
44+
.option(commandLinesOptions.csv.flags, commandLinesOptions.description, commandLinesOptions.defaultValue)
45+
.option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue)
3246
.action(runAction);
3347

3448
program
3549
.command('albumsSync')
3650
.description('update all albums playcounts and ratings based on existing Navidrome DB')
37-
.option('-u, --user <user_name>', 'choose Navidrome username (by default if not used, the first user will be used)')
38-
.option('--verbose', 'verbose debugging')
39-
.option(
40-
'--db <path>',
41-
'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS',
42-
'navidrome.db'
43-
)
51+
.option(commandLinesOptions.user.flags, commandLinesOptions.user.description)
52+
.option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description)
53+
.option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue)
4454
.action(runAction);
4555

4656
program
4757
.command('artistsSync')
4858
.description('update all artists playcounts and ratings based on existing Navidrome DB')
49-
.option('-u, --user <user_name>', 'choose Navidrome username (by default if not used, the first user will be used)')
50-
.option('--verbose', 'verbose debugging')
51-
.option(
52-
'--db <path>',
53-
'Navidrome SQLITE .db source file path. Default: navidrome.db, in the same folder as MBNDS',
54-
'navidrome.db'
55-
)
59+
.option(commandLinesOptions.user.flags, commandLinesOptions.user.description)
60+
.option(commandLinesOptions.verbose.flags, commandLinesOptions.verbose.description)
61+
.option(commandLinesOptions.db.flags, commandLinesOptions.db.description, commandLinesOptions.db.defaultValue)
5662
.action(runAction);
5763

5864
program.parse();

lib/handlers/MBNDSynchronizer.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,17 @@ class MBNDSynchronizer {
152152
albumRating: 'number',
153153
playCount: 'number',
154154
skipCount: 'number',
155-
rating: item => parseInt(item) || 0,
155+
rating: item => {
156+
let rating = parseInt(item);
157+
if (!rating) {
158+
return 0;
159+
}
160+
// handling Additional Tagging & Reporting Tools new rating system
161+
if (rating > 5 && rating <= 100) {
162+
rating = Math.round(rating / 20);
163+
}
164+
return rating;
165+
},
156166
dateAdded: item => (dayjs(item, 'DD/MM/YYYY HH:mm').isValid() ? dayjs(item, 'DD/MM/YYYY HH:mm').utc() : null),
157167
lastPlayed: item => (dayjs(item, 'DD/MM/YYYY HH:mm').isValid() ? dayjs(item, 'DD/MM/YYYY HH:mm').utc() : null),
158168
dateModified: item => (dayjs(item, 'DD/MM/YYYY HH:mm').isValid() ? dayjs(item, 'DD/MM/YYYY HH:mm').utc() : null),
@@ -162,7 +172,8 @@ class MBNDSynchronizer {
162172
.preFileLine((fileLineString, lineIdx) => {
163173
if (lineIdx === 0) {
164174
this.REQUIRED_HEADERS.map(header => {
165-
if (!fileLineString.includes(header)) {
175+
// camelCase: handling Additional Tagging & Reporting Tools new headers
176+
if (!camelCase(fileLineString).includes(camelCase(header))) {
166177
throw new Error(`${header} missing in your CSV headers`);
167178
}
168179
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "musicbee-navidrome-sync",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "sync ratings and playcount from musicbee db to navidrome db",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)