mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-10-31 10:37:13 -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 .genre import Genre | ||||||
| from .studio import Studio | from .studio import Studio | ||||||
| from .metadataid import MetadataID | from .metadataid import MetadataID | ||||||
| from ..utils import format_date |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class Status(str, Enum): | class Status(str, Enum): | ||||||
| @ -45,16 +44,15 @@ class Movie: | |||||||
| 	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 | ||||||
| 		# 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_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0] | ||||||
| 		return { | 		return { | ||||||
| 			**asdict(self), | 			**asdict(self), | ||||||
| 			**asdict(self.translations[default_language]), | 			**asdict(self.translations[default_language]), | ||||||
| 			"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 | 			"logo": select_image(self, "logos"), | ||||||
| 			), |  | ||||||
| 			"logo": next(iter(self.translations[default_language].logos), None), |  | ||||||
| 			"trailer": next(iter(self.translations[default_language].trailers), None), | 			"trailer": next(iter(self.translations[default_language].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], | ||||||
|  | |||||||
| @ -47,6 +47,7 @@ class Show: | |||||||
| 	translations: dict[str, ShowTranslation] = field(default_factory=dict) | 	translations: dict[str, ShowTranslation] = field(default_factory=dict) | ||||||
| 
 | 
 | ||||||
| 	def to_kyoo(self): | 	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. | 		# For now, the API of kyoo only support one language so we remove the others. | ||||||
| 		default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0] | 		default_language = os.environ["LIBRARY_LANGUAGES"].split(",")[0] | ||||||
| 		return { | 		return { | ||||||
| @ -54,11 +55,9 @@ class Show: | |||||||
| 			**asdict(self.translations[default_language]), | 			**asdict(self.translations[default_language]), | ||||||
| 			"studio": next((x.to_kyoo() for x in self.studios), None), | 			"studio": next((x.to_kyoo() for x in self.studios), None), | ||||||
| 			"seasons": None, | 			"seasons": None, | ||||||
| 			"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 | 			"logo": select_image(self, "logos"), | ||||||
| 			), |  | ||||||
| 			"logo": next(iter(self.translations[default_language].logos), None), |  | ||||||
| 			"trailer": next(iter(self.translations[default_language].trailers), None), | 			"trailer": next(iter(self.translations[default_language].trailers), None), | ||||||
| 			"genres": [x.to_kyoo() for x in self.genres], | 			"genres": [x.to_kyoo() for x in self.genres], | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -1,4 +1,11 @@ | |||||||
|  | import os | ||||||
| from datetime import date | 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: | 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() | 	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): | class ProviderError(RuntimeError): | ||||||
| 	def __init__(self, *args: object) -> None: | 	def __init__(self, *args: object) -> None: | ||||||
| 		super().__init__(*args) | 		super().__init__(*args) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user