Clean up logging levels
This commit is contained in:
parent
4ac1fba240
commit
419dd19faa
28
app.py
28
app.py
@ -37,7 +37,7 @@ CACHE_SIZE_LIMIT = 100 * 1024 * 1024 # 100 MB
|
|||||||
cache = None
|
cache = None
|
||||||
if os.environ.get('NICONICOGAY_DISABLE_CACHE', '') != '1':
|
if os.environ.get('NICONICOGAY_DISABLE_CACHE', '') != '1':
|
||||||
cache = Cache("disk_cache", size_limit=CACHE_SIZE_LIMIT)
|
cache = Cache("disk_cache", size_limit=CACHE_SIZE_LIMIT)
|
||||||
logger.info("Using disk cache")
|
logger.debug("Using disk cache")
|
||||||
else:
|
else:
|
||||||
logger.info("Disk cache disabled")
|
logger.info("Disk cache disabled")
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ try:
|
|||||||
cookie_jar.load(ignore_discard=True, ignore_expires=True)
|
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)
|
user_session = next((cookie.value for cookie in cookie_jar if cookie.name == 'user_session'), None)
|
||||||
except FileNotFoundError:
|
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 = requests.Session()
|
||||||
s.headers.update({
|
s.headers.update({
|
||||||
@ -70,7 +70,7 @@ if all(key in os.environ for key in [
|
|||||||
config=BotoConfig(s3={'addressing_style': 'virtual'}),
|
config=BotoConfig(s3={'addressing_style': 'virtual'}),
|
||||||
)
|
)
|
||||||
else:
|
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 = {
|
download_tracker = {
|
||||||
'active_downloads': 0,
|
'active_downloads': 0,
|
||||||
@ -89,7 +89,7 @@ def download_and_upload_video(video_id, url, video_quality):
|
|||||||
temp_path = temp_file.name
|
temp_path = temp_file.name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.info(f"Starting download for video ID: {video_id}")
|
logger.info(f"Starting video download of {video_id}")
|
||||||
nndownload_args = [
|
nndownload_args = [
|
||||||
"--no-login",
|
"--no-login",
|
||||||
"--user-agent", "Googlebot/2.1",
|
"--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)
|
cache.set(f"{video_id}_uploaded", True, expire=CACHE_EXPIRATION_SECONDS)
|
||||||
# Clear HTML cache for this video to ensure next view gets updated HTML
|
# Clear HTML cache for this video to ensure next view gets updated HTML
|
||||||
cache.delete(f"{video_id}_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
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -131,7 +131,7 @@ def download_and_upload_video(video_id, url, video_quality):
|
|||||||
finally:
|
finally:
|
||||||
if os.path.exists(temp_path):
|
if os.path.exists(temp_path):
|
||||||
os.unlink(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:
|
except Exception as e:
|
||||||
logger.error(f"Error in download process for video {video_id}: {e}")
|
logger.error(f"Error in download process for video {video_id}: {e}")
|
||||||
return False
|
return False
|
||||||
@ -167,7 +167,7 @@ worker_thread.start()
|
|||||||
def is_video_in_cdn(video_id):
|
def is_video_in_cdn(video_id):
|
||||||
"""Check if video exists in CDN"""
|
"""Check if video exists in CDN"""
|
||||||
if cache is not None and cache.get(f"{video_id}_uploaded"):
|
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
|
return True
|
||||||
|
|
||||||
if not s3_client:
|
if not s3_client:
|
||||||
@ -211,7 +211,7 @@ def get_video_quality(params, quality_level_threshold=3):
|
|||||||
def get_data(video_id, real_url):
|
def get_data(video_id, real_url):
|
||||||
"""Get the server response for a given video ID"""
|
"""Get the server response for a given video ID"""
|
||||||
try:
|
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 = s.get(real_url, timeout=10)
|
||||||
# r.raise_for_status()
|
# r.raise_for_status()
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
@ -282,13 +282,13 @@ def proxy(video_id):
|
|||||||
logger.info(f"Received request for video ID: {video_id}")
|
logger.info(f"Received request for video ID: {video_id}")
|
||||||
|
|
||||||
if cache is not None:
|
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")
|
cached_html = cache.get(f"{video_id}_html")
|
||||||
if cached_html is not None:
|
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
|
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
|
# Not in cache or cache expired; fetch from nicovideo.jp
|
||||||
real_url = f"https://www.nicovideo.jp/watch/{video_id}"
|
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
|
|||||||
</head><body></body></html>"""
|
</head><body></body></html>"""
|
||||||
|
|
||||||
if cache is not None:
|
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)
|
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")
|
return Response(html_response, mimetype="text/html")
|
||||||
|
|
||||||
@app.route("/owoembed")
|
@app.route("/owoembed")
|
||||||
@ -398,5 +398,5 @@ def owoembed():
|
|||||||
"version": "1.0"
|
"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)
|
return jsonify(oembed_response)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user