mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-07 10:14:13 -04:00
Fix entries fetching when first ep of season is not 1
This commit is contained in:
parent
720e0e6975
commit
b207cc77fd
@ -1,6 +1,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from pydantic import Field
|
||||||
|
|
||||||
from ..utils import Language, Model
|
from ..utils import Language, Model
|
||||||
from .metadataid import SeasonId
|
from .metadataid import SeasonId
|
||||||
@ -12,6 +15,7 @@ class Season(Model):
|
|||||||
end_air: date | None
|
end_air: date | None
|
||||||
external_id: dict[str, SeasonId]
|
external_id: dict[str, SeasonId]
|
||||||
translations: dict[Language, SeasonTranslation] = {}
|
translations: dict[Language, SeasonTranslation] = {}
|
||||||
|
extra: dict[str, Any] = Field(exclude=True)
|
||||||
|
|
||||||
|
|
||||||
class SeasonTranslation(Model):
|
class SeasonTranslation(Model):
|
||||||
|
@ -278,6 +278,13 @@ class TheMovieDatabase(Provider):
|
|||||||
"append_to_response": "alternative_titles,videos,credits,keywords,images,external_ids,translations",
|
"append_to_response": "alternative_titles,videos,credits,keywords,images,external_ids,translations",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
seasons = await asyncio.gather(
|
||||||
|
*[
|
||||||
|
self._get_season(serie["id"], x["season_number"])
|
||||||
|
for x in serie["seasons"]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
entries = await self._get_all_entries(serie["id"], seasons)
|
||||||
|
|
||||||
return Serie(
|
return Serie(
|
||||||
slug=to_slug(serie["name"]),
|
slug=to_slug(serie["name"]),
|
||||||
@ -364,13 +371,8 @@ class TheMovieDatabase(Provider):
|
|||||||
)
|
)
|
||||||
for trans in serie["translations"]["translations"]
|
for trans in serie["translations"]["translations"]
|
||||||
},
|
},
|
||||||
seasons=await asyncio.gather(
|
seasons=seasons,
|
||||||
*[
|
entries=entries,
|
||||||
self._get_season(serie["id"], x["season_number"])
|
|
||||||
for x in serie["seasons"]
|
|
||||||
]
|
|
||||||
),
|
|
||||||
entries=await self._get_all_entries(serie["id"], serie["seasons"]),
|
|
||||||
extra=[],
|
extra=[],
|
||||||
collections=[],
|
collections=[],
|
||||||
studios=[self._map_studio(x) for x in serie["production_companies"]],
|
studios=[self._map_studio(x) for x in serie["production_companies"]],
|
||||||
@ -411,17 +413,23 @@ class TheMovieDatabase(Provider):
|
|||||||
)
|
)
|
||||||
for trans in season["translations"]["translations"]
|
for trans in season["translations"]["translations"]
|
||||||
},
|
},
|
||||||
|
extra={
|
||||||
|
"first_entry": next(
|
||||||
|
(x["episode_number"] for x in season["episodes"]), None
|
||||||
|
),
|
||||||
|
"entries_count": len(season["episodes"]),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _get_all_entries(
|
async def _get_all_entries(
|
||||||
self, serie_id: str | int, seasons: list[dict[str, Any]]
|
self, serie_id: str | int, seasons: list[Season]
|
||||||
) -> list[Entry]:
|
) -> list[Entry]:
|
||||||
# TODO: batch those
|
# TODO: batch those
|
||||||
ret = await asyncio.gather(
|
ret = await asyncio.gather(
|
||||||
*[
|
*[
|
||||||
self._get_entry(serie_id, s["season_number"], e)
|
self._get_entry(serie_id, s.season_number, s.extra["first_entry"] + e)
|
||||||
for s in seasons
|
for s in seasons
|
||||||
for e in range(1, s["episode_count"])
|
for e in range(0, s.extra["entries_count"])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -449,33 +457,23 @@ class TheMovieDatabase(Provider):
|
|||||||
# one piece's s22e1089 is the first ep of s22.
|
# one piece's s22e1089 is the first ep of s22.
|
||||||
# this is because episode_numbers simply don't reset after season start
|
# this is because episode_numbers simply don't reset after season start
|
||||||
# (eg s21e1088 is the last ep of s21)
|
# (eg s21e1088 is the last ep of s21)
|
||||||
season_starts = [
|
season_starts = [s.extra["first_entry"] for s in seasons]
|
||||||
next(
|
|
||||||
(
|
|
||||||
x["episode_number"]
|
|
||||||
for x in episodes
|
|
||||||
if x["season_number"] == s["season_number"]
|
|
||||||
),
|
|
||||||
1,
|
|
||||||
)
|
|
||||||
for s in seasons
|
|
||||||
]
|
|
||||||
|
|
||||||
if len(episodes) != len(ret):
|
if len(episodes) != len(ret):
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"Incomplete absolute group for show {serie_id}. Filling missing values by assuming season/episode order is ascending."
|
f"Incomplete absolute group for show {serie_id}. Filling missing values by assuming season/episode order is ascending."
|
||||||
)
|
)
|
||||||
episodes += [
|
episodes += [
|
||||||
{"season_number": s["season_number"], "episode_number": e}
|
{"season_number": s.season_number, "episode_number": e}
|
||||||
for s in seasons
|
for s in seasons
|
||||||
for e in range(1, s["episodes_count"] + 1)
|
for e in range(1, s.extra["entries_count"] + 1)
|
||||||
if not any(
|
if not any(
|
||||||
x["season_number"] == s["season_number"]
|
x["season_number"] == s.season_number
|
||||||
and (
|
and (
|
||||||
x["episode_number"] == e
|
x["episode_number"] == e
|
||||||
# take into account weird absolute (for example one piece, episodes are not reset to 1 when the season starts)
|
# take into account weird absolute (for example one piece, episodes are not reset to 1 when the season starts)
|
||||||
or x["episode_number"]
|
or x["episode_number"]
|
||||||
== season_starts[s["season_number"] - 1] + e
|
== season_starts[s.season_number - 1] + e
|
||||||
)
|
)
|
||||||
for x in episodes
|
for x in episodes
|
||||||
)
|
)
|
||||||
|
@ -143,7 +143,7 @@ class RequestProcessor:
|
|||||||
returning
|
returning
|
||||||
videos
|
videos
|
||||||
""",
|
""",
|
||||||
[request.pk],
|
request.pk,
|
||||||
)
|
)
|
||||||
if finished and finished["videos"] != request.videos:
|
if finished and finished["videos"] != request.videos:
|
||||||
await self._client.link_videos(show.slug, finished["videos"])
|
await self._client.link_videos(show.slug, finished["videos"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user