Automatically creates genre collections for your Plex media

Overview

Plex Auto Genres

Plex Auto Genres is a simple script that will add genre collection tags to your media making it much easier to search for genre specific content

  1. Requirements
  2. Optimal Setup
  3. Getting Started
  4. Automating
  5. Docker Usage
  6. Troubleshooting
Movies example (with cover art set using --set-posters flag.)

Movie Collections

Anime example

Anime Collections

Requirements

  1. Python 3 - Instructions > Windows / Mac / Linux (Not required if using Docker)
  2. TMDB Api Key (Only required for non-anime libraries)

Optimal Setup

  1. Anime / Anime Movies are in their own library on your plex server. (Anime and Anime Movies can share the same library)
  2. Standard TV Shows are in their own library on your plex server.
  3. Standard Movies are in their own library on your plex server.
  4. Proper titles for your media, this makes it easier to find the media. (see https://support.plex.tv/articles/naming-and-organizing-your-tv-show-files/)

For this to work well your plex library should be sorted. Meaning standard and non-standard media should not be in the same Plex library. Anime is an example of non-standard media.

If your anime shows and standard tv shows are in the same library, you can still use this script just choose (standard) as the type. However, doing this could cause incorrect genres added to some or all of your anime media entries.

Here is an example of my plex library setup

Plex Library Example

Getting Started

  1. Read the Optimal Setup section above
  2. Run python3 -m pip install -r requirements.txt to install the required dependencies.
  3. Rename the .env.example file to .env
  4. Rename the config/config.json.example file to config/config.json. The default settings are probably fine.
  5. Edit the .env file and set your plex username, password, and server name. If you are generating collections for standard media (non anime) you will need to also obtain an TMDB Api Key (for movies and tv shows)
    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)
  6. Optional, If you want to update the poster art of your collections. See posters/README.md

You are now ready to run the script

usage: plex-auto-genres.py [-h] [--library LIBRARY] [--type {anime,standard-movie,standard-tv}] [--set-posters] [--sort] [--rate-anime]
                           [--create-rating-collections] [--query QUERY [QUERY ...]] [--dry] [--no-progress] [-f] [-y]

Adds genre tags (collections) to your Plex media.

optional arguments:
  -h, --help            show this help message and exit
  --library LIBRARY     The exact name of the Plex library to generate genre collections for.
  --type {anime,standard-movie,standard-tv}
                        The type of media contained in the library
  --set-posters         uploads posters located in posters/<type> of matching collections. Supports (.PNG)
  --sort                sort collections by adding the sort prefix character to the collection sort title
  --rate-anime          update media ratings with MyAnimeList ratings
  --create-rating-collections
                        sorts media into collections based off rating
  --query QUERY [QUERY ...]
                        Looks up genre and match info for the given media title.
  --dry                 Do not modify plex collections (debugging feature)
  --no-progress         Do not display the live updating progress bar
  -f, --force           Force proccess on all media (independently of proggress recorded in logs/).
  -y, --yes

examples: 
python plex-auto-genres.py --library "Anime Movies" --type anime
python plex-auto-genres.py --library "Anime Shows" --type anime
python plex-auto-genres.py --library Movies --type standard-movie
python plex-auto-genres.py --library "TV Shows" --type standard-tv

python plex-auto-genres.py --library Movies --type standard-movie --set-posters
python plex-auto-genres.py --library Movies --type standard-movie --sort
python plex-auto-genres.py --library Movies --type standard-movie --create-rating-collections

python plex-auto-genres.py --type anime --query chihayafuru
python plex-auto-genres.py --type standard-movie --query Thor Ragnarok

Example Usage

Automating

I have conveniently included a script to help with automating the process of running plex-auto-genres when combined with any number of cron scheduling tools such as crontab, windows task scheduler, etc.

If you have experience with Docker I reccommend using my docker image which will run on a schedule.

  1. Copy .env.example to .env and update the values
  2. Copy config.json.example to config.json and update the values
  3. Each entry in the run list will be executed when you run this script
  4. Have some cron/scheduling process execute python3 automate.py, I suggest running it manually first to test that its working.

Note: The first run of this script may take a long time (minutes to hours) depending on your library sizes.

Note: Don't be alarmed if you do not see any text output. The terminal output you normally see when running plex-auto-genres.py is redirected to the log file after each executed run in your config.

Docker Usage

  1. Install Docker
  2. Install Docker Compose
  3. Clone or Download this repository
  4. Edit docker/docker-compose.yml
    1. Update the volumes: paths to point to the config,logs,posters directories in this repo.
    2. Update the environment: variables. See Getting Started.
  5. Copy config/config.json.example to config/config.json
    1. Edit the run array examples to match your needs. When the script runs, each library entry in this array will be updated on your Plex server.
  6. Run docker-compose up -d, the script will run immediately then proceed to run on a schedule every night at 1am UTC. Logs will be located at logs/plex-auto-genres-automate.log

Another Docker option of this tool can be found here.

Troubleshooting

  1. If you are not seeing any new collections close your plex client and re-open it.
  2. Delete the generated plex-*-successful.txt and plex-*-failures.txt files if you want the script to generate collections from the beginning. You may want to do this if you delete your collections and need them re-created.
  3. Having the release year in the title of a tv show or movie can cause the lookup to fail in some instances. For example Battlestar Galactica (2003) will fail, but Battlestar Galactica will not.
Comments
  • Error on docker or native python

    Error on docker or native python

    Hello, I discover your tool yesterday and i try it today. But i follow the instruction and i have the same error on docker and native python. I attach my error.

    I guess you you forgot in docker-compose.yml the " version: 'XX'"

    Can someone help me python

    bug 
    opened by rachid598 11
  • Invalid API key

    Invalid API key

    Plex Version 1.22.3.4523

    Followed instructions and receive API key error.

    I have successfully authenticated with username and password, and ensured that token is the same copied from end of URL string when looking at the XML of a media file from my library as per updated readme.

    Process starts and appears in logs to query my media fine, but then fails:

    Invalid API key: You must be granted a valid key., when searching for entry: 21 Bridges, of type standard-movie.

    It the proceeds to fail for every media file.

    opened by danielmeridew-mto 8
  • Feature Request: Prefix for sort titles

    Feature Request: Prefix for sort titles

    Add a feature like PLEX_COLLECTION_PREFIX but for sort titles. So the genre collections will be together instead of getting mixed with other collections.

    enhancement 
    opened by darkknight6722 5
  • Lots of standard TV failures

    Lots of standard TV failures

    Looking at my logs:

    cat logs/plex-standard-tv-failures.txt
    ["The Americans (2013) (2013)", "Anne of Green Gables (1985) (1985)", "Archer (2009) (2009)", "Battlestar Galactica (2003) (2003)", "Brave New World (2020) (2020)", "Bull (2016) (2016)", "Cannonball (US) (2020)", "Card Sharks (2019) (2019)", "Castle (2009) (2009)", "Celebrity Game Face (2020)", "The Crystal Maze (2017) (2016)", "DAVE (2020) (2020)", "Emergency Call (US) (2020)", "The Fix (2018) (2018)", "The Flash (2014) (2014)", "For the People (2018) (2018)", "The Goldbergs (2013) (2013)", "Grand Hotel (US) (2019)", "Hunted (US) (2017)", "Instinct (2018) (2018)", "Jeopardy! (1964)", "Last Man Standing (2011) (2011)", "The Librarians (2014) (2004)", "MacGyver (2016) (2016)", "The Magicians (2015) (2015)", "Making it Home with Kortney and Dave (2020)", "Mars (2016) (2016)", "Masters of Illusion (2014) (2014)", "Miracle Workers (2019) (2019)", "Nancy Drew (2019) (2019)", "Nashville (2012) (2012)", "neXt (2020) (2020)", "No Activity (US) (2017)", "Nurses (2020) (2020)", "Once Upon a Time (2011) (2011)", "The Outsider (2020) (2020)", "Pandora (2019) (2019)", "Poldark (2015) (2015)", "Powers (2015) (2015)", "Press Your Luck (2019) (2019)", "S.W.A.T. (2017) (2017)", "Scandal (2012) (2012)", "Snowfall (2017) (2017)", "The Stand (2020) (2020)", "Swamp Thing (2019) (2019)", "The Tick (2016) (2016)", "Timeless (2016) (2016)", "Travelers (2016) (2016)", "The Twilight Zone (2019) (2019)", "Unsolved (2018) (2018)", "Who Wants to Be a Millionaire (2020) (2020)", "Wife Swap (2019) (2019)", "Your Honor (US) (2020)"]
    

    It appears, most of the failures have double (YEAR) entries.. Is this expected?

    opened by vaparr 5
  • No poster found for Plex created collections

    No poster found for Plex created collections

    I already have some collections created by plex and plex auto collections. It shows no posters found for those collections. I don`t want to change the posters for those collections but want posters for new genre collections. Any ways or I am doing something wrong?

    opened by darkknight6722 5
  • MAL made changes to genres and split in into demographics/themes

    MAL made changes to genres and split in into demographics/themes

    Since the changes am unable to scan through and add new items without 503 errors (very inconsistentally, sometimes it works, sometimes it doesn't, have to try multiple times and depends on luck):

    Uncaught Exception: HTTP 503 - status=503, type=BadResponseException, message=Jikan failed to connect to MyAnimeList. MyAnimeList may be down/unavailable or refuses to connect, error=None for search type=anime, query=Attack on Titan←[0m Updated 0 entrie(s) since last run.

    Article for Change: https://myanimelist.net/forum/?topicid=1956762 Affected Code: https://github.com/ShaneIsrael/plex-auto-genres/blob/master/src/genres.py#L16-L17

    opened by Icnopandaz 4
  • no attribute 'collection'

    no attribute 'collection'

    Traceback (most recent call last): File "/mnt/mpathae/mtauberjr/plex-auto-genres/plex-auto-genres.py", line 35, in uploadCollectionArt(plex) File "/mnt/mpathae/mtauberjr/plex-auto-genres/src/plex.py", line 179, in uploadCollectionArt collections = plex.library.section(LIBRARY).collection() AttributeError: 'MovieSection' object has no attribute 'collection'

    opened by mtauberjr 4
  • collection sort

    collection sort

    D:\github\plex-auto-genres-master\plex-auto-genres-master>python plex-auto-genres.py --library Movies --type standard-movie --sort
    
    Connecting to Plex...
    
    You are about to sort [Movies] collection's by prefixing their sort titles with our prefix character set in config/config.json.
    Continue? y/n... y
    Traceback (most recent call last):
      File "D:\github\plex-auto-genres-master\plex-auto-genres-master\plex-auto-genres.py", line 40, in <module>
        sortCollections(plex, LIBRARY)
      File "D:\github\plex-auto-genres-master\plex-auto-genres-master\src\plex.py", line 225, in sortCollections
        collections = plex.library.section(library).collections(title=c)
    AttributeError: 'MovieSection' object has no attribute 'collections'
    
    cannot reproduce 
    opened by Septan 4
  • Uploading collection artwork

    Uploading collection artwork

    D:\github\plex-auto-genres-master\plex-auto-genres-master>python plex-auto-genres.py --library Movies --type standard-movie --set-posters
    
    Connecting to Plex...
    
    You are about to update your [Movies] collection's posters to any matching image titles located at posters/.
    Continue? y/n... y
    
    Uploading collection artwork...
    Traceback (most recent call last):
      File "D:\github\plex-auto-genres-master\plex-auto-genres-master\plex-auto-genres.py", line 35, in <module>
        uploadCollectionArt(plex)
      File "D:\github\plex-auto-genres-master\plex-auto-genres-master\src\plex.py", line 207, in uploadCollectionArt
        + sub(f'^{os.getcwd()}', '', posterPath) + f'{bcolors.ENDC}.')
      File "C:\Python39\lib\re.py", line 210, in sub
        return _compile(pattern, flags).sub(repl, string, count)
      File "C:\Python39\lib\re.py", line 304, in _compile
        p = sre_compile.compile(pattern, flags)
      File "C:\Python39\lib\sre_compile.py", line 764, in compile
        p = sre_parse.parse(p, flags)
      File "C:\Python39\lib\sre_parse.py", line 948, in parse
        p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
      File "C:\Python39\lib\sre_parse.py", line 443, in _parse_sub
        itemsappend(_parse(source, state, verbose, nested + 1,
      File "C:\Python39\lib\sre_parse.py", line 525, in _parse
        code = _escape(source, this, state)
      File "C:\Python39\lib\sre_parse.py", line 426, in _escape
        raise source.error("bad escape %s" % escape, len(escape))
    re.error: bad escape \g at position 3
    
    opened by Septan 4
  • Crash at 15.4%

    Crash at 15.4%

    I am unable to get passed 15.4%, with this crash:

    root@Unraid:/tmp/plex-auto-genres# python3 ./plex-auto-genres.py --library Anime --type anime

    Connecting to Plex...

    You are about to create [anime] genre collection tags for the library [Anime] on your server [Falken].With prefix [*]. Continue? y/n... y Found 872 media entries under Anime (133/872 completed). Estimated time to completion: 198 minutes...

    Traceback (most recent call last):---------------------------| 15.4% Complete File "./plex-auto-genres.py", line 22, in UPDATE_COUNT = generate(plex) File "/tmp/plex-auto-genres/src/plex.py", line 75, in generate genres = getGenres(media, TYPE) File "/tmp/plex-auto-genres/src/genres.py", line 49, in getGenres genres = getAnimeGenres(media.title) File "/tmp/plex-auto-genres/src/genres.py", line 15, in getAnimeGenres animeId = query['results'][0]['mal_id'] # anime's MyAnimeList ID IndexError: list index out of range

    Side note, when we crash, it doesnt save progress.. so i had to stop it at 15.3% once, then try to repro so i wouldnt lose my place.

    opened by vaparr 4
  • Error due to ARM (Raspberry Pi)

    Error due to ARM (Raspberry Pi)

    I have the following error in my logs after starting my docker container. standard_init_linux.go:228: exec user process caused: exec format error I believe this is due to me using it on a Raspberry Pi. Any image for ARM devices? Or am I stuck not being able to use it?

    Thanks!

    opened by Droppisalt 3
  • New Anime Enhancement Request

    New Anime Enhancement Request

    Your Script has been an amazing time saver. Thank you for putitng it into the world.

    Creating Plex Anime collections by genre is great, however, have you ever considered creating collections by Themes (which also appear to be provided by the Jikan API)? Where Genres work well for american movies and tv shows, Themes seem to be more specific and better suited for Anime collections in my opinion. Though I'm not a developer, it seems like it might be an easy addition or change. (See https://myanimelist.net/anime.php to view the various myanimelist themes. )

    Just throwing the idea out there to see if it seems like a good idea to others

    2022-06-17 23_14_02-Anime - MyAnimeList net .

    opened by petenun 1
Owner
Shane Israel
Shane Israel
The DL Streamer Pipeline Zoo is a catalog of optimized media and media analytics pipelines.

The DL Streamer Pipeline Zoo is a catalog of optimized media and media analytics pipelines. It includes tools for downloading pipelines and their dependencies and tools for measuring their performace.

null 8 Dec 4, 2022
NeRD: Neural Reflectance Decomposition from Image Collections

NeRD: Neural Reflectance Decomposition from Image Collections Project Page | Video | Paper | Dataset Implementation for NeRD. A novel method which dec

Computergraphics (University of Tübingen) 195 Dec 29, 2022
EMNLP 2021 Adapting Language Models for Zero-shot Learning by Meta-tuning on Dataset and Prompt Collections

Adapting Language Models for Zero-shot Learning by Meta-tuning on Dataset and Prompt Collections Ruiqi Zhong, Kristy Lee*, Zheng Zhang*, Dan Klein EMN

Ruiqi Zhong 42 Nov 3, 2022
PyTorch implementation of "Representing Shape Collections with Alignment-Aware Linear Models" paper.

deep-linear-shapes PyTorch implementation of "Representing Shape Collections with Alignment-Aware Linear Models" paper. If you find this code useful i

Romain Loiseau 27 Sep 24, 2022
A Blender python script for getting asset browser custom preview images for objects and collections.

asset_snapshot A Blender python script for getting asset browser custom preview images for objects and collections. Installation: Click the code butto

Johnny Matthews 44 Nov 29, 2022
Collections for the lasted paper about multi-view clustering methods (papers, codes)

Multi-View Clustering Papers Collections for the lasted paper about multi-view clustering methods (papers, codes). There also exists some repositories

Andrew Guan 10 Sep 20, 2022
A Python script that creates subtitles of a given length from text paragraphs that can be easily imported into any Video Editing software such as FinalCut Pro for further adjustments.

Text to Subtitles - Python This python file creates subtitles of a given length from text paragraphs that can be easily imported into any Video Editin

Dmytro North 9 Dec 24, 2022
This program creates a formatted excel file which highlights the undervalued stock according to Graham's number.

Over-and-Undervalued-Stocks Of Nepse Using Graham's Number Scrap the latest data using different websites and creates a formatted excel file that high

null 6 May 3, 2022
Python script that allows you to automatically setup your Growtopia server.

AutoSetup Python script that allows you to automatically setup your Growtopia server. How To Use Firstly, install all the required modules that used i

Aspire 3 Mar 6, 2022
QT Py Media Knob using rotary encoder & neopixel ring

QTPy-Knob QT Py USB Media Knob using rotary encoder & neopixel ring The QTPy-Knob features: Media knob for volume up/down/mute with "qtpy-knob.py" Cir

Tod E. Kurt 56 Dec 30, 2022
Cross-media Structured Common Space for Multimedia Event Extraction (ACL2020)

Cross-media Structured Common Space for Multimedia Event Extraction Table of Contents Overview Requirements Data Quickstart Citation Overview The code

Manling Li 49 Nov 21, 2022
Tensorflow python implementation of "Learning High Fidelity Depths of Dressed Humans by Watching Social Media Dance Videos"

Learning High Fidelity Depths of Dressed Humans by Watching Social Media Dance Videos This repository is the official tensorflow python implementation

Yasamin Jafarian 287 Jan 6, 2023
A crossplatform menu bar application using mpv as DLNA Media Renderer.

Macast Chinese README A menu bar application using mpv as DLNA Media Renderer. Install MacOS || Windows || Debian Download link: Macast release latest

null 4.4k Jan 1, 2023
Research Artifact of USENIX Security 2022 Paper: Automated Side Channel Analysis of Media Software with Manifold Learning

Manifold-SCA Research Artifact of USENIX Security 2022 Paper: Automated Side Channel Analysis of Media Software with Manifold Learning The repo is org

Yuanyuan Yuan 172 Dec 29, 2022
CoReD: Generalizing Fake Media Detection with Continual Representation using Distillation (ACMMM'21 Oral Paper)

CoReD: Generalizing Fake Media Detection with Continual Representation using Distillation (ACMMM'21 Oral Paper) (Accepted for oral presentation at ACM

Minha Kim 1 Nov 12, 2021
A Python package for performing pore network modeling of porous media

Overview of OpenPNM OpenPNM is a comprehensive framework for performing pore network simulations of porous materials. More Information For more detail

PMEAL 336 Dec 30, 2022
Hunt down social media accounts by username across social networks

Hunt down social media accounts by username across social networks Installation | Usage | Docker Notes | Contributing Installation # clone the repo $

null 1 Dec 14, 2021
MARS: Learning Modality-Agnostic Representation for Scalable Cross-media Retrieva

Introduction This is the source code of our TCSVT 2021 paper "MARS: Learning Modality-Agnostic Representation for Scalable Cross-media Retrieval". Ple

null 7 Aug 24, 2022
This was initially the repo for the project of PSYC626@USC of Asaf Mazar, Millad Kassaie and Georgios Chochlakis named "Powered by the Will? Exploring Lay Theories of Behavior Change through Social Media"

Subreddit Analysis This repo includes tools for Subreddit analysis, originally developed for our class project of PSYC 626 in USC, titled "Powered by

Georgios Chochlakis 1 Dec 17, 2021