Cleanup. Add debug variable

This commit is contained in:
Luigi311
2022-05-23 04:33:55 -06:00
parent 8d39bd6d33
commit 26a9c85d3b
5 changed files with 29 additions and 27 deletions

View File

@@ -1,4 +1,5 @@
DRYRUN = "True" DRYRUN = "True"
DEBUG = "True"
SLEEP_DURATION = "3600" SLEEP_DURATION = "3600"
LOGFILE = "log.log" LOGFILE = "log.log"
#USER_MAPPING = { "test2": "test" } #USER_MAPPING = { "test2": "test" }

View File

@@ -24,7 +24,7 @@ def cleanup_watched(watched_list_1, watched_list_2, user_mapping):
elif user_2 in watched_list_2: elif user_2 in watched_list_2:
user = user_2 user = user_2
else: else:
print(f"User {user_1} and {user_2} not found in watched list 2") logger(f"User {user_1} and {user_2} not found in watched list 2", 1)
user = None user = None
if user: if user:
@@ -119,7 +119,6 @@ def setup_black_white_lists():
logger(f"Blacklist Users: {blacklist_users}", 1) logger(f"Blacklist Users: {blacklist_users}", 1)
whitelist_users = os.getenv("WHITELIST_USERS") whitelist_users = os.getenv("WHITELIST_USERS")
# print whitelist_users object type
if whitelist_users: if whitelist_users:
if len(whitelist_users) > 0: if len(whitelist_users) > 0:
whitelist_users = whitelist_users.split(",") whitelist_users = whitelist_users.split(",")

View File

@@ -5,11 +5,12 @@ load_dotenv(override=True)
logfile = os.getenv("LOGFILE","log.log") logfile = os.getenv("LOGFILE","log.log")
def logger(message, log_type=0): def logger(message, log_type=0):
debug = str_to_bool(os.getenv("DEBUG", "True"))
output = str(message) output = str(message)
if log_type == 0: if log_type == 0:
pass pass
elif log_type == 1: elif log_type == 1 and debug:
output = f"[INFO]: {output}" output = f"[INFO]: {output}"
elif log_type == 2: elif log_type == 2:
output = f"[ERROR]: {output}" output = f"[ERROR]: {output}"

View File

@@ -130,18 +130,19 @@ class Jellyfin():
return users_watched return users_watched
def update_watched(self, watched_list, user_mapping, dryrun=False): def update_watched(self, watched_list, user_mapping=None, dryrun=False):
for user, libraries in watched_list.items(): for user, libraries in watched_list.items():
other = None if user_mapping:
if user in user_mapping.keys(): other = None
other = user_mapping[user]
if user in user_mapping.keys():
other = user_mapping[user]
elif user in user_mapping.values():
other = search_mapping(user_mapping, user)
elif user in user_mapping.values(): if other:
other = search_mapping(user_mapping, user) logger(f"Swapping user {user} with {other}", 1)
user = other
if other:
logger(f"Swapping user {user} with {other}", 1)
user = other
user_id = None user_id = None
for key, value in self.users.items(): for key, value in self.users.items():
@@ -175,7 +176,7 @@ class Jellyfin():
for video in videos: for video in videos:
for key, value in jellyfin_video["ProviderIds"].items(): for key, value in jellyfin_video["ProviderIds"].items():
if key.lower() in video.keys() and value.lower() == video[key.lower()].lower(): if key.lower() in video.keys() and value.lower() == video[key.lower()].lower():
msg = f"{jellyfin_video['Name']} as watched for {user}" msg = f"{jellyfin_video['Name']} as watched for {user} in Jellyfin"
if not dryrun: if not dryrun:
logger(f"Marking {msg}", 0) logger(f"Marking {msg}", 0)
self.query(f"/Users/{user_id}/PlayedItems/{jellyfin_video_id}", "post") self.query(f"/Users/{user_id}/PlayedItems/{jellyfin_video_id}", "post")

View File

@@ -119,25 +119,25 @@ class Plex:
return users_watched return users_watched
def update_watched(self, watched_list, user_mapping, dryrun=False): def update_watched(self, watched_list, user_mapping=None, dryrun=False):
for user, libraries in watched_list.items(): for user, libraries in watched_list.items():
other = None if user_mapping:
if user in user_mapping.keys(): other = None
other = user_mapping[user]
if user in user_mapping.keys():
other = user_mapping[user]
elif user in user_mapping.values():
other = search_mapping(user_mapping, user)
elif user in user_mapping.values(): if other:
other = search_mapping(user_mapping, user) logger(f"Swapping user {user} with {other}", 1)
user = other
if other:
logger(f"Swapping user {user} with {other}", 1)
user = other
for index, value in enumerate(self.users): for index, value in enumerate(self.users):
if user.lower() == value.title.lower(): if user.lower() == value.title.lower():
user = self.users[index] user = self.users[index]
break break
print(user)
if self.admin_user == user: if self.admin_user == user:
user_plex = self.plex user_plex = self.plex
else: else:
@@ -156,7 +156,7 @@ class Plex:
for video_keys, video_id in video.items(): for video_keys, video_id in video.items():
if video_keys == guid_source and video_id == guid_id: if video_keys == guid_source and video_id == guid_id:
if movies_search.viewCount == 0: if movies_search.viewCount == 0:
msg = f"{movies_search.title} watched" msg = f"{movies_search.title} as watched for {user.title} in Plex"
if not dryrun: if not dryrun:
logger(f"Marked {msg}", 0) logger(f"Marked {msg}", 0)
movies_search.markWatched() movies_search.markWatched()