Plex Manage Collections is a simple script that will add genre collection tags to your media making it much easier to search for genre specific content.
- Requirements
- Compatible Setups
- Optional Features
- Getting Started
- Credits
- Auto-Run Whenever There's New Media
- Troubleshooting
- Docker Usage
- Python 3
- Python dependencies listed in
requirements.txt
(if you have pip, simply dopip install -r requirements.txt
). - TMDB Api Key (Only required for non-anime media)
For either setup, proper titles for your media are necessary. This makes it easier to find the media (see https://support.plex.tv/articles/naming-and-organizing-your-tv-show-files/).
- Anime shows and movies are in their own library on your plex server. (Anime shows and movies can share the same library)
- Standard TV Shows are in their own library on your plex server.
- Standard Movies are in their own library on your plex server.
In this setup, the script'll simply create genres collections for your media in each library (also with anime-specific genres for the anime libraries).
Note: this setup works well with ZeroQI's Absolute Series Scanner (ASS) and Hama.bundle agent.
- Anime and standard TV shows share their own library on your plex server.
- Anime and standard movies share their own library on your plex server.
In this setup, the script'll create three types of collections:
- Type of media: "Non-Anime" and "Anime" collections
- Standard genres: contain only standard media
- Anime genres: contain only anime and the collections' names are preceded by "[A]"
You may set poster arts to your collections like the ones in sample-posters/ (inspired by reddit's /u/alexnyc1998).
If you wish to use the provided arts, simply rename sample-posters/
to posters/
.
If you would like to create your own posters matching the provided style, you can use the template.psd file to create your own (requires Photoshop). When setting up your own poster, organize them in a posters/ directory like the provided ones are in the sample-posters/.
The directories must match the media type (movies, shows, anime). There can be also a directory titled "general", for the "Anime" and "Non-Anime" collections (see the Standard media and anime are mixed setup option). The posters' names must match the collections' names without any prefix (either PLEX_COLLECTION_PREFIX or the "[A]" for anime genres). The names must be completely lowercase and any spaces in it must be replaced by dashes (-).
Examples:
- If you have PLEX_COLLECTION_PREFIX="*", your "Science Fiction" collection in Plex would be named "*Science Fiction" and your art poster should be titled "science-fiction.png";
- Likewise, if you have a mixed-media library, your anime genre "Seinen" collection in Plex would be named "[A] Seinen" and your art poster should be titled "seinen.png" and placed in the "posters/anime/" directory;
This feature is only available to mixed-media libraries (see the Standard media and anime are mixed setup option).
It'll edit the generated collections' title sort in a way that the "type of media" collections will be at the top and all of the anime genres' collections will be at the bottom.
- Non-Anime's title sort --> "01"
- Anime's title sort --> "02"
- [A] *'s title sort --> "zzzzzz<ORIGINAL GENRE NAME>"
e.g.: [A] Sci-Fi's title sort will be set to "zzzzzzSci-Fi".
-
Read the Requirements and Compatible Setups sections above
-
Rename the
.env.example
file to.env
-
Edit the
.env
file and set your plex username, password, and server name or plex base url and auth token. -
If you are generating collections for standard media, you'll also need to set your TMDB Api Key on the
.env
file.Variable Authentication method Value PLEX_USERNAME Username and password Your Plex Username PLEX_PASSWORD Username and password Your Plex Password PLEX_SERVER_NAME Username and password Your Plex Server Name PLEX_BASE_URL Token Your Plex Server base URL PLEX_TOKEN Token Your Plex Token PLEX_COLLECTION_PREFIX (Optional) Prefix for the created Plex collections. For example, with a value of "*", a collection named "Adventure", the name would instead be "*Adventure".
Default value : ""TMDB_API_KEY Your TMDB api key (not required for anime library tagging)
usage: plexmngcollections.py [-h] [-l LIBRARY]
[-t {anime,standard-movies,standard-shows,mixed-movies,mixed-shows}]
[-p] [-g] [-s] [-n] [-y] [-f]
Adds collection genre tags to your Plex media as well as helps you manage it.
optional arguments:
-h, --help show this help message and exit
-l, --library LIBRARY
The exact name of the Plex library to generate genre
collections for.
-t, --type {anime,standard-movies,standard-shows,mixed-movies,mixed-shows}
The type of media contained in the library. Mixed
libraries contain both standard media and anime ('Non-
Anime' and 'Anime' collections will be generated and
anime's genre collections will be preceded by '[A]').
-p, --set-posters Uploads posters located in posters/$media-type - media-
type {anime, movies, shows}. Supports .PNG
-g, --generate-collections
Generate genre collections for the selected media.
-s, --sort Only applies to mixed libraries. Updates the
collections' sorting titles so that 'Non-Anime' and
'Anime' will be the first collections and the anime
genres' collections will be the last.
-n, --nono, -d, --dry
Do not modify plex collections (debugging feature).
-y, --yes Do not prompt.
-f, --force Force proccess on all media (independently of proggress
recorded in logs/).
examples:
python3 plexmngcollections.py -l "Anime Movies" -t anime --generate-collections
python3 plexmngcollections.py -l "Anime Shows" -t anime --generate-collections --set-posters
python3 plexmngcollections.py -l Movies -t standard-movies --generate-collections --set-posters
python3 plexmngcollections.py -l "TV Shows" -t standard-shows --set-posters
python3 plexmngcollections.py -l Movies -t mixed-movies --generate-collections --set-posters --sort
python3 plexmngcollections.py -l "TV Shows" -t mixed-shows --generate-collections --set-posters --sort
If you wish run this script every time a new media is added to server, I suggest you use [Tautulli](https://github.com/Tautulli/Tautulli)'s very useful script notification agent. I've implemented an update.py
script that you may use, but you also can implement your own, as Tautulli support many file types: .bat, .cmd, .php, .pl, .ps1, .py, .pyw, .rb, .sh
.
The provided provided update script will simply run python3 plexmngcollections.py -l <LIBRARY> -t <TYPE> -g -s -y
on all libraries specified. In order to use it, follow the instructions below:
- Go to the
update-script/
directory - Rename
libraries.json.example
tolibraries.json
- Following the template, edit
libraries.json
and list all the libraries you want the script to run on, as well as it's corresponding types - On your Tautulli page, go to Settings > Notification Agents > Add a new notification agent > Script
- On the "Script Folder" fuekd, select the full path to
plex-manage-collections/update-script
- Likewise, on the "Script File" field, select
update.py
- On the "Triggers" tab, select the "Recently Added" trigger
- Set any other settings as you wish and finally hit "Save"
I recommend you test the notification (select the ./update.py
on the "Test Notifications" tab and test it) and check the Tautulli logs to see the script's output. You may run into the following error: ModuleNotFoundError: No module named 'dotenv'
.
If so, you'll need to execute a few more steps:
- Install the required modules on the
plex-managecollections/
directory (using pip, you can executepip3 install --target=path/to/plex-manage-collections/ -r path/to/plex-manage-collections/requirements.txt
) - If you the same error persists, install again specifically the not found module (I had to do it to "idna_ssl":
pip3 install --upgrade --target=path/to/plex-manage-collections/ idna_ssl
) - Change the
plex-manage-collections
directory's permission in order for the user running Tautulli will be able to read, write and execute files inside it (in my case, I simply ranchmod -R 777 path/to/plex-manage-collections/
so that any user will have rwx permissons)
Note: The update.py
script'll only generate and sort the collections, but not update their posters (you'll have to do it manually). If you want it to set posters everytime it runs, simply swap the script's 6th line from
for lib in libraries: os.system(f'cd ..; python3 plexmngcollections.py -l {lib["name"]} -t {lib["type"]} -g -s -y')
to
for lib in libraries: os.system(f'cd ..; python3 plexmngcollections.py -l {lib["name"]} -t {lib["type"]} -g -s -y -p')
This script is a fork from ShaneIsrael's Plex Auto Genres, which works great for the Standard media and anime are separated setup option. I've only done some cleanup/modularization and made it compatible with the Standard media and anime are mixed setup option (as it is the one I use) and the Tautulli trigger.
I'd also like to thanks reddit's /u/SwiftPanda16 for helping me setup Tautulli to trigger the script (see the Auto-Run Whenever There's New Media section)
- If you are not seeing any new collections or updates in posters and sorting, try to realod your Plex client or to close it and re-open it.
- Delete the generated
logs/plex-*-successful.txt
andlogs/plex-*-failures.txt
files if you want the script to generate collections from scratch. You may want to do this if you delete your collections and need them re-created. Another option is to use the-f, --force
flag. - Having the release year in the title of a show or movie can cause the lookup to fail in some instances. For example Battlestar Galactica (2003) will fail, but Battlestar Galactica will not.
- If you run into a "ModuleNotFound" error when setting up the Tautulli script trigger, check what to do in the Auto-Run Whenever There's New Media section. For more information, you can also read this reddit post.
Unfortunately, this fork isn't available to run this via a Docker Container, but the original script is, see fdarveau Plex Auto Genres Docker.