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.
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.
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 .
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.
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}')
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.
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?
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.
As an alternative you can bypass the need for authentication for local IPs.
Under your plex servers settings → network → List 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.