From b6921d6fe2de1896ad9fe5360ba8e36477b3473e Mon Sep 17 00:00:00 2001 From: mbrucedogs Date: Fri, 25 Jul 2025 12:45:51 -0500 Subject: [PATCH] Signed-off-by: mbrucedogs --- data/channel_cache.json | 2 +- examine_cache.py | 26 ++++++++++++++++++++++++++ karaoke_downloader/download_planner.py | 2 +- karaoke_downloader/tracking_manager.py | 23 ++++++++++++++++++++++- karaoke_downloader/youtube_utils.py | 8 +++++--- 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 examine_cache.py diff --git a/data/channel_cache.json b/data/channel_cache.json index d06bb06..d71c2a9 100644 --- a/data/channel_cache.json +++ b/data/channel_cache.json @@ -29967,7 +29967,7 @@ }, "settings": { "cache_duration_hours": 168, - "last_updated": "2025-07-23T20:17:15.426193" + "last_updated": "2025-07-24T20:17:15.426193" }, "@SingKingKaraoke": [ { diff --git a/examine_cache.py b/examine_cache.py new file mode 100644 index 0000000..af1de99 --- /dev/null +++ b/examine_cache.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import json + +# Load the cache file +with open('data/channel_cache.json', 'r', encoding='utf-8') as f: + cache = json.load(f) + +print(f"šŸ“‹ Channel cache type: {type(cache)}") +print(f"šŸ“‹ Channel cache keys: {list(cache.keys())}") + +# Check if it's a dictionary with channel URLs as keys +if isinstance(cache, dict): + print(f"\nšŸ” First few cache entries:") + for i, (key, value) in enumerate(list(cache.items())[:3]): + print(f" {i+1}. Key: '{key}'") + print(f" Type: {type(value)}") + if isinstance(value, list): + print(f" Length: {len(value)} videos") + if value: + print(f" First video: {value[0]}") + print() + +# Check if there's a "channels" key +if "channels" in cache: + print(f"šŸ” Found 'channels' key with {len(cache['channels'])} entries") + print(f"šŸ” Channels keys: {list(cache['channels'].keys())}") \ No newline at end of file diff --git a/karaoke_downloader/download_planner.py b/karaoke_downloader/download_planner.py index cbe5ce8..5b0b4da 100644 --- a/karaoke_downloader/download_planner.py +++ b/karaoke_downloader/download_planner.py @@ -57,11 +57,11 @@ def build_download_plan(channel_urls, undownloaded, tracker, yt_dlp_path, fuzzy_ ) print(f" šŸ“Š Channel has {len(available_videos)} videos to scan against {len(undownloaded)} songlist songs") matches_this_channel = 0 + video_matches = [] # Initialize video_matches for this channel # Pre-process video titles for efficient matching if fuzzy_match: # For fuzzy matching, create normalized video keys - video_matches = [] for video in available_videos: v_artist, v_title = extract_artist_title(video['title']) video_key = create_song_key(v_artist, v_title) diff --git a/karaoke_downloader/tracking_manager.py b/karaoke_downloader/tracking_manager.py index 43cabc6..67a3e28 100644 --- a/karaoke_downloader/tracking_manager.py +++ b/karaoke_downloader/tracking_manager.py @@ -241,10 +241,31 @@ class TrackingManager: channel_name, channel_id = None, None from karaoke_downloader.youtube_utils import get_channel_info channel_name, channel_id = get_channel_info(channel_url) - cache_key = channel_id or channel_url + + # Try multiple possible cache keys + possible_keys = [ + channel_id, # The extracted channel ID + channel_url, # The full URL + channel_name # The extracted channel name + ] + + cache_key = None + for key in possible_keys: + if key and key in self.cache: + cache_key = key + break + + if not cache_key: + cache_key = channel_id or channel_url # Use as fallback for new entries + + print(f" šŸ” Trying cache keys: {possible_keys}") + print(f" šŸ” Selected cache key: '{cache_key}'") + if not force_refresh and cache_key in self.cache: print(f" šŸ“‹ Using cached video list ({len(self.cache[cache_key])} videos)") return self.cache[cache_key] + else: + print(f" āŒ Cache miss for all keys") # Fetch with yt-dlp print(f" 🌐 Fetching video list from YouTube (this may take a while)...") import subprocess diff --git a/karaoke_downloader/youtube_utils.py b/karaoke_downloader/youtube_utils.py index f5d8bd2..5ada9f2 100644 --- a/karaoke_downloader/youtube_utils.py +++ b/karaoke_downloader/youtube_utils.py @@ -12,17 +12,19 @@ def get_channel_info(channel_url: str, yt_dlp_path: str = "downloader/yt-dlp.exe try: # Extract channel name from URL for now (faster than calling yt-dlp) if "/@" in channel_url: - channel_name = channel_url.split("/@")[1].split("/")[0] + # Keep the @ symbol for cache key consistency + channel_name = "@" + channel_url.split("/@")[1].split("/")[0] elif "/channel/" in channel_url: channel_name = channel_url.split("/channel/")[1].split("/")[0] else: channel_name = "Unknown" - # Extract channel ID from URL + # Extract channel ID from URL (keep @ symbol for @ channels) if "/channel/" in channel_url: channel_id = channel_url.split("/channel/")[1].split("/")[0] elif "/@" in channel_url: - channel_id = channel_url.split("/@")[1].split("/")[0] + # Keep the @ symbol for cache key consistency + channel_id = "@" + channel_url.split("/@")[1].split("/")[0] else: channel_id = channel_url