Skip to content

Media Server Abstraction: PlexLibraryItem → MediaItem Migration#8

Closed
enoch85 wants to merge 5 commits into
jellyfin-type-consolidationfrom
rules-engine-mediaitem-migration
Closed

Media Server Abstraction: PlexLibraryItem → MediaItem Migration#8
enoch85 wants to merge 5 commits into
jellyfin-type-consolidationfrom
rules-engine-mediaitem-migration

Conversation

@enoch85

@enoch85 enoch85 commented Jan 1, 2026

Copy link
Copy Markdown
Owner

Media Server Abstraction: PlexLibraryItem → MediaItem Migration

Summary

Migrates core services from Plex-specific PlexLibraryItem to server-agnostic MediaItem, enabling rules, collections, and media lookups to work with both Plex and Jellyfin.

Property Mappings

Plex Jellyfin MediaItem
ratingKey Id id
parentRatingKey ParentId parentId
grandparentRatingKey SeriesId grandparentId
EPlexDataType.* BaseItemKind.* 'movie'/'show'/'season'/'episode'
Guid[] array ProviderIds object providerIds
index IndexNumber index
parentIndex ParentIndexNumber parentIndex

Logical Changes

  1. getGuidFromPlexLibItem helper removed — Had a fallback to parse guid string for provider IDs, but per Plex API spec guid is always plex://... format. Provider IDs (imdb://, tmdb://, tvdb://) only appear in the Guid array, now normalized to providerIds by adapters.

  2. Season number extracted to variable — Duplicated ternary dataType === 'season' ? origLibItem.index : origLibItem.parentIndex now computed once and reused in API call and log message. Logic unchanged.

  3. Media server abstractionPlexApiService methods replaced with MediaServerFactory.getService() calls throughout rules engine:

    • RuleExecutorService: getLibraryContents()
    • CollectionsService: UpdateCollectionSettings(), getAllIdsForContextAction()
    • RulesService: getAllIdsForContextAction(), getMetadata()
  4. getAllIdsForContextAction() abstracted — New IMediaServerService method for show→season→episode traversal. Implemented in both Plex and Jellyfin adapters.

  5. getTmdbIdFromPlexData removed — Deprecated method with no callers. getTmdbIdFromMediaItem handles all provider ID lookups via normalized providerIds.

Testing

✅ 394 tests pass · ✅ Types check · ✅ Build succeeds

@enoch85 enoch85 force-pushed the rules-engine-mediaitem-migration branch from 7489e80 to 09b8944 Compare January 1, 2026 14:12
BREAKING CHANGE: Rules engine now uses server-agnostic MediaItem type

This migration enables the rules engine to work with both Plex and Jellyfin
by replacing Plex-specific types with the abstracted MediaItem type.

Key changes:
- rule-executor.service: Uses MediaServerFactory instead of PlexApiService
- rule.comparator.service: Updated types and property mappings
- All getter services: Accept MediaItem, use abstracted media server
- sonarr-getter: New findTvdbidFromMediaItem using normalized providerIds

Property mappings:
- ratingKey → id
- parentRatingKey → parentId
- grandparentRatingKey → grandparentId
- EPlexDataType enums → MediaItemType strings

The original guid string fallback in findTvdbidFromPlexLibItem was removed
as it was dead code - per Plex API spec, guid is always plex://... format,
provider IDs (imdb/tmdb/tvdb) only appear in the Guid array.

Also updates docker/Dockerfile.dev to use this branch.
@enoch85 enoch85 force-pushed the rules-engine-mediaitem-migration branch from 09b8944 to b053e53 Compare January 1, 2026 14:18
… abstraction

- Add getAllIdsForContextAction() to IMediaServerService interface
- Implement in PlexAdapterService and JellyfinAdapterService
- Migrate CollectionsService: remove PlexApiService dependency
- Migrate RulesService: 5 getAllIdsForContextAction + 3 getMetadata calls
- Remove PlexMapper imports from both services
- Remove unused PlexMetadata, PlexLibraryItem imports
- Remove deprecated getTmdbIdFromPlexData method (no callers)
- getTmdbIdFromMediaItem handles all provider ID lookups via normalized providerIds
@enoch85 enoch85 changed the title refactor(rules): migrate rules engine from PlexLibraryItem to MediaItem Media Server Abstraction: PlexLibraryItem → MediaItem Migration Jan 1, 2026
- Replace direct PlexApiService.getCorrectedUsers() calls with IMediaServerService.getUsers()
- Add resolveRequestUsername() helper to handle different user types:
  - Local users (userType 2) → username directly
  - Jellyfin/Emby users (userType 3/4) → jellyfinUsername directly
  - Plex users → lookup via media server abstraction
- Lazy load users only when needed for Plex user lookup
- Add REMAINING_ISSUES.md documenting implementation status

This makes both getter services work correctly regardless of which
media server (Plex or Jellyfin) is configured.
…-getters

fix: remove PlexApiService dependency from Overseerr/Jellyseerr getters

enoch85 commented Jan 3, 2026

Copy link
Copy Markdown
Owner Author

Closing in favor of consolidated PR #24 (jellyfin-dev branch). All changes are included there.

@enoch85 enoch85 closed this Jan 3, 2026
enoch85 added a commit that referenced this pull request Jan 31, 2026
…switch

Added a switchInProgress flag that:
- Prevents concurrent switch operations from starting
- Blocks factory.getService() calls during the switch
- Is always released in a finally block

This prevents API requests from routing to the wrong adapter during
the window between settings update and server initialization.

Fixes review item #8.
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.

1 participant