Skip to content

Align TPDB scene mapping with Plex Metadata Response (adult flag, actor identity, external GUIDs) - #2

Merged
adeze merged 7 commits into
mainfrom
copilot/fix-plex-image-handling
Jun 4, 2026
Merged

Align TPDB scene mapping with Plex Metadata Response (adult flag, actor identity, external GUIDs)#2
adeze merged 7 commits into
mainfrom
copilot/fix-plex-image-handling

Conversation

Copilot AI commented Jun 4, 2026

Copy link
Copy Markdown

This PR closes gaps between TPDB payloads and Plex’s richer metadata contract: explicit adult classification, stronger performer→actor identity mapping, and external ID mappings for faster/more-accurate cross-provider matching.

  • Adult-content classification

    • Set isAdult unconditionally in mapped scene outputs to reflect TPDB-only adult content.
    • Applied to both match payloads and full metadata payloads.
  • External identifier mapping (Guid array)

    • Added Guid entries in Plex format (provider://id) sourced from TPDB scene fields and nested ID containers.
    • Supports Plex-native providers (imdb, tmdb, tvdb) plus TPDB-native identity (tpdb://...) for stable internal linkage.
  • Performer → Plex Role enrichment

    • Extended Role entries with stable performer IDs (tpdb://performer/{id-or-slug}), in addition to existing tag/thumb mapping.
    • Preserves deterministic precedence when both id and slug are present.
  • Coverage updates for new contract behavior

    • Added assertions for hardcoded isAdult, Guid emission, performer ID precedence, and empty-image metadata response behavior.
# example mapped metadata excerpt
{
  "isAdult": 1,
  "Guid": [
    {"id": "imdb://tt1234567"},
    {"id": "tmdb://98765"},
    {"id": "tpdb://123"}
  ],
  "Role": [
    {"tag": "Performer", "id": "tpdb://performer/p1", "thumb": "https://img/p.jpg"}
  ]
}
Original prompt

Fix Plex image handling in the repository adeze/plex-tpdb-scanner.

Problem:

  • Plex is requesting GET /library/metadata/{rating_key}/images and the provider currently returns 404 because no such route exists.
  • The provider currently implements only:
    • GET /
    • POST /library/metadata/matches
    • GET /library/metadata/{rating_key}
  • Match and metadata payloads currently use the TPDB scene slug as ratingKey/key, which is acceptable in the current design; the immediate bug is the missing /images endpoint.

Repository context:

  • FastAPI app in provider/main.py
  • Existing metadata route in provider/routes/metadata.py
  • Metadata fetching logic in provider/services/metadata_service.py
  • TPDB-to-Plex mapping helpers in provider/mappers/tpdb_to_plex.py
  • TPDB API client in metadata_tool/api.py

Please implement a proper fix with code changes and open a pull request.

Requirements:

  1. Add support for GET /library/metadata/{rating_key}/images.
  2. Reuse existing metadata/service/mapping code where practical; prefer existing project patterns and well-known libraries already in the repo.
  3. Fetch the scene by rating_key (currently TPDB slug), hydrate as needed, and return Plex-compatible image data for poster/thumb/art/background if available.
  4. Avoid breaking current /library/metadata/{rating_key} behavior.
  5. If appropriate, add a small helper/service function to centralize image extraction from TPDB scene payloads.
  6. Add or update tests covering the new route and a successful non-404 response when scene images exist; also cover the not-found case.
  7. Keep implementation straightforward and Pythonic.

Docs to align with:

  • Plex metadata provider docs referenced by the user: https://developer.plex.tv/pms/index.html#section/API-Info/Metadata-Providers
  • TPDB API docs referenced by the user: https://api.theporndb.net/docs

Expected outcome:

  • A PR against main that fixes the missing images endpoint so Plex no longer gets 404 for /library/metadata/{rating_key}/images when metadata is present.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: how do i rebuild the container via docker compose?

Assistant: From the repo root, run:

docker compose up -d --build

That works because docker-compose.yml uses build: . for the tpdb-provider service, so Compose will rebuild the image from the local Dockerfile and recreate the container.

If you want to force a clean rebuild, use:

docker compose build --no-cache
docker compose up -d

Or in one go:

docker compose up -d --build --force-recreate

A few repo-specific notes:

  • docker-compose.yml is the file to use for local rebuilds.
  • docker-compose.portainer.yml uses a prebuilt image (ghcr.io/mystrock/plex-tpdb-scanner:latest), so that one does not rebuild from your local source.
  • You’ll also need TPDB_API_KEY set in your shell or a .env file before starting.

Typical flow:

git clone https://github.com/adeze/plex-tpdb-scanner.git
cd plex-tpdb-scanner
export TPDB_API_KEY=your_api_key_here
docker compose up -d --build

To verify it came back up:

docker compose ps
docker compose logs -f

If you want, I can also show you the best docker compose workflow for Apple Silicon specifically, including when to use --no-cache, down, and volume cleanup.

User: do i need to turn off the current running container? how?

Assistant: Yes — usually you should stop and remove the currently running container before bringing up the rebuilt one, though docker compose up -d --build will often recreate it for you automatically.

Simplest safe approach from the repo directory:

docker compose down
docker compose up -d --build

What these do:

  • docker compose down stops and removes the existing container, network, and Compose-managed resources.
  • docker compose up -d --build rebuilds the image and starts a fresh container in the background.

If you want minimal steps, this is often enough by itself:

docker compose up -d --build

Compose will detect the config/image change and replace the running container.

If you specifically want to stop just the running service first:

docker compose stop
docker compose rm -f
docker compose up -d --build

Useful checks:

docker compose ps
docker compose logs -f tpdb-provider

If the old container was started outside Compose, remove it manually:

docker stop tpdb-provider
docker rm tpdb-provider

Recommended for your case: use this sequence:

cd plex-tpdb-scanner
docker compose down
docker compose up -d --build

If you want, I can give you the exact command sequence for macOS zsh with your TPDB_API_KEY included.

User: i think there's an error since the logs show:

INFO:     172.67.149.54:31411 - "GET /library/metadata/vrmassaged-fit-redhead-is-craving-your-dick-pt2/images?X-Plex-Country=US&X-Plex...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

Copilot AI changed the title [WIP] Fix Plex image handling by adding missing images endpoint Add /library/metadata/{rating_key}/images endpoint for Plex image lookups Jun 4, 2026
Copilot finished work on behalf of adeze June 4, 2026 07:17
Copilot AI requested a review from adeze June 4, 2026 07:17
Copilot finished work on behalf of adeze June 4, 2026 07:19
Copilot finished work on behalf of adeze June 4, 2026 07:21
Copilot AI changed the title Add /library/metadata/{rating_key}/images endpoint for Plex image lookups Add legacy TPDB image-field compatibility for scene art and performer photos Jun 4, 2026
Copilot finished work on behalf of adeze June 4, 2026 07:27
Copilot finished work on behalf of adeze June 4, 2026 07:28
Copilot AI changed the title Add legacy TPDB image-field compatibility for scene art and performer photos Improve TPDB image compatibility and mapper output quality for scenes/actors Jun 4, 2026
Copilot finished work on behalf of adeze June 4, 2026 07:31
Copilot finished work on behalf of adeze June 4, 2026 07:33
Copilot AI changed the title Improve TPDB image compatibility and mapper output quality for scenes/actors Align TPDB scene mapping with Plex Metadata Response (adult flag, actor identity, external GUIDs) Jun 4, 2026
Copilot finished work on behalf of adeze June 4, 2026 07:45
@adeze
adeze marked this pull request as ready for review June 4, 2026 07:48
Copilot AI review requested due to automatic review settings June 4, 2026 07:48
@adeze
adeze merged commit 84b254f into main Jun 4, 2026
1 check passed
Copilot finished work on behalf of adeze June 4, 2026 07:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR expands the TPDB→Plex mapping layer and provider API surface to better match Plex’s metadata expectations by adding an /images endpoint, enriching performer identity in Role, emitting external GUID mappings, and explicitly flagging adult content.

Changes:

  • Added GET /library/metadata/{rating_key}/images plus supporting MetadataService.get_images() and scene→image-entry mapping.
  • Extended scene mapping to always emit isAdult = 1, add external Guid entries (imdb/tmdb/tvdb/tpdb), and add stable performer Role.id values.
  • Updated and added tests covering the new mapping behavior and the /images route responses.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
provider/mappers/tpdb_to_plex.py Adds scene image extraction + /images mapping, GUID emission, adult flag, and richer performer role identity mapping.
provider/services/metadata_service.py Centralizes get_scene() hydration and adds get_images() for the new route.
provider/services/match_service.py Expands “has image” detection to include face fields during hydration decisions.
provider/routes/metadata.py Adds the new GET /library/metadata/{rating_key}/images endpoint.
provider/routes/manifest.py Advertises the images feature in the provider manifest.
tests/test_tpdb_enrichment.py Adds assertions for adult/GUID/role-id behavior and new map_scene_to_images() behavior.
tests/test_metadata_routes.py Introduces route-level tests for the new /images endpoint behavior (200/404/empty).
README.md Documents the new /library/metadata/{id}/images endpoint.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +117 to +139
image_entries = []
seen_urls: set[str] = set()
for image_type, image_url in scene_images.items():
if image_url in seen_urls:
logger.debug(
"Skipping duplicate image url for scene=%s type=%s url=%s",
slug,
image_type,
image_url,
)
continue
seen_urls.add(image_url)
image_entries.append(
{
"type": image_type,
"url": image_url,
"key": f"/library/metadata/{slug}/images/{image_type}",
"ratingKey": slug,
"provider": "tv.plex.agents.custom.tpdb",
}
)

return image_entries
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.

3 participants