@@ -50,7 +50,7 @@ async def update(self):
5050 try :
5151 info_res = await self ._hass .async_add_executor_job (
5252 requests .get ,
53- f'{ info_url } ?X-Plex-Token={ self ._token } ' ,
53+ f'{ info_url } ?X-Plex-Token={ self ._token } ' ,
5454 {
5555 "headers" :{
5656 "User-agent" : USER_AGENT ,
@@ -62,8 +62,8 @@ async def update(self):
6262 check_headers (info_res )
6363 root = ElementTree .fromstring (info_res .text )
6464 identifier = root .get ("machineIdentifier" )
65- except OSError as e :
66- raise FailedToLogin
65+ except ( OSError , ValueError ) as e :
66+ raise FailedToLogin from e
6767
6868 url_base = f'{ info_url } /library/sections'
6969 all_libraries = f'{ url_base } /all'
@@ -76,7 +76,7 @@ async def update(self):
7676 try :
7777 libraries = await self ._hass .async_add_executor_job (
7878 requests .get ,
79- f'{ all_libraries } ?X-Plex-Token={ self ._token } ' ,
79+ f'{ all_libraries } ?X-Plex-Token={ self ._token } ' ,
8080 {
8181 "headers" :{
8282 "User-agent" : USER_AGENT ,
@@ -91,8 +91,8 @@ async def update(self):
9191 libs .append (lib .get ("title" ))
9292 if lib .get ("type" ) in self ._section_types and (len (self ._section_libraries ) == 0 or lib .get ("title" ) in self ._section_libraries ):
9393 sections .append ({'type' : lib .get ("type" ),'key' : lib .get ("key" )})
94- except OSError as e :
95- raise FailedToLogin
94+ except ( OSError , ValueError ) as e :
95+ raise FailedToLogin from e
9696
9797 """ Looping through all libraries (sections) """
9898 data = {
@@ -102,30 +102,34 @@ async def update(self):
102102 data [s ] = []
103103
104104 for library in sections :
105- recent_or_deck = on_deck if self ._on_deck else recently_added
106- sub_sec = await self ._hass .async_add_executor_job (
107- requests .get ,
108- f'{ recent_or_deck .format (library ["key" ], self ._max * 2 )} &X-Plex-Token={ self ._token } ' ,
109- {
110- "headers" :{
111- "User-agent" : USER_AGENT ,
112- "Accept" : ACCEPTS ,
113- },
114- "timeout" :10
115- }
116- )
117- check_headers (sub_sec )
118- root = ElementTree .fromstring (sub_sec .text )
119- parsed_libs = parse_library (root )
120-
121- # Fetch trailer URLs for each item
122- for item in parsed_libs :
123- item ['trailer' ] = await get_tmdb_trailer_url (self ._hass , item ['title' ], library ['type' ])
124-
125- if library ["type" ] not in data ['all' ]:
126- data ['all' ][library ["type" ]] = []
127- data ['all' ][library ["type" ]] += parsed_libs
128- data [library ["type" ]] += parsed_libs
105+ try :
106+ recent_or_deck = on_deck if self ._on_deck else recently_added
107+ sub_sec = await self ._hass .async_add_executor_job (
108+ requests .get ,
109+ f'{ recent_or_deck .format (library ["key" ], self ._max * 2 )} &X-Plex-Token={ self ._token } ' ,
110+ {
111+ "headers" :{
112+ "User-agent" : USER_AGENT ,
113+ "Accept" : ACCEPTS ,
114+ },
115+ "timeout" :10
116+ }
117+ )
118+ check_headers (sub_sec )
119+ root = ElementTree .fromstring (sub_sec .text )
120+ parsed_libs = parse_library (root )
121+
122+ # Fetch trailer URLs for each item
123+ for item in parsed_libs :
124+ item ['trailer' ] = await get_tmdb_trailer_url (self ._hass , item ['title' ], library ['type' ])
125+
126+ if library ["type" ] not in data ['all' ]:
127+ data ['all' ][library ["type" ]] = []
128+ data ['all' ][library ["type" ]] += parsed_libs
129+ data [library ["type" ]] += parsed_libs
130+ except (OSError , ValueError ) as e :
131+ # Skip this library if it fails to load
132+ continue
129133
130134 data_out = {}
131135 for k in data .keys ():
0 commit comments