Signed-off-by: mbrucedogs <mbrucedogs@gmail.com>
This commit is contained in:
parent
42e7a6a09c
commit
409e66780c
@ -383,6 +383,67 @@ class KaraokeDownloader:
|
|||||||
if not videos_to_download:
|
if not videos_to_download:
|
||||||
print("🎵 No new videos to download.")
|
print("🎵 No new videos to download.")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Create download plan for caching and resuming
|
||||||
|
download_plan = []
|
||||||
|
for video, artist, title, filename in videos_to_download:
|
||||||
|
download_plan.append({
|
||||||
|
"video_id": video["id"],
|
||||||
|
"artist": artist,
|
||||||
|
"title": title,
|
||||||
|
"filename": filename,
|
||||||
|
"channel_name": channel_name,
|
||||||
|
"video_title": video.get("title", ""),
|
||||||
|
"force_download": force_download
|
||||||
|
})
|
||||||
|
|
||||||
|
# Cache the download plan for resuming
|
||||||
|
import hashlib
|
||||||
|
from karaoke_downloader.cache_manager import get_download_plan_cache_file, save_plan_cache, load_cached_plan
|
||||||
|
|
||||||
|
plan_kwargs = {
|
||||||
|
"channel": channel_name,
|
||||||
|
"total_videos": len(available_videos),
|
||||||
|
"force_download": force_download,
|
||||||
|
}
|
||||||
|
if limit:
|
||||||
|
plan_kwargs["limit"] = limit
|
||||||
|
|
||||||
|
cache_file = get_download_plan_cache_file("all_videos", **plan_kwargs)
|
||||||
|
|
||||||
|
# Check for existing cache
|
||||||
|
cached_plan, _ = load_cached_plan(cache_file)
|
||||||
|
if cached_plan and not force_refresh:
|
||||||
|
print(f"\n📋 Found existing download plan cache: {cache_file.name}")
|
||||||
|
print(f" 🎬 Cached videos to download: {len(cached_plan)}")
|
||||||
|
download_plan = cached_plan
|
||||||
|
else:
|
||||||
|
# Create new download plan
|
||||||
|
download_plan = []
|
||||||
|
for video, artist, title, filename in videos_to_download:
|
||||||
|
download_plan.append({
|
||||||
|
"video_id": video["id"],
|
||||||
|
"artist": artist,
|
||||||
|
"title": title,
|
||||||
|
"filename": filename,
|
||||||
|
"channel_name": channel_name,
|
||||||
|
"video_title": video.get("title", ""),
|
||||||
|
"force_download": force_download
|
||||||
|
})
|
||||||
|
|
||||||
|
# Save the new plan to cache
|
||||||
|
save_plan_cache(cache_file, download_plan, []) # No unmatched for all-videos mode
|
||||||
|
|
||||||
|
# Show download plan summary
|
||||||
|
print(f"\n📋 Download Plan Summary:")
|
||||||
|
print(f" 📺 Channel: {channel_name}")
|
||||||
|
print(f" 🎬 Total videos to download: {len(videos_to_download)}")
|
||||||
|
print(f" ⏭️ Videos skipped: {skipped_count}")
|
||||||
|
if limit:
|
||||||
|
print(f" 🎯 Limit applied: {limit} videos")
|
||||||
|
print(f" 📁 Output directory: downloads/{channel_name}/")
|
||||||
|
print(f" 💾 Download plan cached to: {cache_file.name}")
|
||||||
|
print(f"\n🎬 Starting downloads...")
|
||||||
|
|
||||||
# Download videos using the download pipeline
|
# Download videos using the download pipeline
|
||||||
pipeline = DownloadPipeline(
|
pipeline = DownloadPipeline(
|
||||||
@ -394,22 +455,30 @@ class KaraokeDownloader:
|
|||||||
)
|
)
|
||||||
|
|
||||||
success_count = 0
|
success_count = 0
|
||||||
for i, (video, artist, title, filename) in enumerate(videos_to_download, 1):
|
total_to_download = len(download_plan)
|
||||||
print(f"⬇️ Downloading {i}/{len(videos_to_download)}: {artist} - {title}")
|
for i, plan_item in enumerate(download_plan[:], 1): # Use slice to create a copy for iteration
|
||||||
|
print(f"⬇️ Downloading {i}/{total_to_download}: {plan_item['artist']} - {plan_item['title']}")
|
||||||
|
|
||||||
if pipeline.execute_pipeline(
|
if pipeline.execute_pipeline(
|
||||||
video_id=video["id"],
|
video_id=plan_item["video_id"],
|
||||||
artist=artist,
|
artist=plan_item["artist"],
|
||||||
title=title,
|
title=plan_item["title"],
|
||||||
channel_name=channel_name,
|
channel_name=plan_item["channel_name"],
|
||||||
video_title=video.get("title", ""),
|
video_title=plan_item["video_title"],
|
||||||
):
|
):
|
||||||
print(f"✅ Successfully downloaded: {artist} - {title}")
|
|
||||||
success_count += 1
|
success_count += 1
|
||||||
else:
|
# Remove completed item from cache
|
||||||
print(f"❌ Failed to download: {artist} - {title}")
|
download_plan.remove(plan_item) # Remove the current item
|
||||||
|
if download_plan: # If there are still items left
|
||||||
|
save_plan_cache(cache_file, download_plan, [])
|
||||||
|
print(f"🗑️ Removed completed item from download plan. {len(download_plan)} items remaining.")
|
||||||
|
else:
|
||||||
|
# All downloads completed, delete the cache file
|
||||||
|
from karaoke_downloader.cache_manager import delete_plan_cache
|
||||||
|
delete_plan_cache(cache_file)
|
||||||
|
print("🗑️ All downloads completed, deleted download plan cache.")
|
||||||
|
|
||||||
print(f"\n🎉 Download complete! {success_count}/{len(videos_to_download)} videos downloaded successfully")
|
print(f"\n🎉 Download complete! {success_count}/{total_to_download} videos downloaded successfully")
|
||||||
return success_count > 0
|
return success_count > 0
|
||||||
|
|
||||||
def download_songlist_across_channels(
|
def download_songlist_across_channels(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user