fix: clip count uses log-tracked list not disk scan; folder structure viral_clips/date/title_ytid/
This commit is contained in:
+17
-12
@@ -222,14 +222,15 @@ async def process_video(bot, url: str):
|
|||||||
title = await get_video_title(url)
|
title = await get_video_title(url)
|
||||||
log.info(f"[process] Video ID: {yt_id}, Title: {title!r}")
|
log.info(f"[process] Video ID: {yt_id}, Title: {title!r}")
|
||||||
|
|
||||||
safe_title = re.sub(r'[<>:"/\\|?*#\s]+', "_", title)[:60].strip("_") or "video"
|
# Use title if available, else fall back to YouTube ID so folders are always unique
|
||||||
title_folder = f"{safe_title}_{yt_id}"
|
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")
|
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}"
|
folder = f"{date_folder}/{title_folder}"
|
||||||
target = f"{NEXTCLOUD_BASE}/{folder}"
|
target = f"{NEXTCLOUD_BASE}/{folder}"
|
||||||
|
|
||||||
os.makedirs(target, exist_ok=True)
|
os.makedirs(target, exist_ok=True)
|
||||||
log.info(f"[process] Nextcloud target folder: {target}")
|
log.info(f"[process] Nextcloud target folder: {target}")
|
||||||
|
|
||||||
@@ -387,13 +388,17 @@ async def process_video(bot, url: str):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning(f"[process] Nextcloud scan failed: {e}")
|
log.warning(f"[process] Nextcloud scan failed: {e}")
|
||||||
|
|
||||||
# 7. Count final clips in target folder
|
# 7. Count clips — use log-tracked list as primary (exact count for THIS run),
|
||||||
try:
|
# fall back to disk count only if parser got 0 (e.g. regex didn't match)
|
||||||
final_clips = [f for f in os.listdir(target) if f.endswith(".mp4") and not f.startswith("temp_")]
|
total_done = len(completed_clips)
|
||||||
total_done = len(final_clips)
|
if total_done == 0:
|
||||||
log.info(f"[process] Final clip count in Nextcloud folder: {total_done}")
|
try:
|
||||||
except Exception:
|
disk_clips = [f for f in os.listdir(target) if f.endswith(".mp4") and not f.startswith("temp_")]
|
||||||
total_done = len(completed_clips)
|
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
|
# 8. Final completion message
|
||||||
if rc == 0 and total_done > 0:
|
if rc == 0 and total_done > 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user