Skip to content

Map studio/site into Plex Collection tags (with dedupe) and cover performer role thumbs - #3

Merged
adeze merged 2 commits into
mainfrom
copilot/update-plex-collections-mapping
Jun 4, 2026
Merged

Map studio/site into Plex Collection tags (with dedupe) and cover performer role thumbs#3
adeze merged 2 commits into
mainfrom
copilot/update-plex-collections-mapping

Conversation

Copilot AI commented Jun 4, 2026

Copy link
Copy Markdown

This updates the in-progress TPDB→Plex mapping fix so studio/site is also emitted as a Plex Collection tag in both match and full metadata payloads. It preserves existing studio behavior and avoids duplicate collection entries when studio already appears in series/collection/franchise data.

  • Collection mapping update

    • Updated provider/mappers/tpdb_to_plex.py to include _get_studio(scene) in _get_collections(scene).
    • Reuses existing seen-based dedupe, so studio is only added once even if already present in incoming collection fields.
    • Because both map_scene_to_match(...) and map_scene_to_metadata(...) consume _get_collections(scene), the behavior is consistent across both endpoints.
  • Studio field compatibility

    • Kept current studio field population unchanged in match/metadata output.
    • Change is additive: studio remains in studio and is now also available in Collection for Plex browsing workflows.
  • Test coverage additions

    • Extended tests/test_tpdb_enrichment.py to assert:
      • studio is present in Collection for metadata output,
      • studio is deduped when already present in collection-like fields,
      • performer images map to Role[].thumb,
      • performers without images still map cleanly without thumb data.
def _get_collections(scene: dict[str, Any]) -> list[dict[str, str]]:
    candidates = []
    for key in ("collections", "collection", "series", "franchise", "franchises"):
        ...
    studio = _get_studio(scene)
    if studio:
        candidates.append(studio)
    ...
Original prompt

Update the in-progress fix for adeze/plex-tpdb-scanner to also map the studio/site name into Plex collections.

Additional requirement from the user:

  • Map the Studio tag to Collections because that is more functional for their Plex usage.

Repository context already identified:

  • TPDB-to-Plex mapping lives in provider/mappers/tpdb_to_plex.py
  • _get_studio(scene) extracts the studio/site name
  • _get_collections(scene) extracts collection/series/franchise names
  • map_scene_to_match(...) and map_scene_to_metadata(...) currently set studio separately and populate Collection from _get_collections(scene) only

Please implement the following in the PR:

  1. Ensure the studio/site name is included in Plex Collection output for both match results and full metadata.
  2. Avoid duplicates if the studio/site name is already present in collections.
  3. Preserve current studio field behavior unless there is a strong compatibility reason not to.
  4. Update or add tests to cover the studio-to-collection mapping behavior.
  5. Keep the implementation simple and consistent with the existing Python style in the repo.

This should be added to the existing PR/task work rather than creating a separate unrelated change.

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-Language=en-US HTTP/1.1" 404 Not Found

2026-06-04 07:09:19,450 - provider.main - INFO - >>> REQUEST: GET /library/metadata/vrmassaged-fit-redhead-is-craving-your-dick-pt2/images

2026-06-04 07:09:19,451 - provider.main - INFO - <<< RESPONSE: GET /library/metadata/vrmassaged-fit-redhead-is-craving-your-dick-pt2/images -> 404

INFO:     172.67.149.54:56456 - "GET /library/metadata/vrmassaged-fit-redhead-is-craving-your-dick-pt2/images?X-Plex-Country=US&X-Plex-Language=en-US HTTP/1.1" 404 Not Found

shouldn't it be looking for the uuid or something?

Assistant: Yes — I think you found a real bug.

Short version: Plex is requesting:

GET /library/metadata/<slug>/images

but this repo only implements:

GET /library/metadata/{rating_key}
POST /library/metadata/matches
GET /

So the 404...

This pull request was created from Copilot chat.

@adeze
adeze marked this pull request as ready for review June 4, 2026 08:11
Copilot AI review requested due to automatic review settings June 4, 2026 08:11
@adeze
adeze merged commit ab463ba into main Jun 4, 2026
@adeze

adeze commented Jun 4, 2026

Copy link
Copy Markdown
Owner

ok can you ensure the performers images are being downloaded too ?

@adeze
adeze deleted the copilot/update-plex-collections-mapping branch June 4, 2026 08:12
Copilot AI changed the title [WIP] Update studio name mapping into Plex collections Map studio/site into Plex Collection tags (with dedupe) and cover performer role thumbs Jun 4, 2026
Copilot finished work on behalf of adeze June 4, 2026 08:12
Copilot AI requested a review from adeze June 4, 2026 08:12

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 updates the TPDB→Plex mapping to also include the TPDB studio/site name in Plex Collection tags (while preserving the existing studio field), and adds/updates tests to verify the new behavior and deduplication.

Changes:

  • Include studio/site name in _get_collections(...) so both match results and full metadata emit it via Collection.
  • Deduplicate studio vs existing collection/series/franchise names.
  • Update/add tests to assert studio-to-collection mapping and dedupe behavior.

Reviewed changes

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

File Description
provider/mappers/tpdb_to_plex.py Appends extracted studio/site name into the collections candidate set (deduped) so it flows into Collection for match + metadata.
tests/test_tpdb_enrichment.py Updates existing metadata collection expectations and adds a new test covering studio→collection dedupe in match mapping.

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

Comment on lines +172 to +174
studio = _get_studio(scene)
if studio:
candidates.append(studio)
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