mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Handle missing translations for episodes or seasons
This commit is contained in:
parent
ca7dd81452
commit
f8c6602604
@ -1,8 +1,9 @@
|
||||
import os
|
||||
from datetime import date
|
||||
from dataclasses import dataclass, field, asdict
|
||||
from typing import Optional
|
||||
|
||||
from providers.utils import select_translation
|
||||
|
||||
from .show import Show
|
||||
from .metadataid import MetadataID
|
||||
|
||||
@ -24,8 +25,8 @@ class EpisodeID:
|
||||
|
||||
@dataclass
|
||||
class EpisodeTranslation:
|
||||
name: str
|
||||
overview: Optional[str]
|
||||
name: Optional[str]
|
||||
overview: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -45,10 +46,9 @@ class Episode:
|
||||
translations: dict[str, EpisodeTranslation] = field(default_factory=dict)
|
||||
|
||||
def to_kyoo(self):
|
||||
# For now, the API of kyoo only support one language so we remove the others.
|
||||
default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0]
|
||||
trans = select_translation(self) or EpisodeTranslation("")
|
||||
return {
|
||||
**asdict(self),
|
||||
**asdict(self.translations[default_language]),
|
||||
**asdict(trans),
|
||||
"show": None,
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
import os
|
||||
from datetime import date
|
||||
from dataclasses import dataclass, field, asdict
|
||||
from typing import Optional
|
||||
|
||||
from providers.utils import select_translation, select_image
|
||||
|
||||
from .metadataid import MetadataID
|
||||
|
||||
|
||||
@ -28,13 +29,10 @@ class Season:
|
||||
translations: dict[str, SeasonTranslation] = field(default_factory=dict)
|
||||
|
||||
def to_kyoo(self):
|
||||
# For now, the API of kyoo only support one language so we remove the others.
|
||||
default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0]
|
||||
trans = select_translation(self) or SeasonTranslation()
|
||||
return {
|
||||
**asdict(self),
|
||||
**asdict(self.translations[default_language]),
|
||||
"poster": next(iter(self.translations[default_language].posters), None),
|
||||
"thumbnail": next(
|
||||
iter(self.translations[default_language].thumbnails), None
|
||||
),
|
||||
**asdict(trans),
|
||||
"poster": select_image(self, "posters"),
|
||||
"thumbnail": select_image(self, "thumbnails"),
|
||||
}
|
||||
|
@ -3,10 +3,15 @@ from __future__ import annotations
|
||||
import os
|
||||
from datetime import date
|
||||
|
||||
from typing import Literal
|
||||
from typing import Literal, Any
|
||||
|
||||
from providers.types.movie import Movie
|
||||
from providers.types.show import Show
|
||||
from providers.types.season import Season
|
||||
from providers.types.episode import Episode
|
||||
from providers.types.collection import Collection
|
||||
|
||||
type Resource = Movie | Show | Season | Episode | Collection
|
||||
|
||||
|
||||
def format_date(date: date | int | None) -> str | None:
|
||||
@ -21,9 +26,10 @@ def format_date(date: date | int | None) -> str | None:
|
||||
default_languages = os.environ["LIBRARY_LANGUAGES"].split(",")
|
||||
|
||||
|
||||
def select_translation(value: Movie | Show, *, prefer_orginal=False):
|
||||
def select_translation(value: Resource, *, prefer_orginal=False) -> Any:
|
||||
if (
|
||||
prefer_orginal
|
||||
and (isinstance(value, Movie) or isinstance(value, Show))
|
||||
and value.original_language
|
||||
and value.original_language in value.translations
|
||||
):
|
||||
@ -35,7 +41,7 @@ def select_translation(value: Movie | Show, *, prefer_orginal=False):
|
||||
|
||||
|
||||
def select_image(
|
||||
value: Movie | Show,
|
||||
value: Resource,
|
||||
kind: Literal["posters"] | Literal["thumbnails"] | Literal["logos"],
|
||||
) -> str | None:
|
||||
trans = select_translation(value, prefer_orginal=True) or next(
|
||||
|
Loading…
x
Reference in New Issue
Block a user