Plex Media Scanner commandline help

This is a repost of: https://forums.plex.tv/topic/127924-plex-media-scanner-commandline-directory-parameter/

 

The unwashed masses and my epic google searches has not brought me closer to an answer, and a buddy suggested I went to the oracle atop mount whatsitsname in Greece. Due to the economic crisis in parts of europe and bad weather, I texted the oracle instead and I was pointed to this holy place of plex-nin-jit-su-do-kan. Senseis (plural ?), I present my question humbly:

 

Hi. I'm an avid plex user, and have amassed quite a library. I run up against a remote server, with a bunch of external scripting and stuff going on.
 
I can do most everything I want with plex, yet 1 thing escapes me.
 
For sake of argument, lets say this server is on hardware where I want to spend as few cpu cycles as possible. And harddrive IO. I upload a movie-file, lets call it Very.Old.Movie.Which.Is.Now.Public.Domain.1901.mkv. You can also call it Avatar.bootleg.year.mkv. Or LoTR.personal.rip.from.bluray.1990.mkv. Or whatever.
 
Once this upload is done, which might take a long time and done via script, I wish to call Plex Media Scanner and tell it new media has arrived, please scan and retrieve metadata.
 
If I do it like this:

sudo su - plex
 
export LD_LIBRARY_PATH="/usr/lib/plexmediaserver"
export LANG="en_US.UTF-8"
export PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS="6"
export PLEX_MEDIA_SERVER_TMPDIR="/tmp"
export PLEX_MEDIA_SERVER_HOME="/usr/lib/plexmediaserver"
export PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR="/var/lib/plexmediaserver/Library/Application Support"
/usr/lib/plexmediaserver/Plex\ Media\ Scanner --scan --refresh --section 1

 

 

 
Then I get a full scan of section 1, which happens to be the movies section and all is well.
However, again for sake of argument, lets say there are 1.000.000 movies in the movies section, and 1000 are added every day, that's a lot of scans and cpu cycles and such being spent.
if I do --help on the media scanner, I get an option to do single item, but that requires the movie to be in the database already to have an item ID. I also get 2 other options, --directory and --file. Now these seem to be able to help me accomplish this task, however, I cannot make it work. The correct syntax or use of these options escape my grasp at every turn. I either get nothing done, or I get a full scan of either a section or all sections.
 
 
Does anyone happen to be familiar with these options and know how to make them work or even if they can do what I want them to do: run a scan against this single file or directory, add content found to database and download metadata ?

 

 

I humbly await any assistance you might be able to offer.

My continued search has led me to several other threads of people requesting this feature or looking for it.

https://forums.plex.tv/topic/19303-command-line-for-plex-media-scanner/

That as an example.

From these, I have read comments and come to the conclusion that --file and --directory was added to the scanner but never finished in funtion. They are left there in a semicomplete state. I don't code my self, but when watching the scanner at work scanning a section in the logs, it seems it looks through a library for new files to add, and often finds maybe 1-2 new files and once it's done scanning the other 182.000 folders, it starts the process of downloading metadata and such. If I may be so bold, it does look like a very small change to add a command to scan a library and then just ignore everything BUT the complete path to the new episode or movie supplies as an argument to the scanner.

This will naturally not find and remove any files that are no longer present in the library, but in a cloud environment where you conserve cpu cycles and disk read/writes, such a full scan could be scheduled to run once a month instead of every night.

Not everyone has a local filesystem with filesystem events, we are actually quite a few who have discovered NAS devices, cloud services or other technologies.

P.S I'm not criticizing anyone or anything, I just have an invested interest in this functionality. English is furthermore my second language, so I apologize if I have offended anyone.

Thanks for the reminder.  I forget to test this, but in another post someone mentioned that they got the --file or --directory option working but you also had to include the --section keyword.  I guess that makes sense as you could have the same directory in more than one section so you need to be more specific on which directory or file to scan.

Ok.  finally got around to testing this and yes the --directory keyword does work, but you need to specify the section as well.

"Plex Media Scanner.exe" --scan --refresh --section ## --directory "full path to folder"

I cannot get the file option to work.  Everything I try gives me an error.  I am thinking that the file option is not meant for scanning 1 file, but maybe for indexing, which I did not try.

Ok.  finally got around to testing this and yes the --directory keyword does work, but you need to specify the section as well.

"Plex Media Scanner.exe" --scan --refresh --section ## --directory "full path to folder"

I cannot get the file option to work.  Everything I try gives me an error.  I am thinking that the file option is not meant for scanning 1 file, but maybe for indexing, which I did not try.

I played around with your solution, and it seems to do the trick - however, it also refreshes other stuff in the same directory which has some metadata missing I think.

root@DF64:/scripts# ./mtest.sh
GUI: Scanning Edge of Tomorrow (2014)
 * Refreshing Nature Irelands Wild River
GUI: Matching 'Nature Irelands Wild River'
GUI: Requesting metadata for 'Nature Irelands Wild River'
root@DF64:/scripts#
 
mtest.sh scans the folder /movies/Edge.of.tomorrow with edge.of.tomorrow.2014.mkv in it. That nature thing might just be a fluke, but I believe you hit the right syntax. I think in testing it myself, I have done the same, but a that test, it must have done a refresh of loads more and so I discarded that as not working.
 
I'll mark this as replied, and will play around with it in my scripts more.
 
You da man!

It takes about 25-45 seconds to do a scan with this option in my tv-shows, and it works for the episode in question + refreshes metadata for about 6-7 other episodes - same ones each time.

I'm gonna label those as problem eps, and check naming or whatever - perhaps remove them and readd them.

If you don't mind, I'll quote your answer out in the general public, so others may benefit from this if they have this need.

After finding this thread the other day I was able to verify that I can scan my music sections by directory which is something I’ve wanted to be able to do for a very long time. This will really be a tremendous time saver for me.

After playing around with adding some registry keys to my windows registry I have managed to add a shell extension to allow me to right click on a folder to scan it to either my Movies, TV or Music sections. All three options show up on any folder in my file system but I eventually plan on making it so only the appropriate option is available and only when browning a folder that is actually located within a library section. For now I’m just happy to have a quick way to scan any folder into any of the three sections.

I exported the registry keys into a file called PlexMediaScannerShellExtension.reg and the code is as follows:


Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\PMS.1MovieScan.1ScanFolderTree]
@=“PMS Scan Folder to Movies”

[HKEY_CLASSES_ROOT\Directory\shell\PMS.1MovieScan.1ScanFolderTree\command]
@="“C:\\Program Files\\Plex\\Plex Media Server\\Plex Media Scanner.exe” --verbose --section 20 --scan --refresh --directory “%1"”

[HKEY_CLASSES_ROOT\Directory\shell\PMS.2TVShowScan.1ScanFolderTree]
@=“PMS Scan Folder to TV Shows”

[HKEY_CLASSES_ROOT\Directory\shell\PMS.2TVShowScan.1ScanFolderTree\command]
@="“C:\\Program Files\\Plex\\Plex Media Server\\Plex Media Scanner.exe” --verbose --section 1 --scan --refresh --directory “%1"”

[HKEY_CLASSES_ROOT\Directory\shell\PMS.3Music.1ScanFolderTree]
@=“PMS Scan Folder to Music”

[HKEY_CLASSES_ROOT\Directory\shell\PMS.3Music.1ScanFolderTree\command]
@="“C:\\Program Files\\Plex\\Plex Media Server\\Plex Media Scanner.exe” --verbose --section 35 --scan --refresh --directory “%1"”


Just save it to a .reg file and be sure to change the section numbers to match what you have on your system. And remember it won’t work if your try to scan a folder not actually located within the library section’s folder structure.

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