116 lines
4.0 KiB
Python
116 lines
4.0 KiB
Python
#!/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 <container_name> | 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) |