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
|
||||
except Exception as e:
|
||||
logger.error(f"{self.server_type}: Failed to get watched, Error: {e}")
|
||||
raise Exception(e)
|
||||
return {}
|
||||
|
||||
def update_user_watched(
|
||||
self,
|
||||
|
|
@ -681,8 +681,6 @@ class JellyfinEmby:
|
|||
logger.error(
|
||||
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(
|
||||
self,
|
||||
|
|
@ -691,7 +689,6 @@ class JellyfinEmby:
|
|||
library_mapping: dict[str, str] | None = None,
|
||||
dryrun: bool = False,
|
||||
) -> None:
|
||||
try:
|
||||
for user, user_data in watched_list.items():
|
||||
user_other = None
|
||||
user_name = None
|
||||
|
|
@ -736,9 +733,7 @@ class JellyfinEmby:
|
|||
if library_name in library_mapping.keys():
|
||||
library_other = library_mapping[library_name]
|
||||
elif library_name in library_mapping.values():
|
||||
library_other = search_mapping(
|
||||
library_mapping, library_name
|
||||
)
|
||||
library_other = search_mapping(library_mapping, library_name)
|
||||
|
||||
if library_name.lower() not in [
|
||||
x["Name"].lower() for x in jellyfin_libraries
|
||||
|
|
@ -769,6 +764,7 @@ class JellyfinEmby:
|
|||
continue
|
||||
|
||||
if library_id:
|
||||
try:
|
||||
self.update_user_watched(
|
||||
user_name,
|
||||
user_id,
|
||||
|
|
@ -777,7 +773,7 @@ class JellyfinEmby:
|
|||
library_id,
|
||||
dryrun,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"{self.server_type}: Error updating watched, {e}")
|
||||
raise Exception(e)
|
||||
logger.error(
|
||||
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,
|
||||
dryrun: bool,
|
||||
) -> None:
|
||||
try:
|
||||
# If there are no movies or shows to update, exit early.
|
||||
if not library_data.series and not library_data.movies:
|
||||
return
|
||||
|
||||
logger.info(
|
||||
f"Plex: Updating watched for {user.title} in library {library_name}"
|
||||
)
|
||||
logger.info(f"Plex: Updating watched for {user.title} in library {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.
|
||||
if library_data.movies:
|
||||
|
|
@ -109,15 +111,19 @@ def update_user_watched(
|
|||
plex_identifiers = extract_identifiers_from_item(plex_movie)
|
||||
# Check each stored movie for a match.
|
||||
for stored_movie in library_data.movies:
|
||||
if check_same_identifiers(
|
||||
plex_identifiers, stored_movie.identifiers
|
||||
):
|
||||
if check_same_identifiers(plex_identifiers, stored_movie.identifiers):
|
||||
# If the stored movie is marked as watched (or has enough progress),
|
||||
# update the Plex movie accordingly.
|
||||
if stored_movie.status.completed:
|
||||
msg = f"Plex: {plex_movie.title} as watched for {user.title} in {library_name}"
|
||||
if not dryrun:
|
||||
try:
|
||||
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}")
|
||||
log_marked(
|
||||
|
|
@ -132,7 +138,13 @@ def update_user_watched(
|
|||
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}"
|
||||
if not dryrun:
|
||||
try:
|
||||
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}")
|
||||
log_marked(
|
||||
|
|
@ -173,7 +185,13 @@ def update_user_watched(
|
|||
if stored_ep.status.completed:
|
||||
msg = f"Plex: {plex_show.title} {plex_episode.title} as watched for {user.title} in {library_name}"
|
||||
if not dryrun:
|
||||
try:
|
||||
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(
|
||||
f"{'[DRYRUN] ' if dryrun else ''}{msg}"
|
||||
|
|
@ -189,9 +207,15 @@ def update_user_watched(
|
|||
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}"
|
||||
if not dryrun:
|
||||
try:
|
||||
plex_episode.updateTimeline(
|
||||
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(
|
||||
f"{'[DRYRUN] ' if dryrun else ''}{msg}"
|
||||
|
|
@ -208,13 +232,6 @@ def update_user_watched(
|
|||
break # Found a matching episode.
|
||||
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:
|
||||
|
|
@ -423,7 +440,7 @@ class Plex:
|
|||
return users_watched
|
||||
except Exception as e:
|
||||
logger.error(f"Plex: Failed to get watched, Error: {e}")
|
||||
raise Exception(e)
|
||||
return {}
|
||||
|
||||
def update_watched(
|
||||
self,
|
||||
|
|
@ -432,7 +449,6 @@ class Plex:
|
|||
library_mapping: dict[str, str] | None = None,
|
||||
dryrun: bool = False,
|
||||
) -> None:
|
||||
try:
|
||||
for user, user_data in watched_list.items():
|
||||
user_other = None
|
||||
# If type of user is dict
|
||||
|
|
@ -441,9 +457,7 @@ class Plex:
|
|||
|
||||
for index, value in enumerate(self.users):
|
||||
username_title = (
|
||||
value.username.lower()
|
||||
if value.username
|
||||
else value.title.lower()
|
||||
value.username.lower() if value.username else value.title.lower()
|
||||
)
|
||||
|
||||
if user.lower() == username_title:
|
||||
|
|
@ -490,9 +504,7 @@ class Plex:
|
|||
library_other = search_mapping(library_mapping, library_name)
|
||||
# if library in plex library list
|
||||
library_list = user_plex.library.sections()
|
||||
if library_name.lower() not in [
|
||||
x.title.lower() for x in library_list
|
||||
]:
|
||||
if library_name.lower() not in [x.title.lower() for x in library_list]:
|
||||
if library_other:
|
||||
if library_other.lower() in [
|
||||
x.title.lower() for x in library_list
|
||||
|
|
@ -512,6 +524,7 @@ class Plex:
|
|||
)
|
||||
continue
|
||||
|
||||
try:
|
||||
update_user_watched(
|
||||
user,
|
||||
user_plex,
|
||||
|
|
@ -519,7 +532,8 @@ class Plex:
|
|||
library_name,
|
||||
dryrun,
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Plex: Failed to update watched, Error: {e}")
|
||||
raise Exception(e)
|
||||
logger.error(
|
||||
f"Plex: Failed to update watched for {user.title} in {library_name}, Error: {e}",
|
||||
)
|
||||
continue
|
||||
|
|
|
|||
Loading…
Reference in New Issue