Skip to content

Instantly share code, notes, and snippets.

@kirkegaard kirkegaard/plex-streams.sh
Last active Jul 30, 2019

Embed
What would you like to do?
Displays the current streams on plex
#!/bin/sh
PLEX_TOKEN=$(curl -H "Content-Length: 0" -H "X-Plex-Client-Identifier: my-app" -u $PLEX_USERNAME:$PLEX_PASSWORD -X POST https://my.plexapp.com/users/sign_in.xml --silent | xmllint --xpath "/user/authentication-token/text()" -)
XML=$(curl --silent http://$PLEX_HOST:32400/status/sessions -H "X-Plex-Token: $PLEX_TOKEN")
STREAMS=$(echo $XML | xmllint --xpath 'string(//MediaContainer/@size)' -)
echo "Current streams: ${STREAMS}"
for (( i=1; i <= $STREAMS; i++ )); do
USER=$(echo $XML | xmllint --xpath 'string(//Video['$i']/User/@title)' -)
GRANDTITLE=$(echo $XML | xmllint --xpath 'string(//Video['$i']/@grandparentTitle)' -)
TITLE=$(echo $XML | xmllint --xpath 'string(//Video['$i']/@title)' -)
[ -z "$GRANDTITLE" ] && echo "${USER}: ${TITLE}" || echo "${USER}: ${GRANDTITLE} - ${TITLE}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.