@@ -65,9 +65,9 @@ async def _fetch_tmdb_movie(
6565 client : httpx .AsyncClient , tmdb_id : str , api_key : str
6666) -> Optional [TMDBMovie ]:
6767 url = (
68- f"https://api.themoviedb.org/3/movie/{ tmdb_id } ?api_key= { api_key } & append_to_response=reviews"
68+ f"https://api.themoviedb.org/3/movie/{ tmdb_id } ?append_to_response=reviews"
6969 )
70- resp = await client .get (url )
70+ resp = await client .get (url , headers = { "Authorization" : f"Bearer { api_key } " } )
7171 if resp .is_success :
7272 return TMDBMovie .model_validate (resp .json ())
7373 return None
@@ -77,9 +77,9 @@ async def _fetch_tmdb_show(
7777 client : httpx .AsyncClient , tmdb_id : str , api_key : str
7878) -> Optional [TMDBShow ]:
7979 url = (
80- f"https://api.themoviedb.org/3/tv/{ tmdb_id } ?api_key= { api_key } & append_to_response=reviews"
80+ f"https://api.themoviedb.org/3/tv/{ tmdb_id } ?append_to_response=reviews"
8181 )
82- resp = await client .get (url )
82+ resp = await client .get (url , headers = { "Authorization" : f"Bearer { api_key } " } )
8383 if resp .is_success :
8484 return TMDBShow .model_validate (resp .json ())
8585 return None
@@ -90,8 +90,8 @@ async def _fetch_tmdb_episode(
9090) -> Optional [TMDBEpisode ]:
9191 """Attempt to fetch TMDb data for a TV episode by its ID."""
9292
93- url = f"https://api.themoviedb.org/3/tv/episode/{ tmdb_id } ?api_key= { api_key } "
94- resp = await client .get (url )
93+ url = f"https://api.themoviedb.org/3/tv/episode/{ tmdb_id } "
94+ resp = await client .get (url , headers = { "Authorization" : f"Bearer { api_key } " } )
9595 if resp .is_success :
9696 return TMDBEpisode .model_validate (resp .json ())
9797 return None
@@ -190,19 +190,25 @@ async def _augment_episode(
190190 results : List [AggregatedItem ] = []
191191 async with httpx .AsyncClient (timeout = 30 ) as client :
192192 movie_section = server .library .section ("Movies" )
193- movie_tasks = [_augment_movie (client , movie ) for movie in movie_section .all ()]
193+ movie_tasks = [
194+ _augment_movie (client , movie .fetchItem (movie .ratingKey ))
195+ for movie in movie_section .all ()
196+ ]
194197 if movie_tasks :
195198 results .extend (await _gather_in_batches (movie_tasks , batch_size ))
196199
197200 show_section = server .library .section ("TV Shows" )
198201 for show in show_section .all ():
199- show_ids = _extract_external_ids (show )
202+ full_show = show .fetchItem (show .ratingKey )
203+ show_ids = _extract_external_ids (full_show )
200204 show_tmdb : Optional [TMDBShow ] = None
201205 if show_ids .tmdb :
202206 show_tmdb = await _fetch_tmdb_show (client , show_ids .tmdb , tmdb_api_key )
203207 episode_tasks = [
204- _augment_episode (client , episode , show_tmdb )
205- for episode in show .episodes ()
208+ _augment_episode (
209+ client , episode .fetchItem (episode .ratingKey ), show_tmdb
210+ )
211+ for episode in full_show .episodes ()
206212 ]
207213 if episode_tasks :
208214 results .extend (await _gather_in_batches (episode_tasks , batch_size ))
@@ -348,7 +354,7 @@ async def run(
348354 parts .extend (r .get ("content" , "" ) for r in getattr (item .tmdb , "reviews" , []))
349355 text = "\n " .join (p for p in parts if p )
350356 payload = {
351- "data" : item .model_dump (),
357+ "data" : item .model_dump (mode = "json" ),
352358 "title" : item .plex .title ,
353359 "type" : item .plex .type ,
354360 }
@@ -357,7 +363,7 @@ async def run(
357363 if item .plex .year is not None :
358364 payload ["year" ] = item .plex .year
359365 if item .plex .added_at is not None :
360- payload ["added_at" ] = item .plex .added_at
366+ payload ["added_at" ] = int ( item .plex .added_at . timestamp ())
361367 point_id : int | str = (
362368 int (item .plex .rating_key )
363369 if item .plex .rating_key .isdigit ()
@@ -453,7 +459,7 @@ async def run(
453459 else :
454460 logger .info ("No points to upsert" )
455461
456- json .dump ([item .model_dump () for item in items ], fp = sys .stdout , indent = 2 )
462+ json .dump ([item .model_dump (mode = "json" ) for item in items ], fp = sys .stdout , indent = 2 )
457463 sys .stdout .write ("\n " )
458464
459465
0 commit comments