Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mcp_plex/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def resolve_tmdb_season_number(

parent_index = getattr(episode, "parentIndex", None)
parent_title = getattr(episode, "parentTitle", None)
parent_year = getattr(episode, "parentYear", None)
if parent_year is None:
parent_year = getattr(episode, "year", None)

seasons = getattr(show_tmdb, "seasons", []) if show_tmdb else []

Expand All @@ -195,7 +198,9 @@ def resolve_tmdb_season_number(

# match by air date year when Plex uses year-based seasons
year: Optional[int] = None
if isinstance(parent_index, int):
if isinstance(parent_year, int):
year = parent_year
elif isinstance(parent_index, int):
year = parent_index
elif title_norm and title_norm.isdigit():
year = int(title_norm)
Expand All @@ -207,7 +212,9 @@ def resolve_tmdb_season_number(
if int(air[:4]) == year:
return season.season_number

if parent_index is not None:
if isinstance(parent_index, int):
return parent_index
if isinstance(parent_index, str) and parent_index.isdigit():
return int(parent_index)
if isinstance(parent_title, str) and parent_title.isdigit():
return int(parent_title)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "mcp-plex"
version = "0.26.17"
version = "0.26.18"

description = "Plex-Oriented Model Context Protocol Server"
requires-python = ">=3.11,<3.13"
Expand Down
14 changes: 14 additions & 0 deletions tests/test_loader_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,17 @@ def test_resolve_tmdb_season_number_matches_air_date():
seasons=[TMDBSeason(season_number=16, name="Season 16", air_date="2018-01-03")],
)
assert resolve_tmdb_season_number(show, episode) == 16


def test_resolve_tmdb_season_number_parent_year_fallback():
episode = types.SimpleNamespace(
parentIndex="Special",
parentTitle="Special",
parentYear=2018,
)
show = TMDBShow(
id=1,
name="Show",
seasons=[TMDBSeason(season_number=5, name="Season 5", air_date="2018-06-01")],
)
assert resolve_tmdb_season_number(show, episode) == 5
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.