Skip to content

Instantly share code, notes, and snippets.

@kirkegaard kirkegaard/
Last active Jul 30, 2019

What would you like to do?
Displays the current streams on plex
PLEX_TOKEN=$(curl -H "Content-Length: 0" -H "X-Plex-Client-Identifier: my-app" -u $PLEX_USERNAME:$PLEX_PASSWORD -X POST --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}"
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.