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"]

13
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)));
trackers = trackers.concat(config.plex.map(config => new PlexTracker(config)));
const uniqueSpotifys = new Set(config.spotify.map(c => c.client_id));
for (let spotify of uniqueSpotifys)
(async () => await spotify.loadCredentials())(); (async () => await spotify.loadCredentials())();
const plex = new PlexTracker(config.plex);
const recorder = new Recorder(sessions, [plex, spotify], [maloja], config.scrobble, logger); 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,6 +3,8 @@ const schema = {
required: [], required: [],
properties: { properties: {
maloja: { maloja: {
type: 'array',
items: {
type: 'object', type: 'object',
required: ['name', 'url', 'token'], required: ['name', 'url', 'token'],
properties: { properties: {
@ -16,8 +18,11 @@ const schema = {
type: 'string' type: 'string'
}, },
} }
}
}, },
plex: { plex: {
type: 'array',
items: {
type: 'object', type: 'object',
required: ['name', 'url', 'token', 'scrobblers'], required: ['name', 'url', 'token', 'scrobblers'],
properties: { properties: {
@ -82,6 +87,7 @@ const schema = {
minItems: 1 minItems: 1
} }
} }
}
}, },
scrobble: { scrobble: {
@ -102,6 +108,8 @@ const schema = {
}, },
spotify: { spotify: {
type: 'array',
items: {
type: 'object', type: 'object',
required: ['name', 'client_id', 'client_secret', 'redirect_uri', 'scrobblers'], required: ['name', 'client_id', 'client_secret', 'redirect_uri', 'scrobblers'],
properties: { properties: {
@ -125,6 +133,7 @@ const schema = {
minItems: 1 minItems: 1
} }
} }
}
}, },
web: { web: {

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": "",