phase 1 rework
This commit is contained in:
1 parent
211bfd174d
commit
20054198f3
38 files changed
+5001
-1019
No files matched your search
@@ -1,32 +1,118 @@
|
||||
# Proxer-Downloader
|
||||
|
||||
Proxer (Token) -> Proxer-Downloader Web (Parameter) -> Python Script (Execution)
|
||||
Express/EJS submission and status pages, a MongoDB episode queue, Node workers managed by PM2, and Python download entrypoints.
|
||||
|
||||
### Available Parameters
|
||||
scripts/proxer-dl-series.py:
|
||||
-i id [Number] [Required]
|
||||
-n name [String] (Default: id_episode_language) [Optional (uncertain about that)]
|
||||
-e episode range (delimiter "-") [String] [Required]
|
||||
-l language [String] ["engsub", "engdub", "gersub", "gerdub"]
|
||||
-t token [String] [Required]
|
||||
-o output dir [String] (Default: /mnt/media/WIP/)
|
||||
## Phase 1: reliable execution and a protected streaming boundary
|
||||
|
||||
scripts/proxer-dl-video.py:
|
||||
-u url [String] [Required]
|
||||
-f filename [String] (Default: id_episode_language) [Optional (uncertain about that)]
|
||||
-t token [String] [Required]
|
||||
-o output dir [String] (Default: /mnt/media/WIP/)
|
||||
The Phase 1 changes preserve the original files in `scripts/lib/`, the streaming call sequence, existing CLI entrypoint names, and the established filename conventions. The top bar redesign, full modular execution architecture, expiring job ownership, automatic retries, and enforced bandwidth controls are later phases. See [the rollout roadmap](docs/rollout-roadmap.md).
|
||||
|
||||
The current worker records success only when Python exits with code 0, emits exactly one valid completed result, and produces a nonempty regular output file. This is a completion contract, not full media-integrity verification. The protected stream library still writes directly to the target file and cannot resume a partial transfer.
|
||||
|
||||
### Behaviour
|
||||
## Runtime and configuration
|
||||
|
||||
- builds urls from parameters or vice versa, e.g.: https://proxer.me/watch/<id>/<episode>/<language>
|
||||
- save urls in a queue mongodb at 192.168.20.21:27023
|
||||
- should support multi-downloading up to 4 simultaenously using the queue db=downloads, collection=queue
|
||||
- remove after downloaded and add success message, and download params to collection=done
|
||||
- the token is always appened to a existing prefix
|
||||
- use dotenv to store sensitive information, like mongodb connection string, and the token prefix
|
||||
- Interface is a WebApp using express.js and ejs views in a dark/grey with red accent colors
|
||||
- bootstrap flip/toggle switch at the top to toggle between Video and Series
|
||||
- parameters manually appear depending on the mode
|
||||
- at any error from the python script, it should prompt the website saying 'Token expired or Captcha required' with a confirm button to refresh and try again
|
||||
- Node.js **20.19.0 or later**, matching the locked MongoDB driver's minimum requirement.
|
||||
- A Python environment with the existing dependencies in `scripts/requirements.txt`. Keep the working stream dependency versions for this rollout; validate them against the target interpreter before deployment.
|
||||
- MongoDB accessible to the application and workers.
|
||||
- PM2 on the download account's `PATH` when using the worker-management page.
|
||||
- An existing writable output directory, normally `/mnt/media/WIP`, accessible to the download account through its `plex` group or the existing ACL.
|
||||
|
||||
The application can live under `/home/<download_user>/Proxer-Downloader/` or another chosen checkout path. Worker script paths are resolved from the checkout; there is no account name embedded in the browser or server code.
|
||||
|
||||
Install the locked Node dependencies, copy `.env.example` to `.env`, and replace the example settings with the working deployment values. Do not overwrite an existing production `.env` with the example.
|
||||
|
||||
```sh
|
||||
npm ci --ignore-scripts
|
||||
```
|
||||
|
||||
| Variable | Meaning | Default |
|
||||
|---|---|---|
|
||||
| `MONGO_URI` | Private connection string | Required when connecting |
|
||||
| `MONGO_DB` | Database used by both web and workers | `downloads` |
|
||||
| `OUTPUT_DIR` | Existing media output directory | `/mnt/media/WIP` |
|
||||
| `VENV_PYTHON` | Python executable; use the absolute virtual-environment path in production | `python3` |
|
||||
| `TOKEN_PREFIX` | Existing cookie name followed by `=` | Required for submission |
|
||||
| `MAX_SERIES_EPISODES` | Maximum episodes in one submission, from 1 to 10000 | `500` |
|
||||
| `HOST` | Web listener address; the example uses loopback for a reverse proxy | `0.0.0.0` |
|
||||
| `PORT` | Web listener port | `3000` |
|
||||
|
||||
Configuration is loaded from the checkout's `.env`, independently of the caller's working directory. The web form accepts the cookie **value**; the server prepends `TOKEN_PREFIX`. The example cookie name is a placeholder: retain the name from the working configuration. No live token belongs in source control.
|
||||
|
||||
Run PM2 and the application as the download account. Group access to media is separate from administrative network privileges. Preserve the deployment's existing reverse-proxy/firewall access boundary; this phase does not add application login or multi-user authorization. See [Debian 13 deployment and bandwidth assessment](docs/debian-13-deployment.md).
|
||||
|
||||
## Verification
|
||||
|
||||
```sh
|
||||
npm run check:protected
|
||||
npm test
|
||||
```
|
||||
|
||||
The test runner checks the entire protected directory before and after all suites. It uses a temporary workspace and removes it afterward. Node tests use fake databases/processes and local fixtures; subprocess integration tests use copied CLI files with a synthetic stream module. Python tests use the standard library and disable bytecode generation. No test connects to production MongoDB or downloads media.
|
||||
|
||||
Set `TEST_PYTHON` to an absolute interpreter path when the test interpreter should differ from `python3`. The protected check covers all seven original files, their executable flags, exact directory entries, additions, deletions, and symlinks. The frozen baseline must not be regenerated to hide an unexpected change.
|
||||
|
||||
The current Phase 1 run, including the unresolved-link pause fix, passed **158 tests** (114 Node and 44 Python). See the [verification report](docs/phase-1-verification.md) for coverage, runtime versions, and the remaining deployment checks.
|
||||
|
||||
## Start locally
|
||||
|
||||
After configuring the database, interpreter, and output directory, start the web application and a worker in separate terminals or under the existing supervisor:
|
||||
|
||||
```sh
|
||||
npm start
|
||||
```
|
||||
|
||||
```sh
|
||||
npm run worker
|
||||
```
|
||||
|
||||
The worker-management page creates workers using the configured checkout and current Node interpreter. It only lists and controls PM2 processes whose executable is this checkout's `queue_worker.js`; unrelated services are excluded. PM2 IDs are resolved on the server. Saving the host-wide PM2 process list is a deployment operation (`pm2 save` as the download account), so the web control is removed.
|
||||
|
||||
## Submission and filenames
|
||||
|
||||
Only HTTPS Proxer watch URLs on `proxer.me` or `www.proxer.me` are accepted. The URL must identify a positive integer series ID, positive integer episode, and one of `engsub`, `engdub`, `gersub`, or `gerdub`. Fragments and an optional trailing slash are normalized away. Query parameters, credentials in URLs, and custom ports are rejected.
|
||||
|
||||
| Source | Filename before `.mp4` |
|
||||
|---|---|
|
||||
| Web video with title | Explicit legacy `filename`, then the form's `name` |
|
||||
| Web video without title | `{id} E{episode} {language}` |
|
||||
| Web series | `{trimmedNameOrId}E{paddedEpisode}_{language}` |
|
||||
| Standalone series CLI | `{name}_Episode_{episode}_{language}` |
|
||||
|
||||
Web series padding uses the width of the highest requested episode. All destinations are validated before a batch is queued. Filenames must be single names inside the configured directory; symlink and non-file targets are rejected. The corrected video-title fallback is intentional. [Compatibility fixtures](tests/fixtures/legacy-contracts.json) record the original conventions.
|
||||
|
||||
## Python CLI compatibility
|
||||
|
||||
Both original entrypoints remain available:
|
||||
|
||||
```sh
|
||||
python3 -B scripts/proxer-dl-video.py --help
|
||||
python3 -B scripts/proxer-dl-series.py --help
|
||||
```
|
||||
|
||||
Video arguments: `-u/--url`, `-f/--filename`, `-o/--output`, and either `-t/--token` or `--token-stdin`.
|
||||
|
||||
Series arguments: `-i/--id`, `-n/--name`, `-e/--episodes` (inclusive `start-end`), `-l/--language`, `-o/--output`, and either token option.
|
||||
|
||||
`--token-stdin` accepts one complete `cookie_name=value` followed by an optional newline and EOF. It preserves `=` inside the value and limits the complete cookie to 8192 UTF-8 bytes. Workers use this interface so credentials do not appear in process arguments. Legacy `-t` remains for compatibility. For a filename beginning with a dash, use `--filename=-Example` so the parser treats it as a value.
|
||||
|
||||
Each download invocation emits a final `PROXER_RESULT` JSON record outside the library's progress output. Exit codes are 0 for completion, 1 for runtime failure, and 2 for invalid input. A series invocation returns a failure exit code when any episode fails and includes counts for completed, failed, and unattempted episodes. Help output remains normal CLI help.
|
||||
|
||||
Both scripts disable bytecode writing before imports, and workers additionally launch Python with `-B` and `PYTHONDONTWRITEBYTECODE=1`.
|
||||
|
||||
## Failure and shutdown behavior
|
||||
|
||||
- Ordinary source/network/validation failures are recorded in failed history with the original job ID, source URL, filename, category, and a bounded sanitized log. They do not pause unrelated jobs. Automatic retries are deferred to the explicit attempt model.
|
||||
- A missing embed or MP4 marker now produces a `resolution` result and pauses new downloads at the first failure. The full job stays queued for a deliberate retry, while its failed attempt remains visible in history. The banner describes possible CAPTCHA/login verification, an unavailable video, or a changed source page; it does not claim CAPTCHA is confirmed. Verified HTTP 404 remains an ordinary source failure.
|
||||
- Verified HTTP 401/403 access rejection also pauses the pool and retains the job. The pause is persisted before attempt history and claim release. Workers recheck it after claiming and immediately before launching Python; transfers already admitted may finish. The global action resumes after external verification; it does not solve CAPTCHA or refresh an expired token stored in a queued job.
|
||||
- Missing interpreter/dependencies and systemic output-storage failures retain the queued request and halt the worker. They do not consume the remaining queue or set a CAPTCHA block.
|
||||
- On a handled stop, a started child must terminate before its job is made eligible again. A stop during pre-launch validation prevents the child from starting. Resuming an interrupted transfer restarts it from the beginning.
|
||||
- History persistence must succeed before the queue record is removed. A database error leaves the processing claim held and stops the worker.
|
||||
|
||||
The blanket `clear-processing` operation is disabled and returns HTTP 409. Phase 1 still uses legacy claims: forced kills, host loss, database failure, or multi-step history persistence can require manual reconciliation. Expiring ownership, automatic recovery, atomic job state, collision policy, staged output publication, and safe drain controls are later rollout phases. Never clear a claim while its Python process might still be writing.
|
||||
|
||||
## Documentation
|
||||
|
||||
- [Phase 1 baseline and compatibility boundary](docs/phase-1-baseline.md)
|
||||
- [Phase 1 verification report](docs/phase-1-verification.md)
|
||||
- [Unresolved-link pause fix and recovery](docs/phase-1-resolution-fix.md)
|
||||
- [Debian 13 deployment and bandwidth assessment](docs/debian-13-deployment.md)
|
||||
- [Rollout roadmap](docs/rollout-roadmap.md)
|
||||
Reference in new issue
Block a user