Plex Media Scanner via Command Line

Introduction

There are a number of commands that can be used to control the Plex Media Scanner via the command line. This can be used to initiate scans, refresh metadata, generate video preview thumbnails (media index files), or more.

The general method to use this is:

/path/to/Plex\ Media\ Scanner --command

To see a list of available options and arguments:

/path/to/Plex\ Media\ Scanner --help 

That outputs help information:

Plex Media Scanner (c) 2010-2014 Plex Development Team.

  -h, --help           Display this message.
  -v, --verbose        Show more output.
  -p, --progress       Show special progress output.
  --log-file-suffix    Specify suffix for log file.

 Actions:

  -r, --refresh        Refresh the metadata.
  -a, --analyze        Analyze media information.
  --analyze-deeply     Fully read and perform deep media analysis.
  -b, --index          Generate a media index file.
  -s, --scan           Scan for new media.
  -i, --info           Get information.
  -l, --list           List.
  -g, --generate       Regenerate thumbnails/fanart.
  -t, --tree           Show a section tree.
  -w, --reset          Delete all media out of a section.
  -n, --add-section  --type <type:1,2,8> --agent  --location  --lang  Add a new section.
  -D, --del-section    Delete a section.

 Items to which actions apply:

  -c, --section        A library section ID.
  -o, --item           An item ID.
  -d, --directory      A directory path.
  -f, --file           A file.

 Modifiers to actions:

  -x, --force          Force an operation (e.g. refresh).
  --no-thumbs          Do not regenerate thumbs when analyzing.
  --chapter-thumbs-only   Only generate chapter thumbnails during generate pass
  --thumbOffset  Percent offset into video for thumbnail image generated during media analysis.
  --artOffset    Percent offset into video for fanart image generated during media analysis.

For most things you'll do here, you need to establish at least:

  • The Section ID
  • The action to take

Sample Commands

List the Library Sections

To list the Library sections currently defined on the Plex Media Server:

/path/to/Plex\ Media\ Scanner --list

This returns a list of Libraries and their ID:

/path/to/Plex\ Media\ Scanner --list
   29: Movies
   31: Music
   30: TV Shows

List the items in a Library

To list the media items contained in a Library section:

/path/to/Plex\ Media\ Scanner --tree --section 29
* A Bug's Life [1998]
   * /Users/exampleuser/Movies/Media/Movies/A Bug's Life (1998).mkv
* Cars [2006]
   * /Users/exampleuser/Movies/Media/Movies/Cars (2006).mkv
* Enchanted [2007]
   * /Users/exampleuser/Movies/Media/Movies/Enchanted (2007).mkv
...

Scan & Refresh a Library

You can perform the same thing that occurs when you just press the Refresh button in the Media Manager, which is to do a scan and then refresh metadata for any new items:

  • Determine the Section ID to scan
  • For example, the Movies Library above has an ID=29
/path/to/Plex\ Media\ Scanner --scan --refresh --section 29

Refreshing an Entire Library

You can perform the same thing that occurs when you choose to "Refresh All" in the Plex Web App, which is to Refresh metadata for all items in the library:

  • Determine the Section ID to scan
  • For example, the Movies Library above has an ID=29
/path/to/Plex\ Media\ Scanner --scan --refresh --force --section 29

Examples

Windows

In Windows, you perform these from the Command Prompt.

Tip!: You can drag-drop the "Plex Media Scanner.exe" file into your command prompt window to have the full path and filename automatically inserted.

Recreate the thumbnail and fanart images that get generated for media:

"C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe" --generate --section 2

Perform analysis on two items (with Item IDs 21 and 22):

"C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Scanner.exe" -- analyze --item 21,22

OS X

In OS X, you perform these from the Terminal. You can also create an alias for convenience. You need to create the alias at the beginning of every Terminal session to use it. From the Terminal prompt, run:

alias pms="/Applications/Plex\ Media\ Server.app/Contents/MacOS/Plex\ Media\ Scanner"

Refresh the entire Library section 12:

pms --scan --refresh --force --section 12

Generate video preview thumbnails for Item ID 147:

pms --index --item 147

Linux

Note: Specific paths on Linux systems will likely vary depending on the distribution or NAS.

You'll first need to define stuff in your environment at the beginning of each session:

export LD_LIBRARY_PATH=/usr/lib/plexmediaserver

Manually refresh a single item with Item ID 42:

/usr/lib/plexmediaserver/Plex\ Media\ Scanner --refresh --force --item 42