yt-to-post
Turns a YouTube video into a WordPress draft: captions through the official Data API with your OAuth, or a transcript you supply, then a structured article with the video embedded and the source credited. Handles chapters, long videos by chunking, no-caption videos, and non-English speech.
Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/indianopinion/yt-to-post/archive/refs/heads/main.zipTurns one YouTube video into one WordPress draft: the words come from captions downloaded through the official YouTube Data API with your own OAuth, or from a transcript you supply, and a language model writes a structured article with the video embedded and the source credited. An editor reads, fixes and publishes it; the plugin never publishes.
Written from scratch; not derived from any third-party plugin.
This project came out of the work on indianopinion.org and is written from scratch; it is independent of and not affiliated with any third-party plugin it integrates with.
Measured in the test suite (mock model, four seconds a call): a 60-minute captioned talk becomes a draft in 4 model calls and 16 seconds of simulated wall time, inside one 25-second runner tick, with every quote in the draft found word for word in the transcript; a 5 MiB transcript parses, cleans and chunks at a peak of about 21 MiB.
Contents
- Install
- Quick start
- Configuration
- How it works
- Hooks, REST and WP-CLI
- YouTube API policy and your data
- Limitations
- FAQ
- Licence
Install
WordPress 6.4 or later, PHP 8.1 or later, with json, mbstring, dom/libxml and sodium (or WordPress's polyfill). intl and zlib are used when present.
With Composer (in a Composer-managed site):
composer config repositories.llm-json-php vcs https://github.com/IndianOpinion/llm-json-php
composer config repositories.yt-to-post vcs https://github.com/IndianOpinion/yt-to-post
composer require indianopinion/yt-to-post
Without a Composer-managed site: put the plugin in wp-content/plugins/yt-to-post/, run composer install --no-dev inside that folder, and activate it. autoload.php loads vendor/ when it is there. llm-json-php is a Composer vcs dependency and is never bundled with this plugin. If you cannot run Composer, the plugin still loads: plug in your own model caller with the yt_to_post_model_caller filter (see examples/custom-model-caller.php), or load llm-json-php yourself before this plugin.
As a must-use plugin: copy the folder to wp-content/mu-plugins/yt-to-post/ and examples/mu-plugin-loader.php to wp-content/mu-plugins/yt-to-post-loader.php. Must-use plugins never run activation hooks, so the jobs table is created on the first admin page load.
Quick start
-
In your own Google Cloud project, enable the YouTube Data API v3 and create an OAuth client of type "Web application". Register the redirect URI shown on Settings > YouTube to draft (it is
wp-admin/admin-post.php?action=yt_to_post_oauthon your site). -
Put the client in
wp-config.php(preferred) or the settings screen:define('YT_TO_POST_CLIENT_ID', '...apps.googleusercontent.com'); define('YT_TO_POST_CLIENT_SECRET', '...'); define('YT_TO_POST_LLM_API_KEY', '...'); -
On the settings screen, set the model provider and a model chain, then Connect a YouTube account. Use the channel whose videos you will write about.
-
Go to Tools > Video to draft, paste a link, and press Create draft. For a video from another channel, tick "I have the rights to use this video". For a video you cannot download captions for, paste or upload a transcript.
-
When the job is done, the draft is in Posts > Drafts with a notes box showing what it was built from.
Without a Google project at all, supply a transcript: the title and channel for the credit then come from YouTube's public oEmbed endpoint.
With WP-Cron disabled, run the queue from a real cron:
* * * * * cd /var/www/site && wp yt-to-post run --time=50 --quiet
Configuration
Every setting is on Settings > YouTube to draft, validated on save. Constants win over options and show read-only on the screen.
| Setting | Default | Notes |
|---|---|---|
enabled |
on | Kill switch. YT_TO_POST_DISABLED true forces it off. |
client_id, client_secret |
none | OAuth client. Constants YT_TO_POST_CLIENT_ID, YT_TO_POST_CLIENT_SECRET. |
api_key |
none | Metadata only (videos.list), never captions. YT_TO_POST_API_KEY. |
model_kind |
openrouter |
openrouter, openai or generic (OpenAI-compatible). |
model_ids |
none | Comma-separated chain, tried in order. Nothing runs until set. |
model_base_url |
none | https, for generic or a custom endpoint. |
llm_api_key |
none | YT_TO_POST_LLM_API_KEY. |
model_token_cap, model_temperature |
4096, 0.3 | |
default_status |
draft |
draft or pending only. |
default_author |
none | Needed for WP-CLI jobs without --user. |
default_category, default_tags |
none | |
article_language |
site |
source, site or a BCP-47 tag. |
site_country |
from the locale | For region warnings. |
keep_annotations |
off | Keep [Music], (applause) and similar. |
topics_as_tags |
off | Otherwise suggested topics go in the draft notes. |
allow_private_own |
off | Allow your own channel's private videos. |
privacy_embed |
off | Use the youtube-nocookie.com player instead of the WordPress embed. |
allow_playlists |
off | A playlist link makes one job per video. |
max_playlist_items |
25 | 1 to 50. |
max_videos_per_day |
10 | 0 to 500, site day. YT_TO_POST_DAILY_VIDEOS overrides. 0 means no new work. |
max_model_calls_per_day |
200 | 0 to 5,000, retries included. |
youtube_quota_budget |
9,000 | Units per Pacific day (the default project quota is 10,000). |
max_duration_minutes |
240 | Longer videos need the override tick. |
max_chunks |
30 | More need the override tick. |
single_pass_tokens, chunk_tokens |
12,000, 8,000 | Estimated tokens. |
min_words |
150 | Shorter transcripts are refused. |
max_transcript_bytes |
5 MiB | |
max_job_attempts |
3 | |
tick_seconds |
25 | WP-Cron runner time per tick. |
retention_days |
30 | 1 to 90. Transcript and notes in finished jobs; rows go after twice this. |
api_data_days |
30 | 1 to 30. Stored YouTube API data (video details). |
api_data_on_expiry |
purge |
purge or refresh (one videos.list call each). |
draft_transcript_days |
0 | Removes the transcript kept on drafts after this many days; 0 keeps it. |
Other constants: YT_TO_POST_DISABLE_CRON_RUNNER (WP-Cron does housekeeping only; run jobs with WP-CLI).
How it works
- Input. The link is parsed without any network call; only exact YouTube hosts are accepted and the 11-character id is the identity. A draft or running job for the same id is returned instead of a new one unless you force it.
- Metadata.
videos.list(1 unit) with your token or API key. Live, upcoming, processing and other people's private videos are refused; unlisted needs a tick; age, kids and region limits become warnings. Videos from another channel wait for the rights tick. - Captions.
captions.list(50 units) andcaptions.download(200 units) as WebVTT, then SRT, then the original. A 403 (not the owner) or no usable track puts the job in "needs transcript", without spending the download. - Normalise. The format is detected from the content; encodings are checked; TTML is read without entities, network or a DOCTYPE. Tags, annotations and rolling-caption repeats are cleaned.
- Write. Short transcripts take one model call. Long ones are split into chunks (on chapter starts when there are chapters), each chunk is turned into notes and saved at once, and a reduce call writes the article from the notes. Source text only ever goes in the user message, fenced as untrusted data.
- Check. The output must fit the schema. Every quote must appear word for word in the transcript and takes its time from the cue where it begins; others are dropped and counted. The article language is checked by the letters, with one retry.
- Draft. Block markup: embed, standfirst, sections with "Watch from" links, key points, quotes, credit.
wp_insert_postwith status forced to draft or pending after every filter.
Before every paid call the kill switch, the daily caps, the yt_to_post_can_run filter and (when present) spend-meter are read fresh. A held job resumes on its own when the reason clears.
spend-meter (when SPEND_METER_API is 1): before each model call the plugin applies spend_meter_pre_spend with an intent (purpose yt_to_post, caller yt-to-post, provider, model, est_input_tokens). A null answer means no meter is listening and the plugin's own caps decide; otherwise the call goes ahead only when allowed is exactly true. Every attempted call is then reported once with spend_meter_record (status ok, error_billed or error_unbilled, tokens, and the provider's cost in nanos when reported), and a reservation for a call that did not happen is given back with spend_meter_release.
gen-queue (when GEN_QUEUE_VERSION is defined): the plugin registers the job type yt_to_post.article on gen_queue_register_types and enqueues each job through the gen_queue_enqueue_job filter, with the video id and force counter as the idempotency key (plus a resume counter after a retry, a supplied transcript or a rights confirmation). If the filter returns no job id, the plugin's own WP-Cron runner takes the job. Each gen-queue run works on its job for the queue's time, reports the model cost to the job context (as already metered when spend-meter is present), and leaves any remaining steps to the plugin's own runner.
Hooks, REST and WP-CLI
Functions: yt_to_post_create(), yt_to_post_get_job(), yt_to_post_find_by_video(), yt_to_post_supply_transcript(), yt_to_post_confirm_rights(), yt_to_post_cancel(), yt_to_post_retry(), yt_to_post_run(), yt_to_post_parse_video_id(), yt_to_post_is_enabled(). YT_TO_POST_VERSION and the yt_to_post_loaded action tell you it is there.
Actions: yt_to_post_job_created, yt_to_post_job_state, yt_to_post_needs_transcript, yt_to_post_draft_created, yt_to_post_job_failed, yt_to_post_connection_changed.
Filters: yt_to_post_select_track, yt_to_post_estimate_tokens, yt_to_post_bytes_per_token (per-model ratio), yt_to_post_chunk_tokens, yt_to_post_system_prompt, yt_to_post_article_schema, yt_to_post_article, yt_to_post_content, yt_to_post_credit_html, yt_to_post_post_args, yt_to_post_daily_caps (lower only), yt_to_post_can_run, yt_to_post_capability_create, yt_to_post_capability_settings, yt_to_post_retention_days, yt_to_post_model_caller (plug in your own model, see examples/custom-model-caller.php), yt_to_post_model_routes.
REST (yt-to-post/v1, logged in, create capability, REST nonce): POST /jobs, GET /jobs/<id>, POST /jobs/<id>/transcript, POST /jobs/<id>/retry, POST /jobs/<id>/cancel, POST /estimate.
WP-CLI: wp yt-to-post create|run|list|show|transcript|retry|cancel|status|enable|disable|estimate|parse|purge. Exit codes: 0 success, 1 error, 3 disabled, 4 cap or quota reached, 5 needs transcript.
YouTube API policy and your data
Read Google's YouTube API Services Terms of Service and Developer Policies for your own use, including the limits on storing API data. They change; check the current text. By default the plugin keeps stored video details for 30 days and then purges them, or refreshes them if you choose; it never purges anything outside the settings above. Captions you download for your own channel's videos are kept on the draft as private meta for checking quotes until draft_transcript_days removes them.
The OAuth scope youtube.force-ssl is what caption download requires, and it can manage the account. The plugin only calls videos.list, channels.list, captions.list, captions.download and, with playlists on, playlistItems.list. Connect a channel account used for this purpose. A Google project left in "testing" status loses its refresh token after seven days; the plugin then asks you to reconnect.
Transcripts can hold personal data about the people speaking. They go to your configured model provider and nowhere else. The plugin adds a paragraph to the privacy policy guide.
Limitations
- Caption download works only for videos the connected account owns or may edit. For other videos you supply the transcript.
- No audio transcription and no video download.
- No machine translation through YouTube; the model translates when the article language differs.
- The token estimate is bytes divided by three (adjustable per model); it is an estimate.
- Counters and locks use options. The site lock (an atomic insert, and a compare-and-swap to take over an expired lock) keeps one runner at a time, so the daily caps cannot race. Quota units spent outside the runner (estimates, playlist reads, connecting) are counted without that lock and can be off by a few units.
- The privacy-enhanced player is an HTML block; users without
unfiltered_htmlwho edit the draft may see it stripped.
FAQ
Can it publish automatically? No. Status is forced to draft or pending after every filter.
Why do I need my own Google project? The plugin uses only the official API with your credentials. Quota and consent are yours.
The job says "needs transcript". The account cannot download that video's captions, or there are none. Upload a WebVTT, SRT, SBV, TTML or text file from the job screen and the job resumes without another metadata call.
A quote I expected is missing. It was not found word for word in the transcript, so it was dropped; the draft notes give the count.
How do I stop everything now? wp yt-to-post disable, the switch on the settings screen, or define('YT_TO_POST_DISABLED', true);.
Licence
MIT. Copyright (c) 2026 Indian Opinion. See LICENSE.