Last active
July 30, 2019 13:21
-
-
Save kirkegaard/5f1961ed0c7a1e101cb1b538e8717f3f to your computer and use it in GitHub Desktop.
Displays the current streams on plex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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