Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas committed Jan 5, 2025
1 parent bf3a1be commit 7f81b89
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions plugins/trakt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]})
Expand Down Expand Up @@ -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"]
Expand All @@ -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"]
Expand All @@ -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:
Expand Down

0 comments on commit 7f81b89

Please sign in to comment.