mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-04 22:24:14 -04:00
Handle missing translations for movies
This commit is contained in:
parent
c8402780f3
commit
710e3cf10b
@ -87,6 +87,7 @@ class Matcher:
|
|||||||
|
|
||||||
async def search_movie(self, title: str, year: Optional[int], path: str):
|
async def search_movie(self, title: str, year: Optional[int], path: str):
|
||||||
movie = await self._provider.search_movie(title, year)
|
movie = await self._provider.search_movie(title, year)
|
||||||
|
movie.file_title = title
|
||||||
movie.path = path
|
movie.path = path
|
||||||
logger.debug("Got movie: %s", movie)
|
logger.debug("Got movie: %s", movie)
|
||||||
movie_id = await self._client.post("movies", data=movie.to_kyoo())
|
movie_id = await self._client.post("movies", data=movie.to_kyoo())
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
import os
|
|
||||||
from dataclasses import asdict, dataclass, field
|
from dataclasses import asdict, dataclass, field
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from providers.utils import select_translation, select_image
|
||||||
|
|
||||||
from .collection import Collection
|
from .collection import Collection
|
||||||
from .genre import Genre
|
from .genre import Genre
|
||||||
from .studio import Studio
|
from .studio import Studio
|
||||||
@ -44,22 +45,22 @@ class Movie:
|
|||||||
external_id: dict[str, MetadataID]
|
external_id: dict[str, MetadataID]
|
||||||
|
|
||||||
path: Optional[str] = None
|
path: Optional[str] = None
|
||||||
|
# The title of this show according to it's filename (None only for ease of use in providers)
|
||||||
|
file_title: Optional[str] = None
|
||||||
collections: list[Collection] = field(default_factory=list)
|
collections: list[Collection] = field(default_factory=list)
|
||||||
translations: dict[str, MovieTranslation] = field(default_factory=dict)
|
translations: dict[str, MovieTranslation] = field(default_factory=dict)
|
||||||
|
|
||||||
def to_kyoo(self):
|
def to_kyoo(self):
|
||||||
from ..utils import select_image
|
trans = select_translation(self) or MovieTranslation(name=self.file_title or "")
|
||||||
|
|
||||||
# For now, the API of kyoo only support one language so we remove the others.
|
|
||||||
default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0]
|
|
||||||
return {
|
return {
|
||||||
**asdict(self),
|
**asdict(self),
|
||||||
**asdict(self.translations[default_language]),
|
**asdict(trans),
|
||||||
"poster": select_image(self, "posters"),
|
"poster": select_image(self, "posters"),
|
||||||
"thumbnail": select_image(self, "thumbnails"),
|
"thumbnail": select_image(self, "thumbnails"),
|
||||||
"logo": select_image(self, "logos"),
|
"logo": select_image(self, "logos"),
|
||||||
"trailer": next(iter(self.translations[default_language].trailers), None),
|
"trailer": next(iter(trans.trailers), None),
|
||||||
"studio": next((x.to_kyoo() for x in self.studios), None),
|
"studio": next((x.to_kyoo() for x in self.studios), None),
|
||||||
"genres": [x.to_kyoo() for x in self.genres],
|
"genres": [x.to_kyoo() for x in self.genres],
|
||||||
"collections": None,
|
"collections": None,
|
||||||
|
"file_title": None,
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from itertools import chain
|
|
||||||
|
|
||||||
from typing import Literal
|
from typing import Literal
|
||||||
|
|
||||||
@ -16,24 +17,33 @@ def format_date(date: date | int | None) -> str | None:
|
|||||||
return date.isoformat()
|
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.
|
# For now, the API of kyoo only support one language so we remove the others.
|
||||||
default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0]
|
default_languages = os.environ["LIBRARY_LANGUAGES"].split(",")
|
||||||
return next(
|
|
||||||
chain(
|
|
||||||
(
|
def select_translation(value: Movie | Show, *, prefer_orginal=False):
|
||||||
getattr(self.translations[self.original_language], type)
|
if (
|
||||||
if self.original_language
|
prefer_orginal
|
||||||
else []
|
and value.original_language
|
||||||
),
|
and value.original_language in value.translations
|
||||||
getattr(self.translations[default_language], type),
|
):
|
||||||
*(getattr(x, type) for x in self.translations.values()),
|
return value.translations[value.original_language]
|
||||||
),
|
for lang in default_languages:
|
||||||
None,
|
if lang in value.translations:
|
||||||
|
return value.translations[lang]
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def select_image(
|
||||||
|
value: Movie | Show,
|
||||||
|
kind: Literal["posters"] | Literal["thumbnails"] | Literal["logos"],
|
||||||
|
) -> str | None:
|
||||||
|
trans = select_translation(value, prefer_orginal=True) or next(
|
||||||
|
iter(value.translations.values()), None
|
||||||
)
|
)
|
||||||
|
if trans is None:
|
||||||
|
return None
|
||||||
|
return getattr(trans, kind)
|
||||||
|
|
||||||
|
|
||||||
class ProviderError(RuntimeError):
|
class ProviderError(RuntimeError):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user