#!/usr/bin/env python3 """ Test script to verify movie directory scanning logic Simulates what the manual scan would do with correct paths """ import os import sys from pathlib import Path def test_movie_scanning(): """Test movie directory scanning logic""" print("๐Ÿ” Testing Movie Directory Scanning") print("=" * 50) # Test paths - use the corrected paths from the code movie_paths = [ Path("/media/Movies/movies"), Path("/media/Movies/movies6") ] print("๐Ÿ“ Testing paths:") for path in movie_paths: print(f" {path}") # Import the NFO manager to test the IMDb parsing try: from core.nfo_manager import NFOManager nfo_manager = NFOManager() print("โœ… Successfully imported NFOManager") except Exception as e: print(f"โŒ Failed to import NFOManager: {e}") return False # Simulate the scanning logic total_movies_found = 0 for media_path in movie_paths: print(f"\n๐ŸŽฌ Scanning: {media_path}") # Check if path exists (this will fail on your local machine but show the logic) if not media_path.exists(): print(f" โš ๏ธ Path doesn't exist locally (expected on dev machine): {media_path}") print(f" โ„น๏ธ On production server, this path should contain directories like:") print(f" Example Movie [imdb-tt1234567] (2023)/") print(f" Another Movie [imdb-tt7654321] (2022)/") continue movie_count = 0 for item in media_path.iterdir(): if item.is_dir(): imdb_id = nfo_manager.parse_imdb_from_path(item) if imdb_id: movie_count += 1 print(f" โœ… Found movie: {item.name} -> {imdb_id}") else: print(f" โญ๏ธ Skipped (no IMDb ID): {item.name}") print(f" ๐Ÿ“Š Found {movie_count} movies with IMDb IDs in {media_path}") total_movies_found += movie_count print(f"\n๐ŸŽฏ Total movies that would be processed: {total_movies_found}") # Test IMDb ID parsing with sample directory names print(f"\n๐Ÿงช Testing IMDb ID Parsing Logic:") test_names = [ "The Dark Knight [imdb-tt0468569] (2008)", "Inception [imdb-tt1375666] (2010)", "Invalid Movie Name (2020)", "Movie Without IMDb (2021)", "Another Movie [imdb-tt1234567] (2023)" ] for test_name in test_names: test_path = Path(f"/fake/path/{test_name}") imdb_id = nfo_manager.parse_imdb_from_path(test_path) if imdb_id: print(f" โœ… '{test_name}' -> {imdb_id}") else: print(f" โŒ '{test_name}' -> No IMDb ID found") return True def show_manual_scan_instructions(): """Show instructions for testing on the production server""" print("\n" + "="*60) print("๐Ÿ“‹ NEXT STEPS - Test on Production Server") print("="*60) print() print("1. ๐Ÿ”ง Update your environment variables:") print(" export MOVIE_PATHS='/media/Movies/movies,/media/Movies/movies6'") print(" export TV_PATHS='/media/TV/tv,/media/TV/tv6'") print() print("2. ๐Ÿš€ Test the manual scan:") print(" curl -X POST 'http://localhost:8080/manual/scan?scan_type=movies'") print() print("3. ๐Ÿ“Š Check the logs for movie processing:") print(" docker logs | grep -E '(Processing movie|Completed movie scan)'") print() print("4. ๐Ÿงช Test the bulk update script:") print(" python3 test_bulk_update.py") print(" python3 bulk_update_movies.py") print() print("5. โœ… Verify end-to-end workflow:") print(" curl http://localhost:8080/debug/movie/tt1674782") print() if __name__ == "__main__": success = test_movie_scanning() if success: print("\nโœ… Local testing completed successfully!") show_manual_scan_instructions() else: print("\nโŒ Local testing failed!") sys.exit(1)