Skip to content

Conversation

@ttlequals0
Copy link

Summary

This PR adds several major enhancements to Labelarr while maintaining full backward compatibility:

  • Radarr/Sonarr Integration: Automatically detect TMDb IDs from your media managers without requiring file renaming
  • Persistent Storage: Track processed items across container restarts to prevent reprocessing
  • Keyword Normalization: Intelligent formatting of TMDb keywords with pattern recognition
  • Smart Duplicate Cleaning: Automatically removes old unnormalized keywords when adding normalized versions
  • Force Update Mode: Reprocess all items regardless of previous processing status
  • Verbose Logging: Detailed debugging information for troubleshooting matching issues
  • Enhanced Error Handling: Better authentication and connection testing

Key Features

🚀 Radarr/Sonarr Integration

  • Automatic TMDb ID detection through Radarr/Sonarr APIs
  • Multiple matching strategies: title/year, IMDb ID, TVDb ID, file path
  • Optional integration - enable only if you use Radarr/Sonarr
  • Falls back to file path detection if not found in media managers

💾 Persistent Storage

  • JSON file-based storage with atomic writes
  • Prevents reprocessing after container restarts
  • Docker volume support with configurable data directory
  • Tracks which field (label/genre) was updated

📝 Keyword Normalization

  • Pattern-based recognition for dynamic handling
  • Smart title casing with article/preposition handling
  • Acronym detection (FBI, CIA, DEA, etc.)
  • Special patterns for agencies, centuries, locations, relationships
  • Handles "duringcreditsstinger" → "During Credits Stinger"
  • Formats "central intelligence agency (cia)" → "Central Intelligence Agency (CIA)"
  • Smart duplicate cleaning removes old unnormalized versions when adding normalized ones

🔍 Verbose Logging

  • Shows detailed TMDb ID lookup process
  • Displays all matching attempts and sources
  • Shows keyword normalization in action
  • Helps troubleshoot why items aren't being matched

🔄 Force Update Mode

  • Reprocesses all items regardless of previous processing status
  • Useful for applying keyword normalization to existing libraries
  • Bypasses storage checks and "already has keywords" logic
  • Shows clear indication when force update mode is active

🧹 Smart Duplicate Cleaning

  • Automatically removes old unnormalized keywords when adding normalized versions
  • Prevents accumulation of duplicates like both "sci-fi" and "Sci-Fi"
  • Preserves manually set keywords in Plex
  • Works seamlessly with force update mode for library cleanup

Changes Made

New Modules

  • internal/radarr/ - Complete Radarr API v3 client
  • internal/sonarr/ - Complete Sonarr API v3 client
  • internal/storage/ - Persistent storage implementation
  • internal/utils/normalize.go - Keyword normalization utility

Modified Files

  • Enhanced internal/media/processor.go with multi-source TMDb ID detection
  • Updated internal/tmdb/client.go to normalize keywords
  • Extended internal/config/config.go with new configuration options
  • Updated main.go with connection testing and client initialization

Documentation

  • Comprehensive README updates with examples and configuration
  • Detailed CHANGELOG.md with all features documented
  • Added test documentation

Testing

  • Added 90+ test cases for keyword normalization
  • Tested with real-world Plex/Radarr/Sonarr setups
  • Verified backward compatibility with existing installations
  • Confirmed persistent storage works across restarts

Configuration

All new features are optional and disabled by default:

# Radarr Integration (optional)
- USE_RADARR=true
- RADARR_URL=http://radarr:7878
- RADARR_API_KEY=your_api_key

# Sonarr Integration (optional)
- USE_SONARR=true
- SONARR_URL=http://sonarr:8989
- SONARR_API_KEY=your_api_key

# Other new options
- VERBOSE_LOGGING=true
- DATA_DIR=/data
- FORCE_UPDATE=true

Backward Compatibility

  • ✅ All new features are optional
  • ✅ Default behavior unchanged
  • ✅ File path TMDb ID detection still works
  • ✅ No breaking changes to existing configurations

Examples

Verbose Logging Output

🔍 Starting TMDb ID lookup for movie: The Matrix (1999)
   📋 Available Plex GUIDs:
      - imdb://tt0133093
      - tmdb://603
   ✅ Found TMDb ID in Plex metadata: 603
   📝 Normalized: "sci-fi" → "Sci-Fi"
   📝 Normalized: "artificial intelligence (a.i.)" → "Artificial Intelligence (A.I.)"

Persistent Storage

{
  "ratingKey": "12345",
  "title": "The Matrix",
  "tmdbId": "603",
  "lastProcessed": "2025-07-05T10:30:45Z",
  "keywordsSynced": true,
  "updateField": "label"
}

Real-World Results

The keyword normalization feature ensures consistent, professional-looking keywords in your Plex library. For example, "50 First Dates" shows properly formatted genres including "Romantic Comedy" (normalized from "romcom"), "Short-term Memory Loss", and "True Love" - all with correct capitalization and formatting.

Related Issues

This PR addresses several community requests for:

  • Better TMDb ID detection without file renaming
  • Prevention of reprocessing after restarts
  • Clearer debugging information
  • Consistent keyword formatting

@nullable-eth nullable-eth self-requested a review July 6, 2025 12:01
@nullable-eth nullable-eth changed the title Enhanced Labelarr with Radarr/Sonarr Integration and Keyword Normalization feature: Enhanced Labelarr with Radarr/Sonarr Integration and Keyword Normalization Jul 6, 2025
Copy link
Owner

@nullable-eth nullable-eth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, love the Radarr and Sonarr integration. The normalize does not exactly work, and I noticed this before, but I think Plex does there own processing of the label.

1
2

But if you like I'm ok iterating and trying to figure out a solution after the fact because I think people will be greatly aided by the Radarr and Sonarr integration.

@ttlequals0
Copy link
Author

This is great, love the Radarr and Sonarr integration. The normalize does not exactly work, and I noticed this before, but I think Plex does there own processing of the label.

1 2

But if you like I'm ok iterating and trying to figure out a solution after the fact because I think people will be greatly aided by the Radarr and Sonarr integration.

Please do, I also noticed some oddness with the normalized names making it to Plex. I see some do, but most don't, which I'm trying to figure out with no luck.

@ttlequals0
Copy link
Author

After further googling, this appears to be a known Plex behavior. A forum thread
(https://forums.plex.tv/t/can-i-fix-genre-naming-capitalization/193058) shows a user experiencing similar issues
where Plex persisted lowercase genres despite API updates, requiring database optimization to fix.

The forum discussion hints that Plex can be a pain to maintain specific metadata at the database level.
Standard metadata refreshes may not always correct capitalization issues.

It seems the keyword normalization is working correctly from the API perspective, but Plex's internal
Database handling affects the final display. This can still provide some value through duplicate removal and
consistent formatting, even if Plex's internal behavior controls final capitalization.

@nullable-eth
Copy link
Owner

After further googling, this appears to be a known Plex behavior. A forum thread (https://forums.plex.tv/t/can-i-fix-genre-naming-capitalization/193058) shows a user experiencing similar issues where Plex persisted lowercase genres despite API updates, requiring database optimization to fix.

The forum discussion hints that Plex can be a pain to maintain specific metadata at the database level. Standard metadata refreshes may not always correct capitalization issues.

It seems the keyword normalization is working correctly from the API perspective, but Plex's internal Database handling affects the final display. This can still provide some value through duplicate removal and consistent formatting, even if Plex's internal behavior controls final capitalization.

Agreed along with the acronym standardization, LGTM.

I'll merge.

@nullable-eth nullable-eth merged commit 0b7f64e into nullable-eth:main Jul 6, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants