From cd7b8a3cca490b3be48c0787449893fa55492b7b Mon Sep 17 00:00:00 2001 From: pax Date: Wed, 8 Apr 2026 13:46:27 -0500 Subject: [PATCH] Move VIDEO_EXTENSIONS + _is_video from preview.py to media/constants.py (no behavior change) Step 1 of the gui/app.py + gui/preview.py structural refactor. Pure move: the constant and predicate are now in their own module, and preview.py grows a re-export shim at the bottom so existing imports (app.py:1351 and the in-file class methods) keep working unchanged. Shim is removed in commit 14 once importers update to the canonical path. See docs/REFACTOR_PLAN.md for the full migration order. --- booru_viewer/gui/media/__init__.py | 0 booru_viewer/gui/media/constants.py | 11 +++++++++++ booru_viewer/gui/preview.py | 10 ++++------ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 booru_viewer/gui/media/__init__.py create mode 100644 booru_viewer/gui/media/constants.py diff --git a/booru_viewer/gui/media/__init__.py b/booru_viewer/gui/media/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/booru_viewer/gui/media/constants.py b/booru_viewer/gui/media/constants.py new file mode 100644 index 0000000..8a2d876 --- /dev/null +++ b/booru_viewer/gui/media/constants.py @@ -0,0 +1,11 @@ +"""Shared constants and predicates for media files.""" + +from __future__ import annotations + +from pathlib import Path + +VIDEO_EXTENSIONS = (".mp4", ".webm", ".mkv", ".avi", ".mov") + + +def _is_video(path: str) -> bool: + return Path(path).suffix.lower() in VIDEO_EXTENSIONS diff --git a/booru_viewer/gui/preview.py b/booru_viewer/gui/preview.py index c3b0f4a..9eb9eb4 100644 --- a/booru_viewer/gui/preview.py +++ b/booru_viewer/gui/preview.py @@ -17,8 +17,6 @@ import mpv as mpvlib _log = logging.getLogger("booru") -VIDEO_EXTENSIONS = (".mp4", ".webm", ".mkv", ".avi", ".mov") - class Viewport(NamedTuple): """Where and how large the user wants popout content to appear. @@ -51,10 +49,6 @@ class Viewport(NamedTuple): _DRIFT_TOLERANCE = 2 -def _is_video(path: str) -> bool: - return Path(path).suffix.lower() in VIDEO_EXTENSIONS - - ## Overlay styling for the popout's translucent toolbar / controls bar ## now lives in the bundled themes (themes/*.qss). The widgets get their ## object names set in code (FullscreenPreview / VideoPlayer) so theme QSS @@ -2271,3 +2265,7 @@ class ImagePreview(QWidget): def resizeEvent(self, event) -> None: super().resizeEvent(event) + + +# -- Refactor compatibility shims (deleted in commit 14) -- +from .media.constants import VIDEO_EXTENSIONS, _is_video # re-export for refactor compat