@@ -91,76 +91,52 @@ async def _fetch_tmdb_data(self, endpoint, params=None):
91
91
return None
92
92
93
93
async def _get_tmdb_images (self , tmdb_id , media_type = 'movie' ):
94
- """Get TMDB image URLs with preferred language, falling back to English ."""
94
+ """Get TMDB image URLs without language filtering ."""
95
95
if not tmdb_id :
96
96
return None , None , None
97
97
98
- cache_key = f"images_{ media_type } _{ tmdb_id } _ { self . _language } "
98
+ cache_key = f"images_{ media_type } _{ tmdb_id } "
99
99
if cache_key in self ._cache :
100
100
return self ._cache [cache_key ]
101
101
102
102
try :
103
- # Try with preferred language first
104
- params = {"language" : self ._language }
105
- data = await self ._fetch_tmdb_data (f"{ media_type } /{ tmdb_id } /images" , params )
103
+ # Just get all images without language filtering
104
+ data = await self ._fetch_tmdb_data (f"{ media_type } /{ tmdb_id } /images" )
106
105
107
106
poster_url = backdrop_url = main_backdrop_url = None
108
107
109
108
if data :
110
- # Process posters - try to find ones in the preferred language
111
- posters = data .get ('posters' , [])
112
- lang_posters = [p for p in posters if p .get ('iso_639_1' ) == self ._language ]
109
+ _LOGGER .debug ("Image data for %s (%s): Posters: %d, Backdrops: %d" ,
110
+ tmdb_id , media_type , len (data .get ('posters' , [])), len (data .get ('backdrops' , [])))
113
111
114
- # Get poster path (preferred language if available, otherwise any)
115
- if lang_posters :
116
- poster_path = lang_posters [0 ].get ('file_path' )
117
- elif posters :
112
+ # Get first available poster
113
+ posters = data .get ('posters' , [])
114
+ if posters :
118
115
poster_path = posters [0 ].get ('file_path' )
119
- else :
120
- poster_path = None
121
-
122
- # Process backdrops - try to find ones in the preferred language
123
- backdrops = data .get ('backdrops' , [])
124
- lang_backdrops = [b for b in backdrops if b .get ('iso_639_1' ) == self ._language ]
116
+ poster_url = f"{ TMDB_IMAGE_BASE_URL } /w500{ poster_path } " if poster_path else None
125
117
126
- # Get backdrop paths (preferred language if available, otherwise any)
127
- if lang_backdrops :
128
- backdrop_path = lang_backdrops [0 ].get ('file_path' )
129
- main_backdrop_path = lang_backdrops [1 ].get ('file_path' ) if len (lang_backdrops ) > 1 else backdrop_path
130
- elif backdrops :
118
+ # Get first and second available backdrops
119
+ backdrops = data .get ('backdrops' , [])
120
+ if backdrops :
121
+ # Sort by vote count for better quality
131
122
backdrops .sort (key = lambda x : x .get ('vote_count' , 0 ), reverse = True )
123
+
132
124
backdrop_path = backdrops [0 ].get ('file_path' )
133
125
main_backdrop_path = backdrops [1 ].get ('file_path' ) if len (backdrops ) > 1 else backdrop_path
134
- else :
135
- backdrop_path = main_backdrop_path = None
136
-
137
- # If preferred language images are missing but not English, try English as fallback
138
- if (self ._language != 'en' and
139
- (not poster_path or not backdrop_path ) and
140
- not any (p .get ('iso_639_1' ) == 'en' for p in posters )):
141
126
142
- # Fetch English images
143
- en_params = {"language" : "en" }
144
- en_data = await self ._fetch_tmdb_data (f"{ media_type } /{ tmdb_id } /images" , en_params )
145
-
146
- if en_data :
147
- en_posters = en_data .get ('posters' , [])
148
- en_backdrops = en_data .get ('backdrops' , [])
149
-
150
- # Use English poster if needed
151
- if not poster_path and en_posters :
152
- poster_path = en_posters [0 ].get ('file_path' )
153
-
154
- # Use English backdrops if needed
155
- if not backdrop_path and en_backdrops :
156
- en_backdrops .sort (key = lambda x : x .get ('vote_count' , 0 ), reverse = True )
157
- backdrop_path = en_backdrops [0 ].get ('file_path' )
158
- main_backdrop_path = en_backdrops [1 ].get ('file_path' ) if len (en_backdrops ) > 1 else backdrop_path
127
+ backdrop_url = f"{ TMDB_IMAGE_BASE_URL } /w780{ backdrop_path } " if backdrop_path else None
128
+ main_backdrop_url = f"{ TMDB_IMAGE_BASE_URL } /original{ main_backdrop_path } " if main_backdrop_path else None
129
+
130
+ # Use poster as fallback for backdrop if needed
131
+ if poster_url and (not backdrop_url or not main_backdrop_url ):
132
+ if not backdrop_url :
133
+ backdrop_url = poster_url
134
+ if not main_backdrop_url :
135
+ main_backdrop_url = poster_url
136
+ _LOGGER .debug ("Using poster as backdrop fallback for %s" , tmdb_id )
159
137
160
- # Convert paths to URLs
161
- poster_url = f"{ TMDB_IMAGE_BASE_URL } /w500{ poster_path } " if poster_path else None
162
- backdrop_url = f"{ TMDB_IMAGE_BASE_URL } /w780{ backdrop_path } " if backdrop_path else None
163
- main_backdrop_url = f"{ TMDB_IMAGE_BASE_URL } /original{ main_backdrop_path } " if main_backdrop_path else None
138
+ _LOGGER .debug ("Image URLs for %s: poster=%s, backdrop=%s, main_backdrop=%s" ,
139
+ tmdb_id , poster_url is not None , backdrop_url is not None , main_backdrop_url is not None )
164
140
165
141
result = (poster_url , backdrop_url , main_backdrop_url )
166
142
self ._cache [cache_key ] = result
0 commit comments