Context: Upcoming Change: TheTVDB Metadata Support Ending on December 3rd
Plexmatch documentation: https://support.plex.tv/articles/plexmatch/
Using the post from a couple days ago as a starting point, I started thinking of the best way to handle the migration, especially for anime libraries, since those seem like they will have the most issues, and in the least intensive, destructive and intrusive way (in terms of file identifying, renaming, refoldering, or moving). I recommend you read the post linked above to get an idea of the actual considerations and differences between TVDB and TMDB. I wanted to get this out ASAP so people had a chance to set up their own fixes before TVDB support ends on Dec 3.
Thankfully, with TMDB custom episode ordering available in Plex now, you can look for one of the many that fit best for each show, and pick it before migrating your whole library to TMDB. And for the ones that don't have a matching custom order, you can generate a plexmatch file to map TMDB ordering to what your files are actually named on disc, so plex will show the right info for each file. The issue is identifying the right custom ordering to use for each show and generating a plexmatch file for those with no equivalent, at scale. Also, finding the shows that have movies in the Specials/Season0 folders that need to be moved (anime, shows like the new Punisher with its movie) can be a hassle at scale.
So, I put together a python script with assistance from AI (Gemini and Claude) that will scan a Plex TV library via plexapi, use a TMDB reader token to find the best matching custom ordering, suggest one to use if one is a 100% match to your files on disk, and generate a plexmatch file and put it in the right place in my library if an existing custom order doesn't match. It will also point out migration issues, like if it found a movie in the Specials folder that needs to move out to a Movie library, or if there are any episodes it couldn't match between what's in my Plex library vs what's in TMDB and need to be manually looked at. It can output this summary into a csv that I can use to track my progress in fixing the issues identified, since manual work is still required for some shows.
Once there's a .plexmatch file in the show folder, you can change the per-show episode ordering to whatever the script suggested, trigger a "Scan Library Files" on the library, and then refresh metadata, and you should see the new ordering in the Plex UI. Note that any episodes that are remapped by the .plexmatch file will have to rescan for stuff like loudness data and intro/credits. The plexmatch file is not exclusive, so any episodes not covered by the mappings will remain untouched, including future episodes for ongoing shows.
I'm not planning to share the script because I haven't run it through any sort of security or robustness review, but I can share the summary of the project as a prompt that might help people put together something similar for themselves. Note that this is built to run from a Windows PC with the Plex library folders mounted via SMB. Adjust as needed if you're running on your Plex server directly, or from a Linux PC, or have your library mounted via NFS. I made sure the script itself is non-destructive in that it doesn't do any write operations to Plex via the api, to minimize any sort of DB or library corruption issues, and there's a dry run option so you can see what it finds before writing plexmatch files, but I still recommend making a Plex DB backup before beginning to mess with plexapi via python, in case your AI agent of choice decides to be extra helpful. And be sure to run it at small scale (specify a list of shows in the input) before just pointing it at your whole library and letting it rip. If you run into any issues, you can just delete the generated .plexmatch file, change the episode ordering back to what it was, and rescan/refresh again (at least until TVDB support ends).
Below is the summary of the project that you can use as the baseline to creating your own script, structured as an AI prompt. This is only a starting point. Tailor to your specific needs and purposes.
Begin AI generated content:
Write a standalone Python script (generate_plexmatch.py) using plexapi and requests (TMDB v3 API with Bearer token auth and urllib3 Retry backoff on 429/5xx) to audit a Plex TV/Anime library against TMDB and generate spec-compliant .plexmatch files.
##Config & Inputs:
⢠PLEX_URL, PLEX_TOKEN, TV_LIBRARY_NAME, TMDB_READ_TOKEN.
⢠TARGET_SHOWS = [] (scan exact titles case-insensitively, or full library if empty).
⢠PATH_MAPS = [("/plex/path", r"\\server\smb\path")] (strict path-boundary check so /media/TV never matches /media/TV2; skip writing if unmapped; [] if local).
⢠Toggles: SUMMARY_ONLY (read-only report + <library>_plexmatch-summary.csv), PREFERRED_GROUP_NAME (None = auto-pick best), INCLUDE_SPECIALS, DRY_RUN, WRITE_PERFECT_SHOWS (False), BACKUP_EXISTING (True, .bak-YYYYMMDD-HHMMSS), INCLUDE_COMMENTS (True).
##TMDB Catalogs & Alternate Episode Groups:
⢠Fetch /3/tv/{tmdb_id} + batch seasons in chunks of 20 via append_to_response=season/1,season/2,... (include season/0 if INCLUDE_SPECIALS).
⢠Fetch /3/tv/{tmdb_id}/episode_groups and each /3/tv/episode_group/{id} (e.g., Seasons, Crunchyroll, DVD). Parse season numbers via r'\b(?:season|series|cour|part)\s*(\d+)' before falling back to order (so titles like "Season 2 (vs. U-20 Japan)" don't parse as Season 20). Map "special" groups to Season 0. Detect 0-based vs. 1-based episode order dynamically.
##Matching & Conflict Rules:
⢠Normalize titles by replacing punctuation/dots/underscores with spaces (never deleting them). Strip [Group], (1080p), codecs, SxxEyy, and leading show names from filename stems.
⢠Score both ep.title (Plex's TVDB title) and cleaned filename stem against TMDB titles: exact (1.0), generic numbered titles (Episode 5 vs Episode 15 must match numbers or 0.0), word-subset (0.9 only when min(len(w1), len(w2)) >= 2), or SequenceMatcher (>= 0.65). Add +0.25 for air date within ±1 day and +0.05 if (season, ep) already matches.
⢠Evaluate all file parts across all folders in show.locations. Assign each TMDB episode slot to at most one Plex episode (highest score wins; flag runners-up as conflicts). Group consecutive slots sharing one physical file into ranges (S01E02-E03); flag non-consecutive multi-slot files as conflicts.
##Season 0 Movie Check:
⢠Cache (/3/search/movie via @lru_cache) lookups for unmatched Season 0 files using cleaned title + release year. If matched (>= 0.70) or titled with "movie"/"theatrical", flag separately as a standalone Movie to move to a Movies library.
##Strict .plexmatch Syntax & Summary Output:
⢠Write one .plexmatch per root folder in show.locations using forward-slash relative paths (Season 1/file.mkv).
⢠Add an ONLY_CHANGED_HINTS = True toggle that omits single-episode files whose (season, episode) already matches TMDB 1:1 from the generated .plexmatch, writing hints only for remapped episodes, specials (SPxx), and multi-episode ranges (SxxEyy-Ezz).
⢠Format: lowercase title: and tmdbid:, standalone # comment lines above each hint (never inline after filenames), ep: SP01: for specials, ep: S01E01: for episodes, ep: S01E02-E03: for multi-episode files (no invalid : pt: suffixes).
⢠In SUMMARY_ONLY mode, pick the ordering with highest (exact_se_hits, total_matches, -conflicts) (ties favor "Default Aired"), separate 100% Native Match (Set Ordering in Plex) from Needs .plexmatch or Manual Review, and format CSV alignment fractions as ="12/12" so Excel doesn't convert them to dates.