Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for the headless PlexAmp client #593

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: "2"

volumes:
spotifycache:
plex_settings:

services:
# Core services
Expand Down Expand Up @@ -72,3 +73,13 @@ services:
io.balena.features.supervisor-api: 1
environment:
SET_HOSTNAME: balena

plex:
build: ./plugins/plex
restart: on-failure
privileged: true
network_mode: host
ports:
- 32500:32500
volumes:
- plex_settings:/root/.local/share/Plexamp
12 changes: 12 additions & 0 deletions docs/04-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ Spotify Connect requires a premium account. There is two methods of authenticati

Manual authentication will let you stream audio over the internet from a client that is on a different network than the balenaSound device. This is useful if your balenaSound device is on a separate WiFi network that's harder to reach (e.g. a backyard network).

### Plexamp

The headless Plexamp plugin allows for casting to the fleet from the Plex(amp) mobile/desktop/web apps. A Plex Pass is required to use this plugin.

You need to log in before using this plugin, to do that, make sure the plugin has started and spawn a terminal into the container.
Once you have a terminal, run the following command:
```bash
bash login.sh
```
Plexamp will prompt you for a claim token from [plex.tv/claim](https://www.plex.tv/claim/) and a player name, this name is the name that will show in the Plex(amp) app.
Once you have logged in and set a player name, you can exit out of the terminal (you may need to press control+c if plex starts) and restart the Plexamp plugin.

## Installable

The following plugins are available to be added to your balenaSound installation:
Expand Down
16 changes: 16 additions & 0 deletions plugins/plex/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM balenalib/%%BALENA_MACHINE_NAME%%-node:16.18.1


RUN install_packages wget bzip2 jq

# Audio block setup
ENV PULSE_SERVER=tcp:localhost:4317
RUN curl -sL https://raw.githubusercontent.com/balenablocks/audio/master/scripts/alsa-bridge/debian-setup.sh | bash -s y

WORKDIR /opt/plexamp
ADD *.sh /opt/plexamp/

RUN chmod +x start.sh
RUN chmod +x plexamp-setup.sh && ./plexamp-setup.sh

ENTRYPOINT /opt/plexamp/start.sh
11 changes: 11 additions & 0 deletions plugins/plex/login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if [[ -f "/root/.local/share/Plexamp/Settings/%40Plexamp%3Auser%3Atoken" ]]; then
echo "Plexamp appears to be already configured, skipping..."
exit 1
fi

echo "When prompted, enter your claim token from https://plex.tv/claim"
echo "Plexamp should exit after entering your claim token and player name, if it doesnt press control+c. After exiting, you can restart this container and exit the terminal."

cd /opt/plexamp/plexamp/

node js/index.js
12 changes: 12 additions & 0 deletions plugins/plex/plexamp-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version_info=$(curl https://plexamp.plex.tv/headless/version.json)

latest_version_number=$(echo $version_info | jq --raw-output '.latestVersion')
latest_version_url=$(echo $version_info | jq --raw-output '.updateUrl')

echo "Downloading PlexAmp version '$latest_version_number' from '$latest_version_url'"

wget "$latest_version_url" -O "plexamp.tar.bz2"

tar -xf plexamp.tar.bz2


24 changes: 24 additions & 0 deletions plugins/plex/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

if [[ -n "$SOUND_DISABLE_PLEX" ]]; then
echo "Plex is disabled, exiting..."
exit 0
fi

if [[ ! -f "/root/.local/share/Plexamp/Settings/%40Plexamp%3Auser%3Atoken" ]]; then
echo "__________________________________________WARNING__________________________________________________"
echo "| Plex is not configured! |"
echo "| Please enter a shell into the Plex container and run `bash login.sh` to setup your credentials! |"
echo "|_________________________________________________________________________________________________|"
echo ""
echo "Note: This is likely to change as headless Plexamp versions are released with new features."
echo " Passing a claim token via a command line argument has been suggested, we will have to see."
sleep 120
exit 1
fi

echo "Starting Plex plugin..."

cd /opt/plexamp/plexamp/

node js/index.js
Loading