Home

Awesome

Plex Media Tagger

Tested on macOS Catalina (10.15.1)

thanks goes to:
the Plex team, their PMS takes care of all the hard work of gathering the metadata and providing an intuitive web API to browse the local library.
the Subler team, their CLI tool takes care of the actual embedding and reading of the information.

Installation:

Either:

The tool requires python (pre-installed on most versions of Mac OS X and linux). I have tested it with Python v2.7.2 for windows. If you want pretty colors for the output, you might also have to download and install the ctypes module for python (it says it's included, but didn't seem to be with v2.7.2).

Note: Embedding metadata in files only works on OS X, as it uses a tool that unfortunately only is available for that system. Exporting of resources (subtitles, artwork, etc) and statistics gathering should work fine on both unix, linux and windows.

Usage:

	Usage: plexmediatagger.py [options]
	Example 1: plexmediatagger.py --tag
	Example 2: plexmediatagger.py --tag -b --username='foo@bar.com' --interactive-password
		tag everything in the library, and authenticate to Plex Home as user foo@bar.com with password being prompted for (password can also be supplied using the --password option)
	Example 3: plexmediatagger.py -bq --tag --remove-all-tags --optimize --export-subtitles --embed-subtitles -ip 192.168.0.2 --port 55400
	Example 4: plexmediatagger.py --subtitles -m 'D:\Movies' '/Volumes/Media/Movies' -m '\' '/'
	Example 5: plexmediatagger.py -tb --batch-mediatype=movie --batch-breadcrumb='kids>cars'
		only tag movies who are in a section containing the word 'kids' and movies who's name contains 'cars'
	Example 6: plexmediatagger.py -tb --batch-mediatype=show --batch-breadcrumb='>lost>season 1>pilot'
		only tag tv episodes, matches all sections, show name contains lost, season 1, episode title contains 'pilot'
	Example 7: plexmediatagger.py -tb --batch-breadcrumb='tv>weeds>>goat'
		only tag items who are in a section who's title contains 'tv', where the movie or show name contains 'weeds', any season and episode title contains 'goat' 

The tool uses the comment metadata field to store metadata that does not have its own tag, but is a value that iTunes stores in its internal database (such as rating and playcount). There is an iTunes script in the extra's folder that can load this information into iTunes, or you can try using the --add-to-itunes flag that will make sure the item being processed isn't already present in iTunes and it will add in the extra metadata for you. If you do want to do this step manually, add the newly tagged file to iTunes and select the corresponding entry in iTunes and run the script. This will load in that extra information that cannot be embedded directly.

Note: Filepaths to media items in PMS need to be the same as on machine that is running this script (can be worked around by using the -m option to modify the file path).

Options:

OptionDescription
-h, --helpshow this help message and exit
-t, --tagtag all compatible file types, and update any previously tagged files (if metadata in plex has changed)
--tag-updateupdate previously tagged files if the PMS entry has changed since last time (modification time)
--tag-tv-prefer-season-artworkwhen tagging tv show episodes, the season artwork will be used instead of the episode thumbnail
-r, --remove-tagsremove all compatible tags from the files
-f, --forceignore previous work and steam ahead with task (will re-tag previously tagged files, re-enters data into iTunes, etc.)
-o, --optimizeinterleave the audio and video samples, and put the "MooV" atom at the beginning of the file
--chapter-previewsgenerate preview images for any chapter markers
--export-subtitlesexport any subtitles to the same path as the video file
--embed-subtitlesembed compatible files with a compatible "sidecar" subtitle file if present
--export-artworkexport the artwork to the same path as the video file
--statsgather "interesting" statistics about the items being processed
-mperform a find & replace operation on the pms' media file paths (useful if you are running the script on a different machine than the one who is hosting the pms, i.e. the mount paths are different). Supply multiple times to perform several different replacements (operations are performed in order supplied).
--openopen a Finder window at the containing folder of the file just processed (Mac OS X only)
--add-to-itunesadds the item to TV if not already present
-i IP, --ip=IPspecify an alternate IP address that hosts a PMS to connect to (default is localhost)
-p PORT, --port=PORTspecify an alternate port number to use when connecting to the PMS (default is 32400)
--username=USERNAMEspecify the username to use when authenticating with the PMS (default is no authentication)
--password=PASSWORDspecify the password to use when authenticating with the PMS (default is no authentication)
--interactive-passwordthe password to use when authenticating with the PMS will be supplied interactively
--interactiveinteractivly select files to operate on [default]
-b, --batchdisable interactive mode. Requires no human intervention once launched, and will perform operations on all valid files
--batch-mediatype=[movie/show]only specified media type will be processed
--batch-breadcrumb=breadcrumbonly items matching the breadcrumb trail will be processed. Components seperated by '>' (case insensitive)
-v, --verboseincrease verbosity (can be supplied 0-2 times)
-q, --quietninja-like processing (can only be used when in batch mode)
-d, --dry-runpretend to do the job, but never actually change or export anything. Pretends that all tasks succeed. Useful for testing purposes