mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Improve image selection and prefer original language one
This commit is contained in:
parent
5c8c7b8804
commit
8a3a2fecf5
@ -7,7 +7,6 @@ from enum import Enum
|
||||
from .genre import Genre
|
||||
from .studio import Studio
|
||||
from .metadataid import MetadataID
|
||||
from ..utils import format_date
|
||||
|
||||
|
||||
class Status(str, Enum):
|
||||
@ -45,16 +44,15 @@ class Movie:
|
||||
translations: dict[str, MovieTranslation] = field(default_factory=dict)
|
||||
|
||||
def to_kyoo(self):
|
||||
from ..utils import select_image
|
||||
# For now, the API of kyoo only support one language so we remove the others.
|
||||
default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0]
|
||||
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
|
||||
),
|
||||
"logo": next(iter(self.translations[default_language].logos), None),
|
||||
"poster": select_image(self, "posters"),
|
||||
"thumbnail": select_image(self, "thumbnails"),
|
||||
"logo": select_image(self, "logos"),
|
||||
"trailer": next(iter(self.translations[default_language].trailers), None),
|
||||
"studio": next((x.to_kyoo() for x in self.studios), None),
|
||||
"genres": [x.to_kyoo() for x in self.genres],
|
||||
|
@ -47,6 +47,7 @@ class Show:
|
||||
translations: dict[str, ShowTranslation] = field(default_factory=dict)
|
||||
|
||||
def to_kyoo(self):
|
||||
from providers.utils import select_image
|
||||
# For now, the API of kyoo only support one language so we remove the others.
|
||||
default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0]
|
||||
return {
|
||||
@ -54,11 +55,9 @@ class Show:
|
||||
**asdict(self.translations[default_language]),
|
||||
"studio": next((x.to_kyoo() for x in self.studios), None),
|
||||
"seasons": None,
|
||||
"poster": next(iter(self.translations[default_language].posters), None),
|
||||
"thumbnail": next(
|
||||
iter(self.translations[default_language].thumbnails), None
|
||||
),
|
||||
"logo": next(iter(self.translations[default_language].logos), None),
|
||||
"poster": select_image(self, "posters"),
|
||||
"thumbnail": select_image(self, "thumbnails"),
|
||||
"logo": select_image(self, "logos"),
|
||||
"trailer": next(iter(self.translations[default_language].trailers), None),
|
||||
"genres": [x.to_kyoo() for x in self.genres],
|
||||
}
|
||||
|
@ -1,4 +1,11 @@
|
||||
import os
|
||||
from datetime import date
|
||||
from itertools import chain
|
||||
|
||||
from typing import Literal
|
||||
|
||||
from providers.types.movie import Movie
|
||||
from providers.types.show import Show
|
||||
|
||||
|
||||
def format_date(date: date | int | None) -> str | None:
|
||||
@ -9,6 +16,25 @@ def format_date(date: date | int | None) -> str | None:
|
||||
return date.isoformat()
|
||||
|
||||
|
||||
def select_image(
|
||||
self: Movie | Show, type: Literal["posters"] | Literal["thumbnails"] | Literal["logos"]
|
||||
) -> str | None:
|
||||
# For now, the API of kyoo only support one language so we remove the others.
|
||||
default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0]
|
||||
return next(
|
||||
chain(
|
||||
(
|
||||
getattr(self.translations[self.original_language], type)
|
||||
if self.original_language
|
||||
else []
|
||||
),
|
||||
getattr(self.translations[default_language], type),
|
||||
*(getattr(x, type) for x in self.translations.values()),
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
class ProviderError(RuntimeError):
|
||||
def __init__(self, *args: object) -> None:
|
||||
super().__init__(*args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user