Compare commits

...

2 Commits

Author SHA1 Message Date
Tom
2b2cc20a1d Added support for multiple trackers & scrobblers. 2024-12-06 18:19:49 +00:00
Tom
7ef6ebb076 Docker runs the app in production. 2024-12-06 18:18:17 +00:00
5 changed files with 114 additions and 98 deletions

2
.gitignore vendored
View File

@ -4,4 +4,4 @@ config/*
!config/configuration.js !config/configuration.js
!config.schema.js !config.schema.js
credentials.* credentials.*
config*.yml *.yml

View File

@ -14,4 +14,4 @@ COPY . .
EXPOSE ${WEB_PORT} EXPOSE ${WEB_PORT}
CMD [ "node", "app.js" ] CMD ["npm", "run", "start"]

15
app.js
View File

@ -10,11 +10,16 @@ const Recorder = require("./services/recorder");
const MalojaScrobbler = require("./services/scrobblers/maloja-scrobbler"); const MalojaScrobbler = require("./services/scrobblers/maloja-scrobbler");
const maloja = new MalojaScrobbler(config.maloja, logger); let trackers = []
const spotify = new SpotifyTracker(config.spotify); trackers = trackers.concat(config.spotify.map(config => new SpotifyTracker(config)));
(async () => await spotify.loadCredentials())(); trackers = trackers.concat(config.plex.map(config => new PlexTracker(config)));
const plex = new PlexTracker(config.plex);
const recorder = new Recorder(sessions, [plex, spotify], [maloja], config.scrobble, logger); const uniqueSpotifys = new Set(config.spotify.map(c => c.client_id));
for (let spotify of uniqueSpotifys)
(async () => await spotify.loadCredentials())();
const scrobblers = config.maloja.map(config => new MalojaScrobbler(config, logger));
const recorder = new Recorder(sessions, trackers, scrobblers, config.scrobble, logger);
setInterval(() => recorder.record(), 5000); setInterval(() => recorder.record(), 5000);

View File

@ -3,83 +3,89 @@ const schema = {
required: [], required: [],
properties: { properties: {
maloja: { maloja: {
type: 'object', type: 'array',
required: ['name', 'url', 'token'], items: {
properties: { type: 'object',
name: { required: ['name', 'url', 'token'],
type: 'string' properties: {
}, name: {
url: { type: 'string'
type: 'string' },
}, url: {
token: { type: 'string'
type: 'string' },
}, token: {
type: 'string'
},
}
} }
}, },
plex: { plex: {
type: 'object', type: 'array',
required: ['name', 'url', 'token', 'scrobblers'], items: {
properties: { type: 'object',
name: { required: ['name', 'url', 'token', 'scrobblers'],
type: 'string' properties: {
}, name: {
url: {
type: 'string'
},
token: {
type: 'string'
},
filters: {
type: 'array',
minItems: 0,
items: {
type: 'object',
properties: {
library: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
ip: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
deviceId: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
platform: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
product: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
}
}
},
scrobblers: {
type: 'array',
items: {
type: 'string' type: 'string'
}, },
minItems: 1 url: {
type: 'string'
},
token: {
type: 'string'
},
filters: {
type: 'array',
minItems: 0,
items: {
type: 'object',
properties: {
library: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
ip: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
deviceId: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
platform: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
product: {
type: 'array',
items: {
type: 'string'
},
minItems: 0,
},
}
}
},
scrobblers: {
type: 'array',
items: {
type: 'string'
},
minItems: 1
}
} }
} }
}, },
@ -102,27 +108,30 @@ const schema = {
}, },
spotify: { spotify: {
type: 'object', type: 'array',
required: ['name', 'client_id', 'client_secret', 'redirect_uri', 'scrobblers'], items: {
properties: { type: 'object',
name: { required: ['name', 'client_id', 'client_secret', 'redirect_uri', 'scrobblers'],
type: 'string' properties: {
}, name: {
client_id: {
type: 'string'
},
client_secret: {
type: 'string'
},
redirect_uri: {
type: 'string'
},
scrobblers: {
type: 'array',
items: {
type: 'string' type: 'string'
}, },
minItems: 1 client_id: {
type: 'string'
},
client_secret: {
type: 'string'
},
redirect_uri: {
type: 'string'
},
scrobblers: {
type: 'array',
items: {
type: 'string'
},
minItems: 1
}
} }
} }
}, },

View File

@ -3,6 +3,8 @@
"version": "0.0.0", "version": "0.0.0",
"main": "app.js", "main": "app.js",
"scripts": { "scripts": {
"start": "NODE_ENV=production node app.js",
"dev": "NODE_ENV=development node app.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "", "author": "",