From 7f81b8993792893912ff1ea728bfb9476d12cdf2 Mon Sep 17 00:00:00 2001 From: thomas Date: Sun, 5 Jan 2025 16:21:55 +0000 Subject: [PATCH] Add logging --- main.py | 10 +++++++++- plugins/trakt.py | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index d6e42bd..667191d 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,8 @@ import pluginlib from loguru import logger from pyaml_env import parse_config +import os +import sys from apscheduler.schedulers.blocking import BlockingScheduler from apscheduler.triggers.cron import CronTrigger @@ -13,6 +15,12 @@ parser.add_argument('--config', type=str, help='Path to config file', default='config.yaml') args = parser.parse_args() +# Set logging level +log_level = os.getenv("LOG_LEVEL", "INFO").upper() +# Configure Loguru logger +logger.remove() # Remove default configuration +logger.add(sys.stderr, level=log_level) + # Load config config = parse_config(args.config, default_value=None) @@ -58,7 +66,7 @@ def main(config): # Find jellyfin collection or create it collection_id = jf_client.find_collection_with_name_or_create( - list_info['name'], + list_info['name'], list_id, list_info.get("description", None), plugin_name diff --git a/plugins/trakt.py b/plugins/trakt.py index dc81bf9..a9cb539 100644 --- a/plugins/trakt.py +++ b/plugins/trakt.py @@ -89,6 +89,7 @@ def _get_auth_token(config): # If we have already authenticated, read the access token from the file with open(Trakt._access_token_file, 'r') as f: access_token = f.read() + logger.debug("Existing access token found") else: # If we have not authenticated, get the access token from the user r = requests.post("https://api.trakt.tv/oauth/device/code", headers=headers, json={"client_id": config["client_id"]}) @@ -132,9 +133,11 @@ def get_list(list_id, config=None): access_token = Trakt._get_auth_token(config) headers["Authorization"] = f"Bearer {access_token}" + logger.debug("Access token loaded") if list_id.startswith("shows/") or list_id.startswith("movies/"): # Chart + logger.debug("Trakt chart list") r = requests.get(f"https://api.trakt.tv/{list_id}", headers=headers) list_name = Trakt._chart_types[list_id]["title"] description = Trakt._chart_types[list_id]["description"] @@ -146,6 +149,7 @@ def get_list(list_id, config=None): items_data = r.json() else: + logger.debug("Trakt User list") r = requests.get(f"https://api.trakt.tv/lists/{list_id}", headers=headers) list_name = r.json()["name"] description = r.json()["description"] @@ -154,6 +158,7 @@ def get_list(list_id, config=None): # Process the items + logger.debug("Processing items.") items = [] for item_data in items_data: if "type" in item_data: