diff --git a/.gitignore b/.gitignore index dc90221..747051b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ config/* !config/configuration.js !config.schema.js credentials.* -config*.yml \ No newline at end of file +*.yml \ No newline at end of file diff --git a/app.js b/app.js index d7aabb4..bbcf2ad 100644 --- a/app.js +++ b/app.js @@ -10,11 +10,16 @@ const Recorder = require("./services/recorder"); const MalojaScrobbler = require("./services/scrobblers/maloja-scrobbler"); -const maloja = new MalojaScrobbler(config.maloja, logger); -const spotify = new SpotifyTracker(config.spotify); -(async () => await spotify.loadCredentials())(); -const plex = new PlexTracker(config.plex); -const recorder = new Recorder(sessions, [plex, spotify], [maloja], config.scrobble, logger); +let trackers = [] +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())(); + +const scrobblers = config.maloja.map(config => new MalojaScrobbler(config, logger)); +const recorder = new Recorder(sessions, trackers, scrobblers, config.scrobble, logger); setInterval(() => recorder.record(), 5000); diff --git a/config/config.schema.js b/config/config.schema.js index 090ecd0..32b661e 100644 --- a/config/config.schema.js +++ b/config/config.schema.js @@ -3,83 +3,89 @@ const schema = { required: [], properties: { maloja: { - type: 'object', - required: ['name', 'url', 'token'], - properties: { - name: { - type: 'string' - }, - url: { - type: 'string' - }, - token: { - type: 'string' - }, + type: 'array', + items: { + type: 'object', + required: ['name', 'url', 'token'], + properties: { + name: { + type: 'string' + }, + url: { + type: 'string' + }, + token: { + type: 'string' + }, + } } }, plex: { - type: 'object', - required: ['name', 'url', 'token', 'scrobblers'], - properties: { - name: { - type: 'string' - }, - 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: 'array', + items: { + type: 'object', + required: ['name', 'url', 'token', 'scrobblers'], + properties: { + name: { 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: { - type: 'object', - required: ['name', 'client_id', 'client_secret', 'redirect_uri', 'scrobblers'], - properties: { - name: { - type: 'string' - }, - client_id: { - type: 'string' - }, - client_secret: { - type: 'string' - }, - redirect_uri: { - type: 'string' - }, - scrobblers: { - type: 'array', - items: { + type: 'array', + items: { + type: 'object', + required: ['name', 'client_id', 'client_secret', 'redirect_uri', 'scrobblers'], + properties: { + name: { type: 'string' }, - minItems: 1 + client_id: { + type: 'string' + }, + client_secret: { + type: 'string' + }, + redirect_uri: { + type: 'string' + }, + scrobblers: { + type: 'array', + items: { + type: 'string' + }, + minItems: 1 + } } } },