Skip to content

Instantly share code, notes, and snippets.

@kirkegaard
Last active July 30, 2019 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirkegaard/5f1961ed0c7a1e101cb1b538e8717f3f to your computer and use it in GitHub Desktop.
Save kirkegaard/5f1961ed0c7a1e101cb1b538e8717f3f to your computer and use it in GitHub Desktop.
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