clipper.py is a small helper that lets you point yt-dlp at a YouTube video, search the subtitles for a specific line, and download a short clip around that subtitle.
It works by:
- Fetching automatic or creator-provided subtitles via
yt-dlp(JSON format). - Fuzzy matching your query against the transcript to find the best subtitle segment.
- Asking
yt-dlpto download only the portion of the video around that timestamp.
- Python 3.9+
yt-dlpinstalled as a Python package (pip install yt-dlp)ffmpegavailable on yourPATH(required byyt-dlpfor cutting clips)
Create a local environment and install dependencies:
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtOn Windows PowerShell:
py -3 -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txtpython clipper.py "<youtube-url>" "<query text>" --before 5 --after 10 --lang en --output myclip.mp4--before/--aftercontrol how many seconds to keep before/after the matching subtitle (defaults: 5s each).--langselects the subtitle language to search (default:en). The tool will try both manual and automatic subtitles.--outputsets the destination file. If omitted, a name is generated from the query.--formatlets you forward a customyt-dlpformat selector (for example:bestvideo+bestaudio/best).--verbosesurfaces the underlyingyt-dlpandffmpeglogs.--auto-transcribefalls back to a speech-to-text workflow when no subtitles are available.--stt-providerselects the speech-to-text provider plugin to use alongside--auto-transcribe.
Example:
python clipper.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" "never gonna give you up" --before 3 --after 7 --output rickroll.mp4The script uses yt-dlp's --download-sections "*start-end" support to grab just the requested time span when possible, and saves an .srt subtitle file alongside the clip so you can burn captions later if you prefer. If the line occurs multiple times, it picks the subtitle segment with the highest fuzzy match score, which usually corresponds to the closest textual match. When yt-dlp cannot download just the requested range, it falls back to fetching the full video and trims it locally with ffmpeg.
If no good match is found the script exits with a nonzero status. Try adjusting your query (shorter phrases often match better) or confirm that the video has subtitles in the selected language.
Prefer not to use the terminal? Launch the Tkinter-based helper to collect options, preview the exact command that will run, and stream clipper.py output in a scrollable panel:
python clipper_gui.pyFill in the video URL and query text (both required), adjust how many seconds before/after the quote you want, pick a subtitle language and quality preset from the dropdowns, optionally choose an output path, then click Run clipper. The GUI constructs the equivalent CLI command (with verbose logging enabled), runs it on your behalf, and surfaces progress and errors inline so non-technical users can follow along.
At launch the GUI offers to install or update yt-dlp via pip install --upgrade yt-dlp, since staying on the latest release is critical for bypassing YouTube site changes. Accepting the prompt is especially helpful for Windows users who might not update the dependency manually.
==EXPERIMENTAL, HERE BE DRAGONS!==
When yt-dlp cannot fetch subtitles, pass --auto-transcribe to download the audio track, send it through a speech-to-text (STT) provider, and continue matching locally. Providers are pluggable: define a subclass of STTProvider in stt_providers.py, decorate it with @register_provider, and select it at runtime via --stt-provider <name>. The repository currently ships with a stub provider that simply documents the interface; replace it with an implementation that uploads audio to your service of choice (for example, OpenAI Whisper API or Google Cloud Speech-to-Text) and returns timestamped segments.