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 datetime import date
|
||||||
from dataclasses import dataclass, field, asdict
|
from dataclasses import dataclass, field, asdict
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from providers.utils import select_translation
|
||||||
|
|
||||||
from .show import Show
|
from .show import Show
|
||||||
from .metadataid import MetadataID
|
from .metadataid import MetadataID
|
||||||
|
|
||||||
@ -24,8 +25,8 @@ class EpisodeID:
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class EpisodeTranslation:
|
class EpisodeTranslation:
|
||||||
name: str
|
name: Optional[str]
|
||||||
overview: Optional[str]
|
overview: Optional[str] = None
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -45,10 +46,9 @@ class Episode:
|
|||||||
translations: dict[str, EpisodeTranslation] = field(default_factory=dict)
|
translations: dict[str, EpisodeTranslation] = field(default_factory=dict)
|
||||||
|
|
||||||
def to_kyoo(self):
|
def to_kyoo(self):
|
||||||
# For now, the API of kyoo only support one language so we remove the others.
|
trans = select_translation(self) or EpisodeTranslation("")
|
||||||
default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0]
|
|
||||||
return {
|
return {
|
||||||
**asdict(self),
|
**asdict(self),
|
||||||
**asdict(self.translations[default_language]),
|
**asdict(trans),
|
||||||
"show": None,
|
"show": None,
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import os
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from dataclasses import dataclass, field, asdict
|
from dataclasses import dataclass, field, asdict
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from providers.utils import select_translation, select_image
|
||||||
|
|
||||||
from .metadataid import MetadataID
|
from .metadataid import MetadataID
|
||||||
|
|
||||||
|
|
||||||
@ -28,13 +29,10 @@ class Season:
|
|||||||
translations: dict[str, SeasonTranslation] = field(default_factory=dict)
|
translations: dict[str, SeasonTranslation] = field(default_factory=dict)
|
||||||
|
|
||||||
def to_kyoo(self):
|
def to_kyoo(self):
|
||||||
# For now, the API of kyoo only support one language so we remove the others.
|
trans = select_translation(self) or SeasonTranslation()
|
||||||
default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0]
|
|
||||||
return {
|
return {
|
||||||
**asdict(self),
|
**asdict(self),
|
||||||
**asdict(self.translations[default_language]),
|
**asdict(trans),
|
||||||
"poster": next(iter(self.translations[default_language].posters), None),
|
"poster": select_image(self, "posters"),
|
||||||
"thumbnail": next(
|
"thumbnail": select_image(self, "thumbnails"),
|
||||||
iter(self.translations[default_language].thumbnails), None
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,15 @@ from __future__ import annotations
|
|||||||
import os
|
import os
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from typing import Literal
|
from typing import Literal, Any
|
||||||
|
|
||||||
from providers.types.movie import Movie
|
from providers.types.movie import Movie
|
||||||
from providers.types.show import Show
|
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:
|
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(",")
|
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 (
|
if (
|
||||||
prefer_orginal
|
prefer_orginal
|
||||||
|
and (isinstance(value, Movie) or isinstance(value, Show))
|
||||||
and value.original_language
|
and value.original_language
|
||||||
and value.original_language in value.translations
|
and value.original_language in value.translations
|
||||||
):
|
):
|
||||||
@ -35,7 +41,7 @@ def select_translation(value: Movie | Show, *, prefer_orginal=False):
|
|||||||
|
|
||||||
|
|
||||||
def select_image(
|
def select_image(
|
||||||
value: Movie | Show,
|
value: Resource,
|
||||||
kind: Literal["posters"] | Literal["thumbnails"] | Literal["logos"],
|
kind: Literal["posters"] | Literal["thumbnails"] | Literal["logos"],
|
||||||
) -> str | None:
|
) -> str | None:
|
||||||
trans = select_translation(value, prefer_orginal=True) or next(
|
trans = select_translation(value, prefer_orginal=True) or next(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user