mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
chg: fix: add all images in response
This commit is contained in:
parent
88fff8ff24
commit
81cc6d752b
@ -5,7 +5,7 @@ from logging import getLogger
|
||||
from typing import Awaitable, Callable, Dict, List, Optional, Any, TypeVar
|
||||
from itertools import accumulate, zip_longest
|
||||
|
||||
from providers.utils import ProviderError
|
||||
from providers.utils import ProviderError, get_iso_639_1_codes
|
||||
from matcher.cache import cache
|
||||
|
||||
from ..provider import Provider
|
||||
@ -149,8 +149,6 @@ class TheMovieDatabase(Provider):
|
||||
Returns:
|
||||
list: A list of images, prioritized by localization, original language, and any available image.
|
||||
"""
|
||||
print(f"Trying to get best image for {item['title']} in {lng}")
|
||||
print(f"All available languageCodes: {list(map(lambda x: x['iso_639_1'], item['images'][key]))}")
|
||||
# Order images by size and vote average
|
||||
item["images"][key] = sorted(
|
||||
item["images"][key],
|
||||
@ -165,11 +163,8 @@ class TheMovieDatabase(Provider):
|
||||
if image.get("iso_639_1") == lng
|
||||
]
|
||||
|
||||
print(f"Localized images: {localized_images}")
|
||||
|
||||
# Step 2: If no localized images, try images in the original language
|
||||
if not localized_images:
|
||||
print(f"Could not find localized images for {lng}, trying original language")
|
||||
localized_images = [
|
||||
image
|
||||
for image in item["images"][key]
|
||||
@ -178,7 +173,6 @@ class TheMovieDatabase(Provider):
|
||||
|
||||
# Step 3: If still no images, use any available images
|
||||
if not localized_images:
|
||||
print(f"Could not find images for {lng} or original language, using any available")
|
||||
localized_images = item["images"][key]
|
||||
|
||||
return localized_images
|
||||
@ -202,7 +196,7 @@ class TheMovieDatabase(Provider):
|
||||
params={
|
||||
"language": lng,
|
||||
"append_to_response": "alternative_titles,videos,credits,keywords,images",
|
||||
"include_image_language": f"{lng},{lng_iso639_1},null",
|
||||
"include_image_language": f"{get_iso_639_1_codes().join(',')},null",
|
||||
},
|
||||
)
|
||||
logger.debug("TMDb responded: %s", movie)
|
||||
@ -299,7 +293,7 @@ class TheMovieDatabase(Provider):
|
||||
params={
|
||||
"language": lng,
|
||||
"append_to_response": "alternative_titles,videos,credits,keywords,images,external_ids",
|
||||
"include_image_language": f"{lng},{lng_iso639_1},null",
|
||||
"include_image_language": f"{get_iso_639_1_codes().join(',')},null",
|
||||
},
|
||||
)
|
||||
logger.debug("TMDb responded: %s", show)
|
||||
|
@ -13,6 +13,8 @@ if TYPE_CHECKING:
|
||||
from providers.types.episode import Episode
|
||||
from providers.types.collection import Collection
|
||||
|
||||
def get_iso_639_1_codes() -> list[str]:
|
||||
return [code for code in Language.all_codes() if len(code) == 2]
|
||||
|
||||
def format_date(date: date | int | None) -> str | None:
|
||||
if date is None:
|
||||
@ -28,7 +30,7 @@ def normalize_lang(lang: str) -> str:
|
||||
|
||||
# For now, the API of kyoo only support one language so we remove the others.
|
||||
default_languages = os.environ.get("LIBRARY_LANGUAGES", "").split(",")
|
||||
image_prefer_original_language = os.environ.get("IMAGE_PREFER_ORIGINAL_LANGUAGE", "false").lower() == "true"
|
||||
media_prefer_original_language = os.environ.get("MEDIA_PREFER_ORIGINAL_LANGUAGE", "false").lower() == "true"
|
||||
|
||||
|
||||
def sort_translations(
|
||||
@ -65,7 +67,7 @@ def select_image(
|
||||
chain(
|
||||
*(
|
||||
getattr(trans, kind)
|
||||
for trans in sort_translations(value, prefer_orginal=image_prefer_original_language)
|
||||
for trans in sort_translations(value, prefer_orginal=media_prefer_original_language)
|
||||
)
|
||||
),
|
||||
None,
|
||||
|
Loading…
x
Reference in New Issue
Block a user