mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 22:27:01 +01:00
New package. Walks every thread on 4chan's /wsg/, downloads each video it has
not seen, and reviews them one at a time: mpv embedded in a Tk window via --wid
with Keep/Pass/Undo directly beneath the picture.
Dedupe is structural rather than a convention. Every post carrying a file also
carries md5 -- base64 MD5 of the whole file -- so it is the sqlite primary key.
An already-seen video costs zero bytes to skip and a byte-identical repost in
another thread collapses onto the existing row. Verified against a live file:
the API's Nz9OEKdMuMZEdYE6eLTKmA== matched base64(md5(bytes)) exactly.
Undo is unbounded and survives quitting: the verdict trail lives in the index,
not in memory, so yesterday's decisions can still be taken back.
No downloaded video is ever deleted. A pass moves the file to trash/ and leaves
it there; files.apply_move refuses to overwrite an existing destination, so the
guarantee holds by construction rather than per caller.
Three bugs only running it could find, each caught from evidence rather than
guesswork:
- the video stayed black: a <Configure> handler set mpv's geometry, fighting
the automatic sizing --wid already does
- playback never advanced: refresh() ran every tick and re-sent loadfile ~7x
a second, restarting the video continuously
- it froze on one video around the 26th while filenames kept advancing: mpv
pushes an event stream down the same socket and nothing drained it, so the
buffer filled and mpv stopped reading commands. Isolated to command #35
without a drain thread; all 60 honoured with one.
A five-lens review then found nine more, all reproduced before fixing: a failed
mpv start stranded the non-daemon worker forever; undo could clobber a file in
incoming/; a NUL-bearing md5 poisoned the index permanently; an oversized int
killed the worker with no event; gzip bombs on both hosts were accepted; the
board endpoints were fetched unconditionally forever; and Session.missing could
corrupt the undo trail.
mpv runs as a subprocess over its JSON IPC socket rather than via python-mpv,
which resolves libmpv at import time and would fail on CI while passing here.
Third-party surface is requests alone, already declared.
277 package tests, 100% branch coverage on all 22 modules, no suppressions.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
86 lines
2.2 KiB
Python
86 lines
2.2 KiB
Python
"""Storage locations, resolved lazily.
|
|
|
|
Every path is a *function*. A module-level ``Path.home() / ...`` constant is
|
|
evaluated at import time, which makes it impossible for a test to redirect --
|
|
``brother_printer.consumables`` learned that the hard way. Resolving on each
|
|
call keeps the whole package redirectable from one fixture.
|
|
|
|
Nothing in this module deletes anything; ``trash_dir`` is a destination, not a
|
|
bin that gets emptied.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from python_pkg.wsg_grabber.constants import BOARD
|
|
|
|
_APP_DIRNAME = "wsg_grabber"
|
|
|
|
|
|
def data_dir() -> Path:
|
|
"""Return the root directory holding the index and every downloaded file.
|
|
|
|
Honours ``XDG_DATA_HOME`` when set, else ``~/.local/share``.
|
|
|
|
Returns:
|
|
Path: ``<data home>/wsg_grabber`` (not guaranteed to exist).
|
|
"""
|
|
override = os.environ.get("XDG_DATA_HOME")
|
|
base = Path(override) if override else Path.home() / ".local" / "share"
|
|
return base / _APP_DIRNAME
|
|
|
|
|
|
def db_path() -> Path:
|
|
"""Return the sqlite index file.
|
|
|
|
Returns:
|
|
Path: ``<data dir>/index.db``.
|
|
"""
|
|
return data_dir() / "index.db"
|
|
|
|
|
|
def incoming_dir() -> Path:
|
|
"""Return the directory holding downloaded, not-yet-reviewed videos.
|
|
|
|
Returns:
|
|
Path: ``<data dir>/incoming``.
|
|
"""
|
|
return data_dir() / "incoming"
|
|
|
|
|
|
def keep_dir() -> Path:
|
|
"""Return the directory videos are moved to when kept.
|
|
|
|
Returns:
|
|
Path: ``<data dir>/keep``.
|
|
"""
|
|
return data_dir() / "keep"
|
|
|
|
|
|
def trash_dir() -> Path:
|
|
"""Return the directory videos are moved to when passed.
|
|
|
|
Nothing ever removes files from here; clearing it is the user's call.
|
|
|
|
Returns:
|
|
Path: ``<data dir>/trash``.
|
|
"""
|
|
return data_dir() / "trash"
|
|
|
|
|
|
def ipc_socket_path() -> Path:
|
|
"""Return the unix socket used to drive the embedded mpv process.
|
|
|
|
Returns:
|
|
Path: ``<data dir>/mpv-<board>.sock``.
|
|
"""
|
|
return data_dir() / f"mpv-{BOARD}.sock"
|
|
|
|
|
|
def ensure_dirs() -> None:
|
|
"""Create the data, incoming, keep and trash directories if absent."""
|
|
for directory in (data_dir(), incoming_dir(), keep_dir(), trash_dir()):
|
|
directory.mkdir(parents=True, exist_ok=True)
|