mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-22 01:43:29 +01:00
Ability to enable/disable reporting of now playing and scrobbling
This commit is contained in:
49
src/app.ts
49
src/app.ts
@@ -4,12 +4,13 @@ import { appendMimeTypeToClientFor, DEFAULT, Navidrome } from "./navidrome";
|
||||
import encryption from "./encryption";
|
||||
import { InMemoryAccessTokens, sha256 } from "./access_tokens";
|
||||
import { InMemoryLinkCodes } from "./link_codes";
|
||||
import config from "./config";
|
||||
import readConfig from "./config";
|
||||
import sonos, { bonobService } from "./sonos";
|
||||
import { MusicService } from "./music_service";
|
||||
|
||||
logger.info(
|
||||
`Starting bonob with config ${JSON.stringify(config)}`
|
||||
);
|
||||
const config = readConfig();
|
||||
|
||||
logger.info(`Starting bonob with config ${JSON.stringify(config)}`);
|
||||
|
||||
const bonob = bonobService(
|
||||
config.sonos.serviceName,
|
||||
@@ -20,17 +21,45 @@ const bonob = bonobService(
|
||||
|
||||
const sonosSystem = sonos(config.sonos.deviceDiscovery, config.sonos.seedHost);
|
||||
|
||||
const streamUserAgent = config.navidrome.customClientsFor ? appendMimeTypeToClientFor(config.navidrome.customClientsFor.split(",")) : DEFAULT;
|
||||
const streamUserAgent = config.navidrome.customClientsFor
|
||||
? appendMimeTypeToClientFor(config.navidrome.customClientsFor.split(","))
|
||||
: DEFAULT;
|
||||
|
||||
const navidrome = new Navidrome(
|
||||
config.navidrome.url,
|
||||
encryption(config.secret),
|
||||
streamUserAgent
|
||||
);
|
||||
|
||||
const featureFlagAwareMusicService: MusicService = {
|
||||
generateToken: navidrome.generateToken,
|
||||
login: (authToken: string) =>
|
||||
navidrome.login(authToken).then((library) => {
|
||||
return {
|
||||
...library,
|
||||
scrobble: (id: string) => {
|
||||
if (config.scrobbleTracks) return library.scrobble(id);
|
||||
else {
|
||||
logger.info("Track Scrobbling not enabled")
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
},
|
||||
nowPlaying: (id: string) => {
|
||||
if (config.reportNowPlaying) return library.nowPlaying(id);
|
||||
else {
|
||||
logger.info("Reporting track now playing not enabled");
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
},
|
||||
};
|
||||
}),
|
||||
};
|
||||
|
||||
const app = server(
|
||||
sonosSystem,
|
||||
bonob,
|
||||
config.webAddress,
|
||||
new Navidrome(
|
||||
config.navidrome.url,
|
||||
encryption(config.secret),
|
||||
streamUserAgent
|
||||
),
|
||||
featureFlagAwareMusicService,
|
||||
new InMemoryLinkCodes(),
|
||||
new InMemoryAccessTokens(sha256(config.secret))
|
||||
);
|
||||
|
||||
@@ -1,30 +1,36 @@
|
||||
import { hostname } from "os";
|
||||
import logger from "./logger";
|
||||
|
||||
const port = +(process.env["BONOB_PORT"] || 4534);
|
||||
const webAddress =
|
||||
export default function () {
|
||||
const port = +(process.env["BONOB_PORT"] || 4534);
|
||||
const webAddress =
|
||||
process.env["BONOB_WEB_ADDRESS"] || `http://${hostname()}:${port}`;
|
||||
|
||||
if (webAddress.match("localhost")) {
|
||||
logger.error("BONOB_WEB_ADDRESS containing localhost is almost certainly incorrect, sonos devices will not be able to communicate with bonob using localhost, please specify either public IP or DNS entry");
|
||||
if (webAddress.match("localhost")) {
|
||||
logger.error(
|
||||
"BONOB_WEB_ADDRESS containing localhost is almost certainly incorrect, sonos devices will not be able to communicate with bonob using localhost, please specify either public IP or DNS entry"
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
return {
|
||||
port,
|
||||
webAddress,
|
||||
secret: process.env["BONOB_SECRET"] || "bonob",
|
||||
sonos: {
|
||||
serviceName: process.env["BONOB_SONOS_SERVICE_NAME"] || "bonob",
|
||||
deviceDiscovery: (process.env["BONOB_SONOS_DEVICE_DISCOVERY"] || "true") == "true",
|
||||
seedHost: process.env["BONOB_SONOS_SEED_HOST"],
|
||||
autoRegister: process.env["BONOB_SONOS_AUTO_REGISTER"] == "true",
|
||||
sid: Number(process.env["BONOS_SONOS_SERVICE_ID"] || "246")
|
||||
serviceName: process.env["BONOB_SONOS_SERVICE_NAME"] || "bonob",
|
||||
deviceDiscovery:
|
||||
(process.env["BONOB_SONOS_DEVICE_DISCOVERY"] || "true") == "true",
|
||||
seedHost: process.env["BONOB_SONOS_SEED_HOST"],
|
||||
autoRegister: process.env["BONOB_SONOS_AUTO_REGISTER"] == "true",
|
||||
sid: Number(process.env["BONOS_SONOS_SERVICE_ID"] || "246"),
|
||||
},
|
||||
navidrome: {
|
||||
url: process.env["BONOB_NAVIDROME_URL"] || `http://${hostname()}:4533`,
|
||||
customClientsFor: process.env["BONOB_NAVIDROME_CUSTOM_CLIENTS"] || undefined,
|
||||
}
|
||||
url: process.env["BONOB_NAVIDROME_URL"] || `http://${hostname()}:4533`,
|
||||
customClientsFor:
|
||||
process.env["BONOB_NAVIDROME_CUSTOM_CLIENTS"] || undefined,
|
||||
},
|
||||
scrobbleTracks: (process.env["BONOB_SCROBBLE_TRACKS"] || "true") == "true",
|
||||
reportNowPlaying: (process.env["BONOB_REPORT_NOW_PLAYING"] || "true") == "true",
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user