Skip to main content

Media Renamer

A Python tool for renaming movie folders and files with proper IMDB-style formatting using The Movie Database (TMDB) API.

What it does

Media Renamer takes movie folders with inconsistent naming and renames them (and all files within) to a standardised format that includes IMDB identifiers. This is particularly useful for media server applications like Plex that benefit from consistent, metadata-rich file naming.

Example transformation

Before:

Beverly Hills Cop Axel F (2024)/
├── Beverly Hills Cop Axel F (2024).mkv
├── Beverly Hills Cop Axel F (2024).1208527.srt
├── Beverly Hills Cop Axel F (2024).1208528.srt
└── Beverly Hills Cop Axel F (2024).1208529.srt

After:

Beverly Hills Cop -- Axel F (2024) {imdb-tt3083016}/
├── Beverly Hills Cop -- Axel F (2024) {imdb-tt3083016}.mkv
├── Beverly Hills Cop -- Axel F (2024) {imdb-tt3083016}.1208527.srt
├── Beverly Hills Cop -- Axel F (2024) {imdb-tt3083016}.1208528.srt
└── Beverly Hills Cop -- Axel F (2024) {imdb-tt3083016}.1208529.srt

Features

  • Interactive search: Presents multiple options from TMDB with cast information
  • Fuzzy folder name parsing: Handles torrent-style names with quality/codec tags and group identifiers. A multi-candidate pipeline extracts the clean title from before the year token, strips known technical tokens (resolution, codec, audio, release flags such as WS, Multi, EAC3, etc.), and falls back through progressively simpler queries until TMDB returns a match
  • Tolerant year matching: Year is used as a soft ranking signal rather than a hard filter — results for the right film ranked by year proximity, so an off-by-one label won't discard correct matches
  • Intelligent filename sanitisation: Replaces problematic characters (: becomes --, / becomes or, etc.)
  • Comprehensive renaming: Renames both folders and all files within them
  • Flexible input: Accepts custom rename strings or skips items entirely
  • Safe operation: Checks for existing target folders to prevent conflicts
  • Comprehensive test suite: Includes pytest-based tests with mocked API calls

Installation

Via pipx (recommended)

pipx install media-renamer

Then save your TMDB API key:

media-renamer --set-api-key your_api_key_here

This writes the key to ~/.media-renamer.conf and you're ready to go. As a fallback, the TMDB_API_KEY environment variable is also accepted.

From source

  1. Clone the repository:

    git clone <repository-url>
    cd media-renamer
    
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Make scripts executable:

    chmod +x media-renamer
    chmod +x replicate-structure
    

Setup

Get a TMDB API Key

  1. Create a free account at The Movie Database
  2. Go to API Settings and request an API key
  3. Save it:
    media-renamer --set-api-key your_api_key_here
    
    This writes the key to ~/.media-renamer.conf.

Usage

Basic usage

./media-renamer <folder_pattern>

Examples

Rename all movie folders in current directory:

./media-renamer "*"

Rename specific folders:

./media-renamer "Beverly Hills Cop*" "Bridget Jones*"

Supported folder name formats

The tool handles a range of naming conventions:

Format Example
Clean with year Beverly Hills Cop Axel F (2024)
Torrent with quality/group tags Aniara (2019) (1080p BluRay x265 HEVC 10bit DTS 5.1 Qman) [UTR]
Dot-separated with release flags Sexy.Beast.2000.WS.1080p.BluRay.x265.HEVC.EAC3-SARTRE
Multi-language / HDR torrent The.Mummy.1999.Multi.2160p.BluRay.x265.HDR.DTS-HDMA.7.1.[En+Hi]-DTOne
Underscore separators The_Dark_Knight_(2008)
No year Some Movie [YTS]

Year mismatches of one or two years are tolerated — the correct film will still appear in the results, ranked by proximity to the folder's year.

Interactive process

When you run the tool, it will:

  1. Parse each folder name to extract title and year (stripping torrent noise)

  2. Search TMDB for matching movies, ranked by year proximity

  3. Present up to 3 options with cast information:

    Looking up Beverly Hills Cop Axel F (2024)...
    1) Beverly Hills Cop -- Axel F (2024) {imdb-tt3083016} (Beverly Hills Cop: Axel F; 2024; Eddie Murphy, Joseph Gordon-Levitt, Taylour Paige)
    2) Beverly Hills Cop -- Axel F (2024) {imdb-tt8874500} (Beverly Hills Cop: Axel F; 2024; Behind the Scenes)
    3) Beverly Hills Cop -- Axel F (2024) {imdb-tt9876543} (Beverly Hills Cop: Axel F; 2024; Documentary)
    Choose 1-3, or enter a new rename string, or nothing to skip:
    >
    
  4. You can:

    • Enter a number (1-3) to select one of the options
    • Type a custom rename string
    • Press Enter to skip this folder

Filename formatting rules

The tool follows these character replacement rules for safe filenames:

Character Replacement Reason
: -- Subtitle separator
/ or Alternative indicator
\ or Alternative indicator
<> () Bracket substitution
" ' Quote substitution
| , List separator
? ! Question to exclamation
* x Wildcard to letter

Testing

The project includes a comprehensive test suite using pytest.

Run tests

pytest

Create test data

Use the included replicate-structure script to create a test directory structure:

./replicate-structure /path/to/your/movies ./test-data

This creates a copy of your directory structure with empty files, perfect for testing without risking your actual media files.

Test coverage

The test suite covers:

  • Folder name parsing
  • Filename sanitisation
  • Movie name formatting
  • TMDB API integration (mocked)
  • Complete renaming workflows
  • Edge cases and error handling

File structure

media-renamer/
├── media_renamer.py        # Main module
├── media-renamer           # CLI entry point
├── replicate-structure     # Test data generator
├── test_media_renamer.py   # Test suite
├── requirements.txt        # Dev dependencies (requests, pytest, pytest-mock)
├── pyproject.toml          # Package configuration
└── README.md              # This file

Requirements

  • Python 3.7+
  • requests - For TMDB API calls
  • pytest / pytest-mock - For running tests

Compatibility

This tool is designed to work with:

  • Plex Media Server - The naming format is optimised for Plex's metadata agents
  • Other media servers - The standardised format should work with most media management tools
  • General file organisation - Useful for anyone wanting consistent movie file naming

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run the test suite
  5. Submit a pull request

Acknowledgements

Metadata

Release files for media-renamer 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for media-renamer 1.4.1
File Size Uploaded
media_renamer-1.4.1.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for media-renamer 1.4.1
File Interpreter ABI Platform
media_renamer-1.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 18.8 kB

Release files / media_renamer-1.4.1.tar.gz

Download URL media_renamer-1.4.1.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a3857d151d3766f88d4dec597ff39d5ff6fc3c93895ff5dd70ad53431d872150
BLAKE2b-256 checksum
How to use checksums
177d7a3197c28c19ccc57e6e75a4e656c50a20f310be664a7370c1379c951062
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release files / media_renamer-1.4.1-py3-none-any.whl

Download URL media_renamer-1.4.1-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b3d2af6ee723e19ae69fbd3d6a0790ff67834f9b57d8ee3672197a56452f631d
BLAKE2b-256 checksum
How to use checksums
738ae41119ed951eda72ea0d1fb0f103b3cbb461ba4de103c12a48a993b25faf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.13

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page