Add a CLI (and agent tool contract) sharing the web app's engine - #60
Open
moamen1358 wants to merge 3 commits into
Open
Add a CLI (and agent tool contract) sharing the web app's engine#60moamen1358 wants to merge 3 commits into
moamen1358 wants to merge 3 commits into
Conversation
added 3 commits
July 10, 2026 17:04
Move probe/playlist/download/subtitle logic out of the Flask handlers into core.py - pure functions, no Flask, no threads, every expected failure normalized to a single ReclipError. app.py keeps the exact same routes, JSON shapes, and jobs/polling model, now delegating to core. Adds unit tests for the engine and the routes.
New 'reclip' console command sharing the same core engine as the web app: download (MP4/MP3, --quality, --timeout, bulk with per-URL results), info, playlist, and transcript (subtitles as text). Human readable by default, --json for machine output, exit 0/1 contract. Packaged via pyproject.toml (pipx-installable, runs its bundled yt-dlp via python -m yt_dlp so no PATH dependency); deps stay flask + yt-dlp. Docker comments updated to match the module-invocation behavior.
skill/SKILL.md documents the CLI as a tool contract for AI agents (commands, JSON output shapes, exit codes); README gains a CLI section.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
A command-line interface for ReClip that shares the exact engine behind the web UI - so scripts, cron jobs, and AI agents can use ReClip, not just a person in a browser:
Human-readable output by default,
--jsonfor machine consumption, exit 0/1 contract, per-URL results for bulk downloads,--timeoutoverride.How it's structured (3 commits)
core.py- all yt-dlp logic extracted from the Flask handlers into one dependency-free module (probe,expand_playlist,download,transcript). Every expected failure (bad URL, timeout, unreadable yt-dlp output, unwritable directory, missing binary) is normalized to a singleReclipError.app.pykeeps its exact routes, JSON shapes, and jobs/polling model - it just delegates now. The web UI behavior is unchanged.cli.py+pyproject.toml- thereclipcommand (console scriptcli:main). Runs its bundled yt-dlp viapython -m yt_dlp, so a pipx install is fully self-contained. Runtime deps stay exactlyflask+yt-dlp.skill/SKILL.md+ README - a machine-readable tool contract (commands, output shapes, exit codes) that AI agents can consume, plus a README CLI section.Hardening included along the way
The extraction fixed several latent issues that apply to the web app too: glob-metacharacter output paths no longer break file discovery; filename collisions get an atomic
(n)suffix instead of silently overwriting; format entries withoutformat_idor withnullformats/entriesno longer crash; URLs are passed after--so a crafted "URL" can't be parsed as a yt-dlp option (same concern as PR #58); multi-video JSON output parses correctly (extends the fix in 1d161d1).Verification
--name) found no crashes, no tracebacks, no data loss.Deliberate scope limits
core.py,cli.pybesideapp.py) to keep this diff reviewable; documented as pipx-only install.transcriptis subtitles-only (no Whisper) to avoid new dependencies.jobsdict etc.) - kept out of scope on purpose.Disclosure
This was built with AI assistance (Claude Code driving the implementation through an automated review/test pipeline, with every change human-reviewed and live-tested). Happy to adjust anything - naming, layout, scope - to fit the project's direction.
🤖 Generated with Claude Code