From 419dd19faa8dd87f73ae78a9f31de26781431164 Mon Sep 17 00:00:00 2001 From: MMaker Date: Thu, 27 Feb 2025 11:30:12 -0500 Subject: [PATCH] Clean up logging levels --- app.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index 67ffd30..6abbe59 100644 --- a/app.py +++ b/app.py @@ -37,7 +37,7 @@ CACHE_SIZE_LIMIT = 100 * 1024 * 1024 # 100 MB cache = None if os.environ.get('NICONICOGAY_DISABLE_CACHE', '') != '1': cache = Cache("disk_cache", size_limit=CACHE_SIZE_LIMIT) - logger.info("Using disk cache") + logger.debug("Using disk cache") else: logger.info("Disk cache disabled") @@ -47,7 +47,7 @@ try: cookie_jar.load(ignore_discard=True, ignore_expires=True) user_session = next((cookie.value for cookie in cookie_jar if cookie.name == 'user_session'), None) except FileNotFoundError: - logger.warning("cookies.txt not found, starting with empty cookie jar") + logger.info("cookies.txt not found, starting with empty cookie jar") s = requests.Session() s.headers.update({ @@ -70,7 +70,7 @@ if all(key in os.environ for key in [ config=BotoConfig(s3={'addressing_style': 'virtual'}), ) else: - logger.warning("S3 credentials not provided. Videos will not be downloaded.") + logger.info("S3 credentials not provided. Videos will not be downloaded.") download_tracker = { 'active_downloads': 0, @@ -89,7 +89,7 @@ def download_and_upload_video(video_id, url, video_quality): temp_path = temp_file.name try: - logger.info(f"Starting download for video ID: {video_id}") + logger.info(f"Starting video download of {video_id}") nndownload_args = [ "--no-login", "--user-agent", "Googlebot/2.1", @@ -119,7 +119,7 @@ def download_and_upload_video(video_id, url, video_quality): cache.set(f"{video_id}_uploaded", True, expire=CACHE_EXPIRATION_SECONDS) # Clear HTML cache for this video to ensure next view gets updated HTML cache.delete(f"{video_id}_html") - logger.info(f"Cleared cache for video ID: {video_id}") + logger.debug(f"Cleared cache for video ID: {video_id}") return True except Exception as e: @@ -131,7 +131,7 @@ def download_and_upload_video(video_id, url, video_quality): finally: if os.path.exists(temp_path): os.unlink(temp_path) - logger.info(f"Removed temporary file: {temp_path}") + logger.debug(f"Removed temporary file: {temp_path}") except Exception as e: logger.error(f"Error in download process for video {video_id}: {e}") return False @@ -167,7 +167,7 @@ worker_thread.start() def is_video_in_cdn(video_id): """Check if video exists in CDN""" if cache is not None and cache.get(f"{video_id}_uploaded"): - logger.info(f"Video {video_id} is already uploaded to CDN (cached)") + logger.debug(f"Video {video_id} is already uploaded to CDN (cached)") return True if not s3_client: @@ -211,7 +211,7 @@ def get_video_quality(params, quality_level_threshold=3): def get_data(video_id, real_url): """Get the server response for a given video ID""" try: - logger.info(f"Fetching content from URL: {real_url}") + logger.debug(f"Fetching content from URL: {real_url}") r = s.get(real_url, timeout=10) # r.raise_for_status() except requests.RequestException as e: @@ -282,13 +282,13 @@ def proxy(video_id): logger.info(f"Received request for video ID: {video_id}") if cache is not None: - logging.info(f"Checking cache for video ID: {video_id}") + logger.debug(f"Checking cache for video ID: {video_id}") cached_html = cache.get(f"{video_id}_html") if cached_html is not None: - logger.info(f"Using cached response for video ID: {video_id}") + logger.debug(f"Using cached response for video ID: {video_id}") return Response(cached_html, mimetype="text/html") # type: ignore - logging.info(f"Cache miss for video ID: {video_id} - fetching") + logger.debug(f"Cache miss for video ID: {video_id} - fetching") # Not in cache or cache expired; fetch from nicovideo.jp real_url = f"https://www.nicovideo.jp/watch/{video_id}" @@ -360,10 +360,10 @@ if you want to download videos, please consider using a tool like nndownload: ht """ if cache is not None: - logging.info(f"Caching response for video ID: {video_id}") + logger.info(f"Caching response for video ID: {video_id}") cache.set(f"{video_id}_html", html_response, expire=CACHE_EXPIRATION_SECONDS) - logging.info(f"Returning response for video ID: {video_id}") + logger.debug(f"Returning response for video ID: {video_id}") return Response(html_response, mimetype="text/html") @app.route("/owoembed") @@ -398,5 +398,5 @@ def owoembed(): "version": "1.0" } - logger.info(f"Returning oEmbed response for video ID: {video_id}") + logger.debug(f"Returning oEmbed response for video ID: {video_id}") return jsonify(oembed_response)