Cli based tool that assists with collecting client id's for the various devices of a given plex user/account.
Going down the rabbit hole of various automations Plex Webhooks has to offer, I came across webhooks-notifications. The installation steps included getting an auth token via POST request to their API as well as another GET request to fetch the clients under your account.
There were various posts on this forum of people showing their methods of gathering this information; however, the website isn't designed for code/snippet sharing. This caused problems for me with fancy quote, not being completely certain the keys vs the values in the example requests given, etc. So, whats better than just writing one out myself?
Initially I thought that it would be as easy as doing it all in a single curl - which I wasn't wrong about:
$ curl https://plex.tv/api/resources.xml?auth_token=$(curl -sX POST https://plex.tv/users/sign_in.json -u $USER:$PASS -H "X-Plex-Client-Identifier: da token" -H "X-Plex-Product: some more" -H "X-Plex-Version: 0.001" | jq -r .[].'authToken')
Seeing the XML dumped out into my terminal session made it super hard to visually parse out where the clientIdentifier
was and if it was the right device.
This tool, will parse though all that and make it nice and neat with the following output:
Device name: ServerName1
product: Plex Media Server
platform: Windows
clientIdentifier: <client-id-placeholder>
createdAt: 2019-09-25 18:11:49
lastSeenAt: 2020-02-17 14:39:18
Device name: AFTT
product: Plex for Android (TV)
platform: Android
clientIdentifier: <client-id-placeholder>
createdAt: 2018-07-11 16:47:48
lastSeenAt: 2020-02-16 16:28:59
Device name: Philip’s iPhone
product: Plex for iOS
platform: iOS
clientIdentifier: <client-id-placeholder>
createdAt: 2019-01-07 23:13:53
lastSeenAt: 2020-02-17 17:08:56
So, this tool will do the following for you:
- Prompt you for your Plex username/password
- Store your Plex username/password in your keyring
- Get Plex API auth token
- Get client XML and parse to be readable.
This script is made simple enough, that the only optional thing is the verbosity - which prints the response from the Plex API + your API token.
$ python3 ./plex_client_identifier.py --help
Usage: plex_client_identifier.py [OPTIONS]
Main entry point for python Plex client identifier.
:param: verbose: bool, print more verbose details
Options:
-v, --verbose
--help Show this message and exit.