From 8678cb3d7fe39c18389bd7d707af631315aa9aa9 Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Fri, 31 Oct 2025 13:55:36 +1100 Subject: [PATCH] Update --- backend/app/api/auto_download.py | 30 +++++++++++-------- .../components/download/DownloadCenter.tsx | 7 ++--- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/backend/app/api/auto_download.py b/backend/app/api/auto_download.py index 0a4dce5..d029b71 100644 --- a/backend/app/api/auto_download.py +++ b/backend/app/api/auto_download.py @@ -32,21 +32,27 @@ async def process_download_job(job_id: int, db: AsyncSession): # Search for the song search_results = await music_searcher.search_all(job.song_name, limit=10) - # Combine results + # Combine results and filter out short clips (< 90 seconds) to avoid samples all_results = search_results.get("youtube", []) + search_results.get("bilibili", []) - - if not all_results: - job.status = "failed" - job.error_message = "No search results found" - await db.commit() - return - + + # Filter out songs shorter than 90 seconds + filtered_results = [r for r in all_results if r.duration is None or r.duration >= 90] + + if not filtered_results: + # If all results are too short, fall back to original results + filtered_results = all_results + if not filtered_results: + job.status = "failed" + job.error_message = "No search results found" + await db.commit() + return + # Store search results - job.search_results = json.dumps([r.model_dump() for r in all_results]) + job.search_results = json.dumps([r.model_dump() for r in filtered_results]) - # Find priority result (contains "official" or "官方") + # Find priority result (contains "official" or "官方") among filtered results priority_index = -1 - for i, result in enumerate(all_results): + for i, result in enumerate(filtered_results): title_lower = result.title.lower() if "official" in title_lower or "官方" in title_lower: priority_index = i @@ -55,7 +61,7 @@ async def process_download_job(job_id: int, db: AsyncSession): # Select the result (priority if found, otherwise first one) selected_index = priority_index if priority_index >= 0 else 0 - selected_result = all_results[selected_index] + selected_result = filtered_results[selected_index] job.selected_result = json.dumps(selected_result.model_dump()) job.selected_result_index = selected_index diff --git a/frontend/src/components/download/DownloadCenter.tsx b/frontend/src/components/download/DownloadCenter.tsx index 9a7c3f8..a8cbb10 100644 --- a/frontend/src/components/download/DownloadCenter.tsx +++ b/frontend/src/components/download/DownloadCenter.tsx @@ -289,9 +289,7 @@ export default function DownloadCenter({ onPlayMusic }: DownloadCenterProps) {
- {autoJobs.map((job) => { - - return ( + {autoJobs.map((job) => (
- ); - })} + ))} )}