diff --git a/api/web_routes.py b/api/web_routes.py index cc7d5e9..1b23d5e 100644 --- a/api/web_routes.py +++ b/api/web_routes.py @@ -326,6 +326,11 @@ async def update_movie_date(dependencies: dict, imdb_id: str, dateadded: Optiona """Update dateadded for a specific movie""" db = dependencies["db"] + # Debug logging to track the issue + print(f"šŸ” UPDATE_MOVIE_DATE: imdb_id={imdb_id}, dateadded={dateadded}, source={source}") + print(f" - dateadded type: {type(dateadded)}") + print(f" - dateadded repr: {repr(dateadded)}") + # Validate movie exists movie = db.get_movie_dates(imdb_id) if not movie: @@ -451,10 +456,12 @@ async def get_movie_date_options(dependencies: dict, imdb_id: str): # Debug logging to understand the data issue print(f"šŸ” DEBUG: Movie data for {imdb_id}:") - print(f" - released: {movie.get('released')}") - print(f" - dateadded: {movie.get('dateadded')}") - print(f" - source: {movie.get('source')}") - print(f" - path: {movie.get('path')}") + print(f" - released: {repr(movie.get('released'))}") + print(f" - dateadded: {repr(movie.get('dateadded'))}") + print(f" - source: {repr(movie.get('source'))}") + print(f" - path: {repr(movie.get('path'))}") + print(f" - has_video_file: {repr(movie.get('has_video_file'))}") + print(f" - last_updated: {repr(movie.get('last_updated'))}") options = [] @@ -486,18 +493,26 @@ async def get_movie_date_options(dependencies: dict, imdb_id: str): }) # Option 2: Released date as digital release (if different from current) - if movie.get('released'): - release_date = f"{movie['released']}T00:00:00" - # Only add if it's different from current dateadded - current_dateadded = movie.get('dateadded', '') - if not current_dateadded or not current_dateadded.startswith(movie['released']): - options.append({ - "type": "digital_release", - "label": "Use Actual Release Date", - "date": release_date, - "source": "digital_release", - "description": f"Use the movie's actual release date: {movie['released']} (instead of download date)" - }) + if movie.get('released') and movie['released'].strip(): + try: + release_date = f"{movie['released']}T00:00:00" + # Validate the date format + from datetime import datetime + datetime.fromisoformat(release_date.replace('Z', '+00:00')) + + # Only add if it's different from current dateadded + current_dateadded = movie.get('dateadded', '') + if not current_dateadded or not current_dateadded.startswith(movie['released']): + options.append({ + "type": "digital_release", + "label": "Use Actual Release Date", + "date": release_date, + "source": "digital_release", + "description": f"Use the movie's actual release date: {movie['released']} (instead of download date)" + }) + except Exception as e: + print(f"āš ļø Invalid released date format for {imdb_id}: {movie.get('released')} - {e}") + # Don't add this option if the date is invalid # Option 3: Manual entry options.append({ @@ -516,6 +531,10 @@ async def get_movie_date_options(dependencies: dict, imdb_id: str): except Exception: pass + print(f"šŸ” DEBUG: Generated {len(options)} options for {imdb_id}:") + for i, option in enumerate(options): + print(f" Option {i}: {option}") + return { "imdb_id": imdb_id, "current_data": movie, diff --git a/debug_movie.py b/debug_movie.py new file mode 100644 index 0000000..9b1ab32 --- /dev/null +++ b/debug_movie.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 +""" +Debug script to check specific movie data in NFOGuard database +""" +import os +import sys +from pathlib import Path + +# Add the project root to the path +sys.path.insert(0, str(Path(__file__).parent)) + +from core.database import NFOGuardDatabase + +def debug_movie(imdb_id: str): + """Debug a specific movie's data""" + print(f"šŸ” DEBUG MOVIE: {imdb_id}") + print("=" * 50) + + # Initialize database + db = NFOGuardDatabase() + + # Get movie data + movie = db.get_movie_dates(imdb_id) + if not movie: + print(f"āŒ Movie {imdb_id} not found in database") + return + + print("šŸ“Š RAW MOVIE DATA:") + for key, value in movie.items(): + print(f" {key}: {repr(value)}") + + print("\nšŸŽ¬ FORMATTED MOVIE DATA:") + print(f" Title/Path: {movie.get('path', 'Unknown')}") + print(f" Released: {movie.get('released', 'None')}") + print(f" Date Added: {movie.get('dateadded', 'None')}") + print(f" Source: {movie.get('source', 'None')}") + print(f" Has Video: {movie.get('has_video_file', False)}") + print(f" Last Updated: {movie.get('last_updated', 'None')}") + + # Check if released date is valid + released = movie.get('released') + if released and released.strip(): + try: + from datetime import datetime + test_date = f"{released}T00:00:00" + parsed = datetime.fromisoformat(test_date.replace('Z', '+00:00')) + print(f"\nāœ… Released date is valid: {parsed}") + except Exception as e: + print(f"\nāŒ Released date is INVALID: {e}") + else: + print(f"\nāš ļø Released date is empty or None") + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python debug_movie.py ") + sys.exit(1) + + imdb_id = sys.argv[1] + if not imdb_id.startswith('tt'): + imdb_id = f'tt{imdb_id}' + + debug_movie(imdb_id) \ No newline at end of file diff --git a/static/js/app.js b/static/js/app.js index 19ea468..2a9064f 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -643,6 +643,16 @@ async function applySmartFix(mediaType, options) { } } + // Debug logging + console.log('šŸ” SMART FIX DEBUG:', { + mediaType, + imdb_id: options.imdb_id, + selectedOption, + dateadded, + source, + originalDate: selectedOption.date + }); + try { if (mediaType === 'movie') { await updateMovieDate(options.imdb_id, dateadded, source);