Do not fail on some errors
Signed-off-by: Luis Garcia <git@luigi311.com>pull/277/head
parent
3e474a4593
commit
229ab59b44
|
|
@ -469,7 +469,7 @@ class JellyfinEmby:
|
||||||
return users_watched
|
return users_watched
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"{self.server_type}: Failed to get watched, Error: {e}")
|
logger.error(f"{self.server_type}: Failed to get watched, Error: {e}")
|
||||||
raise Exception(e)
|
return {}
|
||||||
|
|
||||||
def update_user_watched(
|
def update_user_watched(
|
||||||
self,
|
self,
|
||||||
|
|
@ -681,8 +681,6 @@ class JellyfinEmby:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"{self.server_type}: Error updating watched for {user_name} in library {library_name}, {e}",
|
f"{self.server_type}: Error updating watched for {user_name} in library {library_name}, {e}",
|
||||||
)
|
)
|
||||||
logger.error(traceback.format_exc())
|
|
||||||
raise Exception(e)
|
|
||||||
|
|
||||||
def update_watched(
|
def update_watched(
|
||||||
self,
|
self,
|
||||||
|
|
@ -691,7 +689,6 @@ class JellyfinEmby:
|
||||||
library_mapping: dict[str, str] | None = None,
|
library_mapping: dict[str, str] | None = None,
|
||||||
dryrun: bool = False,
|
dryrun: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
|
||||||
for user, user_data in watched_list.items():
|
for user, user_data in watched_list.items():
|
||||||
user_other = None
|
user_other = None
|
||||||
user_name = None
|
user_name = None
|
||||||
|
|
@ -736,9 +733,7 @@ class JellyfinEmby:
|
||||||
if library_name in library_mapping.keys():
|
if library_name in library_mapping.keys():
|
||||||
library_other = library_mapping[library_name]
|
library_other = library_mapping[library_name]
|
||||||
elif library_name in library_mapping.values():
|
elif library_name in library_mapping.values():
|
||||||
library_other = search_mapping(
|
library_other = search_mapping(library_mapping, library_name)
|
||||||
library_mapping, library_name
|
|
||||||
)
|
|
||||||
|
|
||||||
if library_name.lower() not in [
|
if library_name.lower() not in [
|
||||||
x["Name"].lower() for x in jellyfin_libraries
|
x["Name"].lower() for x in jellyfin_libraries
|
||||||
|
|
@ -769,6 +764,7 @@ class JellyfinEmby:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if library_id:
|
if library_id:
|
||||||
|
try:
|
||||||
self.update_user_watched(
|
self.update_user_watched(
|
||||||
user_name,
|
user_name,
|
||||||
user_id,
|
user_id,
|
||||||
|
|
@ -777,7 +773,7 @@ class JellyfinEmby:
|
||||||
library_id,
|
library_id,
|
||||||
dryrun,
|
dryrun,
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"{self.server_type}: Error updating watched, {e}")
|
logger.error(
|
||||||
raise Exception(e)
|
f"{self.server_type}: Error updating watched for {user_name} in library {library_name}, {e}",
|
||||||
|
)
|
||||||
|
|
|
||||||
64
src/plex.py
64
src/plex.py
|
|
@ -92,15 +92,17 @@ def update_user_watched(
|
||||||
library_name: str,
|
library_name: str,
|
||||||
dryrun: bool,
|
dryrun: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
|
||||||
# If there are no movies or shows to update, exit early.
|
# If there are no movies or shows to update, exit early.
|
||||||
if not library_data.series and not library_data.movies:
|
if not library_data.series and not library_data.movies:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(
|
logger.info(f"Plex: Updating watched for {user.title} in library {library_name}")
|
||||||
f"Plex: Updating watched for {user.title} in library {library_name}"
|
|
||||||
)
|
|
||||||
library_section = user_plex.library.section(library_name)
|
library_section = user_plex.library.section(library_name)
|
||||||
|
if not library_section:
|
||||||
|
logger.error(
|
||||||
|
f"Plex: Library {library_name} not found for {user.title}, skipping",
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
# Update movies.
|
# Update movies.
|
||||||
if library_data.movies:
|
if library_data.movies:
|
||||||
|
|
@ -109,15 +111,19 @@ def update_user_watched(
|
||||||
plex_identifiers = extract_identifiers_from_item(plex_movie)
|
plex_identifiers = extract_identifiers_from_item(plex_movie)
|
||||||
# Check each stored movie for a match.
|
# Check each stored movie for a match.
|
||||||
for stored_movie in library_data.movies:
|
for stored_movie in library_data.movies:
|
||||||
if check_same_identifiers(
|
if check_same_identifiers(plex_identifiers, stored_movie.identifiers):
|
||||||
plex_identifiers, stored_movie.identifiers
|
|
||||||
):
|
|
||||||
# If the stored movie is marked as watched (or has enough progress),
|
# If the stored movie is marked as watched (or has enough progress),
|
||||||
# update the Plex movie accordingly.
|
# update the Plex movie accordingly.
|
||||||
if stored_movie.status.completed:
|
if stored_movie.status.completed:
|
||||||
msg = f"Plex: {plex_movie.title} as watched for {user.title} in {library_name}"
|
msg = f"Plex: {plex_movie.title} as watched for {user.title} in {library_name}"
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
|
try:
|
||||||
plex_movie.markWatched()
|
plex_movie.markWatched()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(
|
||||||
|
f"Plex: Failed to mark {plex_movie.title} as watched, Error: {e}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
logger.success(f"{'[DRYRUN] ' if dryrun else ''}{msg}")
|
logger.success(f"{'[DRYRUN] ' if dryrun else ''}{msg}")
|
||||||
log_marked(
|
log_marked(
|
||||||
|
|
@ -132,7 +138,13 @@ def update_user_watched(
|
||||||
else:
|
else:
|
||||||
msg = f"Plex: {plex_movie.title} as partially watched for {floor(stored_movie.status.time / 60_000)} minutes for {user.title} in {library_name}"
|
msg = f"Plex: {plex_movie.title} as partially watched for {floor(stored_movie.status.time / 60_000)} minutes for {user.title} in {library_name}"
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
|
try:
|
||||||
plex_movie.updateTimeline(stored_movie.status.time)
|
plex_movie.updateTimeline(stored_movie.status.time)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(
|
||||||
|
f"Plex: Failed to update {plex_movie.title} timeline, Error: {e}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
logger.success(f"{'[DRYRUN] ' if dryrun else ''}{msg}")
|
logger.success(f"{'[DRYRUN] ' if dryrun else ''}{msg}")
|
||||||
log_marked(
|
log_marked(
|
||||||
|
|
@ -173,7 +185,13 @@ def update_user_watched(
|
||||||
if stored_ep.status.completed:
|
if stored_ep.status.completed:
|
||||||
msg = f"Plex: {plex_show.title} {plex_episode.title} as watched for {user.title} in {library_name}"
|
msg = f"Plex: {plex_show.title} {plex_episode.title} as watched for {user.title} in {library_name}"
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
|
try:
|
||||||
plex_episode.markWatched()
|
plex_episode.markWatched()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(
|
||||||
|
f"Plex: Failed to mark {plex_show.title} {plex_episode.title} as watched, Error: {e}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
logger.success(
|
logger.success(
|
||||||
f"{'[DRYRUN] ' if dryrun else ''}{msg}"
|
f"{'[DRYRUN] ' if dryrun else ''}{msg}"
|
||||||
|
|
@ -189,9 +207,15 @@ def update_user_watched(
|
||||||
else:
|
else:
|
||||||
msg = f"Plex: {plex_show.title} {plex_episode.title} as partially watched for {floor(stored_ep.status.time / 60_000)} minutes for {user.title} in {library_name}"
|
msg = f"Plex: {plex_show.title} {plex_episode.title} as partially watched for {floor(stored_ep.status.time / 60_000)} minutes for {user.title} in {library_name}"
|
||||||
if not dryrun:
|
if not dryrun:
|
||||||
|
try:
|
||||||
plex_episode.updateTimeline(
|
plex_episode.updateTimeline(
|
||||||
stored_ep.status.time
|
stored_ep.status.time
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(
|
||||||
|
f"Plex: Failed to update {plex_show.title} {plex_episode.title} timeline, Error: {e}"
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
||||||
logger.success(
|
logger.success(
|
||||||
f"{'[DRYRUN] ' if dryrun else ''}{msg}"
|
f"{'[DRYRUN] ' if dryrun else ''}{msg}"
|
||||||
|
|
@ -208,13 +232,6 @@ def update_user_watched(
|
||||||
break # Found a matching episode.
|
break # Found a matching episode.
|
||||||
break # Found a matching show.
|
break # Found a matching show.
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(
|
|
||||||
f"Plex: Failed to update watched for {user.title} in library {library_name}, Error: {e}",
|
|
||||||
2,
|
|
||||||
)
|
|
||||||
raise e
|
|
||||||
|
|
||||||
|
|
||||||
# class plex accept base url and token and username and password but default with none
|
# class plex accept base url and token and username and password but default with none
|
||||||
class Plex:
|
class Plex:
|
||||||
|
|
@ -423,7 +440,7 @@ class Plex:
|
||||||
return users_watched
|
return users_watched
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Plex: Failed to get watched, Error: {e}")
|
logger.error(f"Plex: Failed to get watched, Error: {e}")
|
||||||
raise Exception(e)
|
return {}
|
||||||
|
|
||||||
def update_watched(
|
def update_watched(
|
||||||
self,
|
self,
|
||||||
|
|
@ -432,7 +449,6 @@ class Plex:
|
||||||
library_mapping: dict[str, str] | None = None,
|
library_mapping: dict[str, str] | None = None,
|
||||||
dryrun: bool = False,
|
dryrun: bool = False,
|
||||||
) -> None:
|
) -> None:
|
||||||
try:
|
|
||||||
for user, user_data in watched_list.items():
|
for user, user_data in watched_list.items():
|
||||||
user_other = None
|
user_other = None
|
||||||
# If type of user is dict
|
# If type of user is dict
|
||||||
|
|
@ -441,9 +457,7 @@ class Plex:
|
||||||
|
|
||||||
for index, value in enumerate(self.users):
|
for index, value in enumerate(self.users):
|
||||||
username_title = (
|
username_title = (
|
||||||
value.username.lower()
|
value.username.lower() if value.username else value.title.lower()
|
||||||
if value.username
|
|
||||||
else value.title.lower()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if user.lower() == username_title:
|
if user.lower() == username_title:
|
||||||
|
|
@ -490,9 +504,7 @@ class Plex:
|
||||||
library_other = search_mapping(library_mapping, library_name)
|
library_other = search_mapping(library_mapping, library_name)
|
||||||
# if library in plex library list
|
# if library in plex library list
|
||||||
library_list = user_plex.library.sections()
|
library_list = user_plex.library.sections()
|
||||||
if library_name.lower() not in [
|
if library_name.lower() not in [x.title.lower() for x in library_list]:
|
||||||
x.title.lower() for x in library_list
|
|
||||||
]:
|
|
||||||
if library_other:
|
if library_other:
|
||||||
if library_other.lower() in [
|
if library_other.lower() in [
|
||||||
x.title.lower() for x in library_list
|
x.title.lower() for x in library_list
|
||||||
|
|
@ -512,6 +524,7 @@ class Plex:
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
try:
|
||||||
update_user_watched(
|
update_user_watched(
|
||||||
user,
|
user,
|
||||||
user_plex,
|
user_plex,
|
||||||
|
|
@ -519,7 +532,8 @@ class Plex:
|
||||||
library_name,
|
library_name,
|
||||||
dryrun,
|
dryrun,
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Plex: Failed to update watched, Error: {e}")
|
logger.error(
|
||||||
raise Exception(e)
|
f"Plex: Failed to update watched for {user.title} in {library_name}, Error: {e}",
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue