add scanner metadata cache reuse and control flags
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
import csv
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, MagicMock
|
||||
@@ -17,6 +18,8 @@ from vlm.scanner import (
|
||||
categorize_file,
|
||||
scan_library,
|
||||
extract_metadata,
|
||||
save_inventory_csv,
|
||||
load_inventory_csv,
|
||||
)
|
||||
|
||||
|
||||
@@ -698,6 +701,63 @@ class TestExtractMetadata:
|
||||
assert vf.duration_seconds is None
|
||||
assert vf.bitrate_kbps is None
|
||||
|
||||
def test_scan_library_with_metadata_disabled(self, tmp_path):
|
||||
"""Test that metadata extraction can be disabled for faster scans."""
|
||||
movie_dir = tmp_path / "movie"
|
||||
movie_dir.mkdir()
|
||||
|
||||
video_file = movie_dir / "test.mp4"
|
||||
video_file.touch()
|
||||
|
||||
config = Config(library_root=tmp_path)
|
||||
|
||||
with patch('subprocess.run') as mock_run:
|
||||
result = scan_library(tmp_path, config, include_video_metadata=False)
|
||||
|
||||
assert len(result) == 1
|
||||
assert result[0].filename == "test.mp4"
|
||||
assert result[0].resolution is None
|
||||
assert result[0].codec is None
|
||||
assert result[0].duration_seconds is None
|
||||
assert result[0].bitrate_kbps is None
|
||||
mock_run.assert_not_called()
|
||||
|
||||
def test_scan_library_reuses_cached_metadata_when_unchanged(self, tmp_path):
|
||||
"""Test unchanged files reuse metadata from previous inventory cache."""
|
||||
movie_dir = tmp_path / "movie"
|
||||
movie_dir.mkdir()
|
||||
video_file = movie_dir / "test.mp4"
|
||||
video_file.write_text("test")
|
||||
|
||||
original = VideoFile(
|
||||
path=video_file,
|
||||
filename=video_file.name,
|
||||
size_bytes=video_file.stat().st_size,
|
||||
modified_timestamp=datetime.fromtimestamp(video_file.stat().st_mtime, tz=timezone.utc),
|
||||
category="movie",
|
||||
resolution="1920x1080",
|
||||
codec="h264",
|
||||
duration_seconds=120.5,
|
||||
bitrate_kbps=5000,
|
||||
)
|
||||
|
||||
cache_file = tmp_path / "cached_inventory.csv"
|
||||
save_inventory_csv([original], cache_file, tmp_path)
|
||||
cached_entries = load_inventory_csv(cache_file)
|
||||
metadata_cache = {str(vf.path): vf for vf in cached_entries}
|
||||
|
||||
config = Config(library_root=tmp_path)
|
||||
with patch("subprocess.run") as mock_run:
|
||||
result = scan_library(tmp_path, config, metadata_cache=metadata_cache)
|
||||
|
||||
assert len(result) == 1
|
||||
scanned = result[0]
|
||||
assert scanned.resolution == "1920x1080"
|
||||
assert scanned.codec == "h264"
|
||||
assert scanned.duration_seconds == 120.5
|
||||
assert scanned.bitrate_kbps == 5000
|
||||
mock_run.assert_not_called()
|
||||
|
||||
|
||||
|
||||
class TestInventoryReports:
|
||||
|
||||
Reference in New Issue
Block a user