Plex Media Scanner CLI Depricated Options in 1.28.1.6018 - Alternatives?

Noticed the scan (-s) , refresh (-r) and index (-b) features are deprecated in the CLI version of the Plex Media Scanner in 1.28.1.6018 beta release

Is there a new way to scan a single directory or file for an update? I have been using this to do directory updates when I add new files.

Running a full scan on my TV library takes 45 minutes - It used to only take 5-10 minutes but slowed down dramatically in a previous version and I’ve been using this as a workaround since.

1 Like

You should use the HTTP API.

If you’re using Python you can look at this unofficial project: GitHub - pkkid/python-plexapi: Python bindings for the Plex API. - specifically this call: plexapi.library — Python PlexAPI documentation

We will be updating our official documentation in due course to include the steps on how to do this, for now the CLI commands will still work but we’re marking it as deprecated as it will be removed at some point in the future and we would like to give you time to make changes if you’re using this in your workflow.

1 Like

Is it just the scan/refresh option that will be deprecated or the CLI all together ? IF cli is there a time frame for when this will happen ?

1 Like

Just the scan and refresh actions.

I’m used to calling both --scan and --refresh whenever new content is to be added to the library:

"%PlexPath%\Plex Media Server.exe" --scan --refresh --section %section% --directory "%path%"

Plex then scans the folder, identifying the new files, and fetches the metadata. Would the following be equivalent?

curl -H "X-Plex-Token: %token%" -H "path: %path%" %server_url%/library/sections/%section%/refresh

path is just a query param, not a header, so you should pass it (URL encoded) with the url e.g. http://127.0.0.1:32400/library/sections/1/refresh?path=UrlEncodedPath

Yep, as soon as I noticed the path had to be URL encoded I gave up on calling curl from the batch file and went for a few Python lines since it would give me more flexibility (found out later I didn’t have to, curl has a flag to encode parameter strings).

Most of my confusion then came from trying to send both path and force simultaneously to the endpoint, turns out they don’t really stack and the scanner would prioritize force and refresh the whole section, which was really unfortunate because not only there’s a lot of files but also many of them are RClone remotes, the very reason I disabled all filesystem monitoring and regular library folder checks in favor of this manual approach :sweat_smile:.

Other than that “minor” setback, I found out a simple /refresh?path=... does indeed both scan to library and fetch metadata, just like Plex Media Scanner --scan --refresh does.

For reference to anyone interested:

curl -G -H "X-Plex-Token: $TOKEN" --data-urlencode "path=$SCAN_PATH" http://localhost:32400/library/sections/$SECTION_ID/refresh
Now useless Python script
import requests
import sys

section = sys.argv[1] or input('Section ID: ')
path = sys.argv[2] or input('Path: ')
with open(f'{sys.path[0]}/token') as file:  # token is stored in a separate
    token = file.readline()                 # file on the script's folder
req = requests.get(
    f'http://localhost:32400/library/sections/{section}/refresh',
    params={'path': path},
    headers={'X-Plex-Token': token}
)
print('Success!' if req.status_code == 200 else f'Failed!\nHTTP Code {req.status_code}\n{req.text}')
1 Like

I created this script last night based on an example above and it works great. Just make sure you set the variables at the top of the script . Your token can be found by going to a library item, clicking get info, and then clicking view XML. An XML page will then load, and you’ll see your token at the end of the URL string in the address bar. As far as your section id and library paths go, you should know what to put here already.

#!/bin/bash
TOKEN=""
SCAN_PATH=/Path/To/Library/
SECTION_ID=YOUR_SECTION_ID
curl -G -H "X-Plex-Token: $TOKEN" --data-urlencode "path=$SCAN_PATH" http://localhost:32400/library/sections/$SECTION_ID/refresh

Alternatively, you could set the following at the end of ~/.profile and just change $TOKEN to $PLEX_TOKEN in the script. Then of course run this:

source ~/.profile

export PLEX_TOKEN=""
3 Likes

Thank you. Just confirming this worked for me. And appears to be much faster than the Plex Media Scanner command.

While my section_id’s are pretty static and can be hand coded. I am wondering if I should be using something other than “Plex\ Media\ Scanner --list” to obtain the section_id. Ideally, I would like to retrieve a list with section_id “library name” and the multiple paths for the given library. Any suggestions?

1 Like

Is there a rotate time on these auth tokens?

I really liked using the CLI because I could just run it as part of my workflow without any need for authentication or adding extra information anywhere (i.e., the auth token).

I understand not wanting to spend resources maintaining two different points for scanning/information, but this does kinda stink.

Apparently the token remains functional for as long as the device is authorized on the server

As an alternative you can bypass the need for authentication for local IPs.

Under your plex servers settingsnetworkList of IP addresses and networks that are allowed without auth you can add the ip of your device running your workflow.

Then just use this in your scripting (as you can see without token) and the plex server will accept the request.

curl -X PUT "http://<local plex server ip>:32400/library/sections/1/refresh?force=1"

The above example will force refresh the metadata for your library with id 1.

2 Likes

Exactly what I would have needed! Thanks a lot. Going to have to implement this into my workflow as scans have been failing…

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.