From f6fc7ab920253faa3e89037a21f9910dada139f7 Mon Sep 17 00:00:00 2001 From: Simon J Date: Sat, 22 Apr 2023 10:54:38 +1000 Subject: [PATCH] Ability to disable album art for playlists (#159) --- .devcontainer/Dockerfile | 1 + .devcontainer/devcontainer.json | 6 +++ README.md | 1 + package.json | 6 +-- src/smapi.ts | 3 ++ tests/smapi.test.ts | 66 +++++++++++++++++++++------------ 6 files changed, 57 insertions(+), 26 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 921b66a..cb55b0f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,6 +3,7 @@ FROM node:16-bullseye LABEL maintainer=simojenki ENV JEST_TIMEOUT=60000 +EXPOSE 4534 RUN apt-get update && \ apt-get -y upgrade && \ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 50ac64a..4ac7bbc 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,6 +3,12 @@ "build": { "dockerfile": "Dockerfile" }, + "containerEnv": { + // these env vars need to be configured appropriately for your local dev env + "BNB_DEV_SONOS_DEVICE_IP": "${localEnv:BNB_DEV_SONOS_DEVICE_IP}", + "BNB_DEV_HOST_IP": "${localEnv:BNB_DEV_HOST_IP}", + "BNB_DEV_SUBSONIC_URL": "${localEnv:BNB_DEV_SUBSONIC_URL}" + }, "remoteUser": "node", "features": { "ghcr.io/devcontainers/features/docker-in-docker:1": { diff --git a/README.md b/README.md index ad89ca0..f83fe7e 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,7 @@ BNB_URL | http://$(hostname):4534 | URL (including path) for bonob so that sonos BNB_SECRET | bonob | secret used for encrypting credentials BNB_AUTH_TIMEOUT | 1h | Timeout for the sonos auth token, described in the format [ms](https://github.com/vercel/ms), ie. '5s' == 5 seconds, '11h' == 11 hours. In the case of using Navidrome this should be less than the value for ND_SESSIONTIMEOUT BNB_LOG_LEVEL | info | Log level. One of ['debug', 'info', 'warn', 'error'] +BNB_DISABLE_PLAYLIST_ART | undefined | Disables playlist art generation, ie. when there are many playlists and art generation takes too long BNB_SERVER_LOG_REQUESTS | false | Whether or not to log http requests BNB_SONOS_AUTO_REGISTER | false | Whether or not to try and auto-register on startup BNB_SONOS_DEVICE_DISCOVERY | true | Enable/Disable sonos device discovery entirely. Setting this to 'false' will disable sonos device search, regardless of whether a seed host is specified. diff --git a/package.json b/package.json index 4bceb2f..afa80e7 100644 --- a/package.json +++ b/package.json @@ -62,9 +62,9 @@ "scripts": { "clean": "rm -Rf build node_modules", "build": "tsc", - "dev": "BNB_LOG_LEVEL=debug BNB_DEBUG=true BNB_SCROBBLE_TRACKS=false BNB_REPORT_NOW_PLAYING=false BNB_ICON_FOREGROUND_COLOR=white BNB_ICON_BACKGROUND_COLOR=darkgrey BNB_SONOS_SERVICE_NAME=bonobDev BNB_SONOS_DEVICE_DISCOVERY=true nodemon -V ./src/app.ts", - "devr": "BNB_LOG_LEVEL=debug BNB_DEBUG=true BNB_SCROBBLE_TRACKS=false BNB_REPORT_NOW_PLAYING=false BNB_ICON_FOREGROUND_COLOR=white BNB_ICON_BACKGROUND_COLOR=darkgrey BNB_SONOS_SERVICE_NAME=bonobDev BNB_SONOS_DEVICE_DISCOVERY=true BNB_SONOS_AUTO_REGISTER=true nodemon -V ./src/app.ts", - "register-dev": "ts-node ./src/register.ts http://$(hostname):4534", + "dev": "BNB_LOG_LEVEL=debug BNB_DEBUG=true BNB_SCROBBLE_TRACKS=false BNB_REPORT_NOW_PLAYING=false BNB_ICON_FOREGROUND_COLOR=white BNB_ICON_BACKGROUND_COLOR=darkgrey BNB_SONOS_SEED_HOST=$BNB_DEV_SONOS_DEVICE_IP BNB_SONOS_SERVICE_NAME=z_bonobDev BNB_SONOS_DEVICE_DISCOVERY=true BNB_URL=\"http://${BNB_DEV_HOST_IP}:4534\" BNB_SUBSONIC_URL=\"${BNB_DEV_SUBSONIC_URL}\" nodemon -V ./src/app.ts", + "devr": "BNB_DISABLE_PLAYLIST_ART=true BNB_LOG_LEVEL=debug BNB_DEBUG=true BNB_SCROBBLE_TRACKS=false BNB_REPORT_NOW_PLAYING=false BNB_ICON_FOREGROUND_COLOR=white BNB_ICON_BACKGROUND_COLOR=darkgrey BNB_SONOS_SEED_HOST=$BNB_DEV_SONOS_DEVICE_IP BNB_SONOS_SERVICE_NAME=z_bonobDev BNB_SONOS_DEVICE_DISCOVERY=true BNB_SONOS_AUTO_REGISTER=true BNB_URL=\"http://${BNB_DEV_HOST_IP}:4534\" BNB_SUBSONIC_URL=\"${BNB_DEV_SUBSONIC_URL}\" nodemon -V ./src/app.ts", + "register-dev": "ts-node ./src/register.ts http://${BNB_DEV_HOST_IP}:4534", "test": "jest", "gitinfo": "git describe --tags > .gitinfo" }, diff --git a/src/smapi.ts b/src/smapi.ts index dcda846..6707dcb 100644 --- a/src/smapi.ts +++ b/src/smapi.ts @@ -266,6 +266,9 @@ export const playlistAlbumArtURL = ( bonobUrl: URLBuilder, playlist: Playlist ) => { + // todo: this should be put into config, or even just removed for the ND music source + if(process.env["BNB_DISABLE_PLAYLIST_ART"]) return iconArtURI(bonobUrl, "music"); + const burns: BUrn[] = uniq( playlist.entries.filter((it) => it.coverArt != undefined), (it) => it.album.id diff --git a/tests/smapi.test.ts b/tests/smapi.test.ts index e6b5dcc..b366b51 100644 --- a/tests/smapi.test.ts +++ b/tests/smapi.test.ts @@ -519,30 +519,30 @@ describe("playlistAlbumArtURL", () => { }); describe("when the playlist has external ids", () => { + const bonobUrl = url("http://localhost:1234/context-path?search=yes"); + const externalArt1 = { + system: "external", + resource: "http://example.com/image1.jpg", + }; + const externalArt2 = { + system: "external", + resource: "http://example.com/image2.jpg", + }; + + const playlist = aPlaylist({ + entries: [ + aTrack({ + coverArt: externalArt1, + album: anAlbumSummary({ id: "album1" }), + }), + aTrack({ + coverArt: externalArt2, + album: anAlbumSummary({ id: "album2" }), + }), + ], + }); + it("should format the url with encrypted urn", () => { - const bonobUrl = url("http://localhost:1234/context-path?search=yes"); - const externalArt1 = { - system: "external", - resource: "http://example.com/image1.jpg", - }; - const externalArt2 = { - system: "external", - resource: "http://example.com/image2.jpg", - }; - - const playlist = aPlaylist({ - entries: [ - aTrack({ - coverArt: externalArt1, - album: anAlbumSummary({ id: "album1" }), - }), - aTrack({ - coverArt: externalArt2, - album: anAlbumSummary({ id: "album2" }), - }), - ], - }); - expect(playlistAlbumArtURL(bonobUrl, playlist).href()).toEqual( `http://localhost:1234/context-path/art/${encodeURIComponent( formatForURL(externalArt1) @@ -550,6 +550,26 @@ describe("playlistAlbumArtURL", () => { formatForURL(externalArt2) )}/size/180?search=yes` ); + }); + + describe("when BNB_NO_PLAYLIST_ART is set", () => { + const OLD_ENV = process.env; + + beforeEach(() => { + process.env = { ...OLD_ENV }; + + process.env["BNB_DISABLE_PLAYLIST_ART"] = "true"; + }); + + afterEach(() => { + process.env = OLD_ENV; + }); + + it("should return an icon", () => { + expect(playlistAlbumArtURL(bonobUrl, playlist).href()).toEqual( + `http://localhost:1234/context-path/icon/music/size/legacy?search=yes` + ); + }); }); });