What’s the proper way to get now playing sessions from command line? I used to do curl localhost:32400/status/sessions but I get unauthorized, even with the username password option.
I would like to know this info as well. I can’t find it anywhere.
I am attempting to get this service to work.
collindelker.com/wp/2016/10/plex-linux-prevent-sleep-take2/
After a bit of searching I found a solution.
The correct url is:
http://localhost:32400/status/sessions?X-Plex-Token=<myPlex User token>
You can get “myPlex User token” by executing the following command:
curl -H "Content-Length: 0" -H "X-Plex-Client-Identifier: my-app" -u <user>:<password> -X POST https://my.plexapp.com/users/sign_in.xml
Replace <user> and <password> with your plex username and password.
Found this very helpful info, and here is what I came up with:
This script relies on curl and xmllint
Created a script named get-active-streams with the following content:
#! /bin/sh
PLEX_HOST=${PLEX_HOST:-localhost}
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()" -)
curl --silent http://$PLEX_HOST:32400/status/sessions -H "X-Plex-Token: $PLEX_TOKEN" | xmllint --xpath 'string(//MediaContainer/@size)' -
don’t forget to chmod the file with u+x: chmod ./get-active-streams
and the you can run it like this:
PLEX_USERNAME="<username>" PLEX_PASSWORD="<password>" ./get-active-streams
In case you run this remotely you’ll need to also update the PLEX_HOST variable:
PLEX_HOST="<plex hostname/ip>" PLEX_USERNAME="<username>" PLEX_PASSWORD="<password>" ./get-active-streams
Hope this helps out to anyone trying to figure this out.