Signed-off-by: mbrucedogs <mbrucedogs@gmail.com>

This commit is contained in:
mbrucedogs 2025-07-25 12:45:51 -05:00
parent aa6608f4a5
commit b6921d6fe2
5 changed files with 55 additions and 6 deletions

View File

@ -29967,7 +29967,7 @@
}, },
"settings": { "settings": {
"cache_duration_hours": 168, "cache_duration_hours": 168,
"last_updated": "2025-07-23T20:17:15.426193" "last_updated": "2025-07-24T20:17:15.426193"
}, },
"@SingKingKaraoke": [ "@SingKingKaraoke": [
{ {

26
examine_cache.py Normal file
View File

@ -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())}")

View File

@ -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") print(f" 📊 Channel has {len(available_videos)} videos to scan against {len(undownloaded)} songlist songs")
matches_this_channel = 0 matches_this_channel = 0
video_matches = [] # Initialize video_matches for this channel
# Pre-process video titles for efficient matching # Pre-process video titles for efficient matching
if fuzzy_match: if fuzzy_match:
# For fuzzy matching, create normalized video keys # For fuzzy matching, create normalized video keys
video_matches = []
for video in available_videos: for video in available_videos:
v_artist, v_title = extract_artist_title(video['title']) v_artist, v_title = extract_artist_title(video['title'])
video_key = create_song_key(v_artist, v_title) video_key = create_song_key(v_artist, v_title)

View File

@ -241,10 +241,31 @@ class TrackingManager:
channel_name, channel_id = None, None channel_name, channel_id = None, None
from karaoke_downloader.youtube_utils import get_channel_info from karaoke_downloader.youtube_utils import get_channel_info
channel_name, channel_id = get_channel_info(channel_url) 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: if not force_refresh and cache_key in self.cache:
print(f" 📋 Using cached video list ({len(self.cache[cache_key])} videos)") print(f" 📋 Using cached video list ({len(self.cache[cache_key])} videos)")
return self.cache[cache_key] return self.cache[cache_key]
else:
print(f" ❌ Cache miss for all keys")
# Fetch with yt-dlp # Fetch with yt-dlp
print(f" 🌐 Fetching video list from YouTube (this may take a while)...") print(f" 🌐 Fetching video list from YouTube (this may take a while)...")
import subprocess import subprocess

View File

@ -12,17 +12,19 @@ def get_channel_info(channel_url: str, yt_dlp_path: str = "downloader/yt-dlp.exe
try: try:
# Extract channel name from URL for now (faster than calling yt-dlp) # Extract channel name from URL for now (faster than calling yt-dlp)
if "/@" in channel_url: 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: elif "/channel/" in channel_url:
channel_name = channel_url.split("/channel/")[1].split("/")[0] channel_name = channel_url.split("/channel/")[1].split("/")[0]
else: else:
channel_name = "Unknown" channel_name = "Unknown"
# Extract channel ID from URL # Extract channel ID from URL (keep @ symbol for @ channels)
if "/channel/" in channel_url: if "/channel/" in channel_url:
channel_id = channel_url.split("/channel/")[1].split("/")[0] channel_id = channel_url.split("/channel/")[1].split("/")[0]
elif "/@" in channel_url: 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: else:
channel_id = channel_url channel_id = channel_url