fix: replace get_event_loop with get_running_loop and utcnow consistently
This commit is contained in:
@@ -16,6 +16,7 @@ from pathlib import Path
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from app.config import get_settings
|
from app.config import get_settings
|
||||||
|
from app.models.base import utcnow
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -369,6 +370,22 @@ class GalleryDLService:
|
|||||||
]
|
]
|
||||||
has_actual_error = any(err in combined for err in actual_error_indicators)
|
has_actual_error = any(err in combined for err in actual_error_indicators)
|
||||||
|
|
||||||
|
# Per-item access warnings (e.g., "Not allowed to view post" on Patreon
|
||||||
|
# /c/user/posts URLs) are normal in multi-post downloads where some posts
|
||||||
|
# are paywalled. These shouldn't block skip detection when the overall
|
||||||
|
# download proceeded successfully with skips.
|
||||||
|
if has_actual_error and (skip_line_count > 0 or has_skip_text):
|
||||||
|
per_item_patterns = ["not allowed to view", "unable to get post"]
|
||||||
|
error_lines = [
|
||||||
|
line for line in combined.split('\n')
|
||||||
|
if any(ind in line for ind in actual_error_indicators)
|
||||||
|
]
|
||||||
|
if error_lines and all(
|
||||||
|
any(p in line for p in per_item_patterns)
|
||||||
|
for line in error_lines
|
||||||
|
):
|
||||||
|
has_actual_error = False
|
||||||
|
|
||||||
# If we have skip evidence and no real errors, it's no_new_content
|
# If we have skip evidence and no real errors, it's no_new_content
|
||||||
if (skip_line_count > 0 or has_skip_text) and not has_actual_error:
|
if (skip_line_count > 0 or has_skip_text) and not has_actual_error:
|
||||||
return ErrorType.NO_NEW_CONTENT, "No new content to download"
|
return ErrorType.NO_NEW_CONTENT, "No new content to download"
|
||||||
@@ -487,9 +504,11 @@ class GalleryDLService:
|
|||||||
if "no suitable" in combined or "unsupported" in combined or "no extractor" in combined:
|
if "no suitable" in combined or "unsupported" in combined or "no extractor" in combined:
|
||||||
return ErrorType.UNSUPPORTED_URL, "URL format not supported by gallery-dl"
|
return ErrorType.UNSUPPORTED_URL, "URL format not supported by gallery-dl"
|
||||||
|
|
||||||
# If we got here with return code 1 and saw some activity but no error patterns matched,
|
# If we got here with a non-catastrophic return code, saw skip activity, and no
|
||||||
# it's likely just no new content (gallery-dl returns 1 when nothing to download)
|
# specific error patterns matched, it's likely just no new content.
|
||||||
if return_code == 1 and stdout.strip() and not has_actual_error:
|
# gallery-dl exit codes: 1 = some extractions skipped, 4 = no URLs extracted
|
||||||
|
# (common with /c/user/posts Patreon URLs where all content is already archived)
|
||||||
|
if return_code in (1, 4) and (skip_line_count > 0 or has_skip_text) and not has_actual_error:
|
||||||
return ErrorType.NO_NEW_CONTENT, "No new content to download"
|
return ErrorType.NO_NEW_CONTENT, "No new content to download"
|
||||||
|
|
||||||
# Final fallback - genuine unknown error
|
# Final fallback - genuine unknown error
|
||||||
@@ -537,10 +556,9 @@ class GalleryDLService:
|
|||||||
Downloads are saved to: {download_path}/{subscription_name}/{platform}/{post_folders}
|
Downloads are saved to: {download_path}/{subscription_name}/{platform}/{post_folders}
|
||||||
"""
|
"""
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
started_at = datetime.utcnow().isoformat()
|
started_at = utcnow().isoformat()
|
||||||
|
|
||||||
# Use default config if none provided
|
# Use default config if none provided
|
||||||
if source_config is None:
|
if source_config is None:
|
||||||
@@ -595,7 +613,7 @@ class GalleryDLService:
|
|||||||
|
|
||||||
# Execute subprocess
|
# Execute subprocess
|
||||||
# Run in thread pool to not block async event loop
|
# Run in thread pool to not block async event loop
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_running_loop()
|
||||||
proc = await loop.run_in_executor(
|
proc = await loop.run_in_executor(
|
||||||
None,
|
None,
|
||||||
lambda: subprocess.run(
|
lambda: subprocess.run(
|
||||||
@@ -607,7 +625,7 @@ class GalleryDLService:
|
|||||||
)
|
)
|
||||||
|
|
||||||
duration = time.time() - start_time
|
duration = time.time() - start_time
|
||||||
completed_at = datetime.utcnow().isoformat()
|
completed_at = utcnow().isoformat()
|
||||||
|
|
||||||
# Log output
|
# Log output
|
||||||
if proc.stdout:
|
if proc.stdout:
|
||||||
@@ -668,7 +686,7 @@ class GalleryDLService:
|
|||||||
error_message=f"Download timed out after {source_config.timeout} seconds",
|
error_message=f"Download timed out after {source_config.timeout} seconds",
|
||||||
duration_seconds=duration,
|
duration_seconds=duration,
|
||||||
started_at=started_at,
|
started_at=started_at,
|
||||||
completed_at=datetime.utcnow().isoformat(),
|
completed_at=utcnow().isoformat(),
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -684,7 +702,7 @@ class GalleryDLService:
|
|||||||
error_message=str(e),
|
error_message=str(e),
|
||||||
duration_seconds=duration,
|
duration_seconds=duration,
|
||||||
started_at=started_at,
|
started_at=started_at,
|
||||||
completed_at=datetime.utcnow().isoformat(),
|
completed_at=utcnow().isoformat(),
|
||||||
)
|
)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user