feat: organize nextcloud clips folder structure under date/title_id subfolders
This commit is contained in:
@@ -206,18 +206,30 @@ async def process_queue(bot):
|
|||||||
log.info(f"[queue] Job done. Queue size now: {queue.qsize()}")
|
log.info(f"[queue] Job done. Queue size now: {queue.qsize()}")
|
||||||
|
|
||||||
|
|
||||||
|
def get_yt_id(url: str) -> str:
|
||||||
|
"""Extract YouTube video ID from URL."""
|
||||||
|
match = re.search(r"(?:v=|\/shorts\/|\/embed\/|\/v\/|youtu\.be\/)([a-zA-Z0-9_-]{11})", url)
|
||||||
|
return match.group(1) if match else "unknown"
|
||||||
|
|
||||||
|
|
||||||
# ─── Main video processor ─────────────────────────────────────────────────────
|
# ─── Main video processor ─────────────────────────────────────────────────────
|
||||||
async def process_video(bot, url: str):
|
async def process_video(bot, url: str):
|
||||||
log.info(f"[process] ===== Starting process_video =====")
|
log.info(f"[process] ===== Starting process_video =====")
|
||||||
log.info(f"[process] URL: {url}")
|
log.info(f"[process] URL: {url}")
|
||||||
|
|
||||||
# 1. Get title
|
# 1. Extract video ID and Get title
|
||||||
|
yt_id = get_yt_id(url)
|
||||||
title = await get_video_title(url)
|
title = await get_video_title(url)
|
||||||
log.info(f"[process] Video title: {title!r}")
|
log.info(f"[process] Video ID: {yt_id}, Title: {title!r}")
|
||||||
|
|
||||||
safe = re.sub(r'[<>:"/\\|?*#\s]+', "_", title)[:80] or "video"
|
safe_title = re.sub(r'[<>:"/\\|?*#\s]+', "_", title)[:60].strip("_") or "video"
|
||||||
folder = f"{safe}_{datetime.now():%Y-%m-%d}"
|
title_folder = f"{safe_title}_{yt_id}"
|
||||||
|
date_folder = datetime.now().strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
# Target folder: YYYY-MM-DD/title_id
|
||||||
|
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}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user