Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(media): 显示尺寸重探沿用系统盘余量闸门

longmeidao4e3188133420
diff --git a/src/peach/display_dimensions_repair.py b/src/peach/display_dimensions_repair.py
index 3aae79a25..577340c39 100644
--- a/src/peach/display_dimensions_repair.py
+++ b/src/peach/display_dimensions_repair.py
@@ -17,6 +17,7 @@ def collect(connection) -> dict:
def reprobe(contract, config, asset_id: int, *, baseline=None) -> dict:
from .library_processing import _ffprobe_path
+ from .jobs import DiskGuard
with contract.database.read_connection() as connection:
row = connection.execute("SELECT * FROM asset WHERE id=? AND medium='video' AND disposal IS NULL",
(asset_id,)).fetchone()
@@ -27,7 +28,10 @@ def reprobe(contract, config, asset_id: int, *, baseline=None) -> dict:
ffprobe = _ffprobe_path(config)
if not ffprobe:
raise ValueError('显示尺寸重探未取得 ffprobe')
+ guard = DiskGuard(config.data_root, 1)
+ guard.check(force=True)
measured = media_probe.measure(ffprobe, asset_id, row['path'])
+ guard.check(force=True)
if measured[0] <= 0 or measured[1] <= 0 or measured[2] <= 0:
raise ValueError('显示尺寸未取得,保留原有测量')
with contract.database.write_transaction() as connection:
diff --git a/tests/test_upgrade_repairs.py b/tests/test_upgrade_repairs.py
index c71713d4c..1ce825170 100644
--- a/tests/test_upgrade_repairs.py
+++ b/tests/test_upgrade_repairs.py
@@ -99,6 +99,21 @@ class UpgradeRepairTests(unittest.TestCase):
self.assertEqual(tuple(connection.execute('SELECT duration,width,height,ctx_orient FROM asset').fetchone()),
(60, 720, 1280, '竖屏'))
+ def test_display_reprobe_checks_system_disk_before_reading_and_before_replacing_measurements(self):
+ from peach import media_probe
+ from peach.jobs import DiskSpaceDenied
+ self.display_sample()
+ for free_space, reads in (([0], 0), ([100, 0], 1)):
+ with self.subTest(free_space=free_space), \
+ patch('peach.library_processing._ffprobe_path', return_value='ffprobe'), \
+ patch('peach.jobs.DiskGuard.free_gb', side_effect=free_space), \
+ patch.object(media_probe, 'probe_file', return_value=(60, 2276, 1280, 'h264', 25, None)) as probe, \
+ self.assertRaises(DiskSpaceDenied):
+ upgrade_repairs._media_run(self.contract, 'upgrade-library:display-dimensions-1:1', Mock())
+ self.assertEqual(probe.call_count, reads)
+ with self.database.read_connection() as connection:
+ self.assertEqual(tuple(connection.execute('SELECT width,height FROM asset').fetchone()), (720, 1280))
+
def test_unchanged_display_geometry_does_not_rebuild_previews(self):
from peach import media_probe
self.display_sample(width=1920, height=1080)