fix: clip count uses log-tracked list not disk scan; folder structure viral_clips/date/title_ytid/

This commit is contained in:
Renato
2026-07-02 19:55:47 +02:00
parent 1ecb8d32c8
commit 4b0e66f5c2
+15 -10
View File
@@ -222,11 +222,12 @@ async def process_video(bot, url: str):
title = await get_video_title(url)
log.info(f"[process] Video ID: {yt_id}, Title: {title!r}")
safe_title = re.sub(r'[<>:"/\\|?*#\s]+', "_", title)[:60].strip("_") or "video"
title_folder = f"{safe_title}_{yt_id}"
# Use title if available, else fall back to YouTube ID so folders are always unique
safe_title = re.sub(r'[<>:"/\\|?*#\s]+', "_", title)[:60].strip("_") if title and title != "video" else ""
title_folder = f"{safe_title}_{yt_id}" if safe_title else yt_id
date_folder = datetime.now().strftime("%Y-%m-%d")
# Target folder: YYYY-MM-DD/title_id
# Target folder: viral_clips/YYYY-MM-DD/video_title_ytid/
folder = f"{date_folder}/{title_folder}"
target = f"{NEXTCLOUD_BASE}/{folder}"
@@ -387,13 +388,17 @@ async def process_video(bot, url: str):
except Exception as e:
log.warning(f"[process] Nextcloud scan failed: {e}")
# 7. Count final clips in target folder
try:
final_clips = [f for f in os.listdir(target) if f.endswith(".mp4") and not f.startswith("temp_")]
total_done = len(final_clips)
log.info(f"[process] Final clip count in Nextcloud folder: {total_done}")
except Exception:
total_done = len(completed_clips)
# 7. Count clips — use log-tracked list as primary (exact count for THIS run),
# fall back to disk count only if parser got 0 (e.g. regex didn't match)
total_done = len(completed_clips)
if total_done == 0:
try:
disk_clips = [f for f in os.listdir(target) if f.endswith(".mp4") and not f.startswith("temp_")]
total_done = len(disk_clips)
log.info(f"[process] Fallback disk count: {total_done} clips in {target}")
except Exception as e:
log.warning(f"[process] Could not count disk clips: {e}")
log.info(f"[process] Final clip count for THIS run: {total_done} (from completed_clips={len(completed_clips)})")
# 8. Final completion message
if rc == 0 and total_done > 0: