I try to automate as much as I can regarding my Plex Media server. My Plex backup process is completely automated, which makes one less thing I need to think about regarding my Plex server. Another thing I have automated is having my libraries automatically scanned when I add media to my server.
While Plex does include options to automatically run scans, including partial scans, I prefer to manage this aspect of my server. Of course, if you prefer you can leave it up to Plex and ignore what I am about to describe to you below.
If you would like to understand how you can automatically have Plex scan your libraries on changes or are just curious, you can find out how I do it in the next section.
Automatically scan a library when media is added or changed
The process I use to have Plex automatically scan when changes are detected is simple but does involve another application outside of Plex. The next few sections outline the entire process that I am using.
Monitoring for changes
The process of having Plex automatically scan my libraries is very simple and requires nothing more than a single, open source, application that I developed called FileWatcher.
FileWatcher is simply a file and folder monitor that runs on my Windows server as a service. It monitors changes to folders that I specify in the config file, and when a change is detected, it performs specific actions.
I use FileWatcher in my Plex backup process to automate generating file hashes.
In my case, however, I only want Plex to scan the folder containing the changed media items. To do this I have FileWatcher call the partial scan API to only scan the folder with changes.
I will show you how I have FileWatcher call the Plex API below.
Scanning for changes
When you have Plex scan your library, you must always ensure you following the correct naming conventions. If you are unsure of the naming conventions for media files, you can use the following links for more information:
When you are sure your media follows the naming conventions, then you can set FileWatcher to monitor your Plex media folders for changes, and then call the Plex partial scan API to automatically have the media items show up in your Plex server.
To do this, you will need to edit the FileWatcher config file. An example of my config file that will monitor my movies media folder and scan for changes in that folder is below:
<watches> <watch> <path>M:\Media\Movies</path> <notifications> <notification> <triggers> <trigger>Create</trigger> <trigger>Change</trigger> </triggers> <method>GET</method> <url>[env:plex_url]/library/sections/2/refresh?path=[urlenc:M:\Media\Movies\[path]]&X-Plex-Token=[env:plex_token]</url> </notification> </notifications> </watch> </watches>
The config file may seem complex, but these are the settings:
- This is the full path to my Plex media folder. In my example, it is the full path to my movies library folder.
- This outlines that I would like to send a request to an endpoint. In this case, I will be sending a request to my Plex server to perform a partial scan.
- This determines what changes will need to happen to send the request. The notifications will be sent out when a file is created or changed.
- This is the method used to send the request. The Plex API information indicates the Plex partial scan is sent using the GET method.
- This is the URL to use for the Plex partial scan. This can be found in the Plex API documentation. The values starting with
[env:<value>]indicate an environment variable. So the
plex_tokenare environment variables containing the Plex URL of my server, and the Plex token, respectively. The
[urlenc:<value>]will URL-encode the value to send to the Plex server. The
[path]placeholder will be replaced with the path of the changed movie item.
I have a separate watch for each media folder on my Plex server. They are all similar, but the paths and the section ID are different between each of the watches.
As I mentioned earlier, FileWatcher is running as a service on my Windows server, so it is constantly monitoring my folders. Once a change is detected, a Plex partial scan is run and the media items appear on my Plex server.
Of course, if I prefer I can still run a scan using the Plex Web app at any time.