npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stephane-klein/youtube-to-markdown

v0.16.0

Published

Collect YouTube channel videos into a YAML config with yt-dlp, download transcripts and turn them into Markdown prose with an LLM.

Readme

youtube-feed-to-markdown

The youtube-to-markdown CLI generates Markdown files from YouTube video transcripts.

I use it to search through the content of popular-science videos and shows of all kinds. I also use it to feed that corpus into a RAG.

Technically, it is fairly simple: the project relies on yt-dlp to fetch the metadata of a YouTube channel or playlist and then to download its transcripts.

In the final step, I use an LLM through a standard OpenAI-compatible API to reconstruct a complete text from the video transcripts.

AI usage in this project

This project was developed using:

  • Harness: OpenCode
  • Models: DeepSeek-V4.1-Flash via OpenCode Go
  • I mostly vibe coded this project: I made the implementation, library and architecture choices, but I reviewed the code very little.

The figures below cover the period from the start of the project to version 0.4.0 (de39801).

Metrics:

  • 16 OpenCode sessions, 1426 interactions;
  • 11 h of human time on this project, against 4 h of AI generation time over the same period, so a human/AI time ratio of 2.75 (11 h / 4 h);
  • Cost: $2.4958;
  • Tokens:
    • input: 7,047,916
    • output: 421,770
    • cache read: 228,841,600
    • total: 236,311,286

Per agent:

| agent | interactions | share | output tokens | active hours | active share | generation hours | cost | |:--------|-------------:|------:|--------------:|-------------:|-------------:|-----------------:|-------:| | build | 962 | 68% | 259,706 | 3.71 | 38% | 1.93 | $1.385 | | plan | 450 | 32% | 155,136 | 5.91 | 61% | 2.10 | $1.098 | | explore | 14 | 1% | 6,928 | 0.02 | 0% | 0.02 | $0.013 |

Requirements

  • Node.js 22 or later;
  • yt-dlp on your PATH.

The commands call yt-dlp with --js-runtimes node: solving YouTube's JavaScript challenges requires an external JavaScript runtime, and Node.js — already required here — does the job.

Install

The package is published on npmjs as @stephane-klein/youtube-to-markdown. Install it globally to get the youtube-to-markdown command on your PATH:

$ npm install -g @stephane-klein/youtube-to-markdown

Or run it without installing it, with npx:

$ npx @stephane-klein/youtube-to-markdown extract-video-metadata

Either way, yt-dlp must be on your PATH (see Requirements).

Run youtube-to-markdown --help to list the available commands:

$ youtube-to-markdown --help
youtube-to-markdown <command>

Commands:
  extract-video-metadata  Fetch the videos of each feed source (channel or
                          playlist) from YouTube into the configuration file
  download-vtt            Download the VTT transcripts of the marked videos
  generate-markdown       Turn the VTT, PDF or HTML transcripts into Markdown
                          prose with an LLM
  label-speakers          Add speaker labels to dialogue Markdown files
  markdown-stats          Report global tokens, cost and time from the Markdown
                          frontmatter
  reorganize              Move the transcripts and Markdown into their
                          folder_slug folders
  doctor                  Check the runtime dependencies and the LLM access
  completion              Generate a shell completion script for bash or zsh

Options:
  --config   Path to the YAML configuration file
                                  [string] [default: "youtube_to_markdown.yaml"]
  --version  Show version number                                       [boolean]
  --help     Show help                                                 [boolean]

Install the shell completion for bash or zsh ($SHELL selects the script):

$ youtube-to-markdown completion >> ~/.zshrc

Use ~/.bashrc on bash.

Getting started

1. Create youtube_to_markdown.yaml with the LLM settings and your sources. The example below uses OpenCode Go, an OpenAI-compatible API:

x_opencode_session: "youtube-to-markdown/0.1"
model_id: "mimo-v2.5"
openaiapi_endpoint: "https://opencode.ai/zen/go/v1/chat/completions"
feed:
  - title: Science4All
    url: https://www.youtube.com/@le_science4all
    videos: []

Only the url is required: extract-video-metadata fills the titles, the dates and the video lists. model_id and openaiapi_endpoint are not specific to OpenCode Go — point them at any OpenAI-compatible provider. The other settings are documented below.

2. Store your API key in .secret.sh and source it. Write it with your editor so the key never lands in your shell history:

$ $EDITOR .secret.sh
$ cat .secret.sh
export OPENAI_API_KEY="sk-…"
$ source .secret.sh

3. Check the setup with doctor and fix every error (a warn is fine):

$ youtube-to-markdown doctor
node      v24.21.0                                        ok
yt-dlp    2026.08.19                                      ok
config    youtube_to_markdown.yaml                        ok (2 channel(s), 636 video(s))
contents  contents                                        ok
model     mimo-v2.5                                       ok
endpoint  https://opencode.ai/zen/go/v1/chat/completions  ok
api key   OPENAI_API_KEY                                  ok
session   set                                             info
pricing   models.dev                                      ok ($0.14 in / $0.28 out / $0.0028 cached per 1M)
llm       1.0s                                            ok (248 in / 8 out)

summary: 9 ok, 0 warning, 0 error

doctor exits with a non-zero status as soon as one line is an error, so it can gate a CI job.

4. Fetch the source videos into the file:

$ youtube-to-markdown extract-video-metadata
→ https://www.youtube.com/@le_science4all
  exact dates 50/2217  2.4s elapsed  ~1m 44s left
  exact dates 100/2217  4.8s elapsed  ~1m 42s left
  exact dates 2217/2217  1m 46s elapsed
  done in 1m 46s
→ https://www.youtube.com/@MonsieurPhi
  done in 12.3s
summary: 2 sources, 2678 videos, 2m 05s elapsed

The command is idempotent: a new run only adds the missing videos. YouTube Shorts are never added; a short already present in the file is removed on the next run.

5. Generate the Markdown with download-vtt, then generate-markdown. The other commands are markdown-stats, reorganize and doctor; run youtube-to-markdown <command> --help for their options.

Configure the settings and the sources

The commands read youtube_to_markdown.yaml from the current directory; override it with --config or YT_TO_MD_CONFIG. It holds the settings and the sources. Settings resolve in this order: command-line flags, then YT_TO_MD_* environment variables, then the settings written in the YAML file, then the built-in defaults. The API key stays a secret: --api-key or OPENAI_API_KEY. The settings are x_opencode_session, model_id, openaiapi_endpoint, concurrency and ytdlp_concurrency (plus the optional api_key, retry_delays, max_output_tokens, chunk_target_tokens, reasoning and contents_path). I only set the source URLs, and the extract-video-metadata command fills the rest:

x_opencode_session is the base of the X-OpenCode-Session header; it is optional and specific to OpenCode. A stable per-video suffix is appended to it, so each video is routed as its own conversation. model_id and openaiapi_endpoint are not: point them at any OpenAI-compatible provider.

x_opencode_session: "youtube-to-markdown/0.1"
model_id: "mimo-v2.5"
openaiapi_endpoint: "https://opencode.ai/zen/go/v1/chat/completions"
concurrency: "6"
ytdlp_concurrency: "2"
feed:
  - title: Science4All
    folder_slug: science-4-all
    url: https://www.youtube.com/@le_science4all
    authors:
      - Lê Nguyên Hoang
    videos:
      - title:
          fr: Pourquoi π est-il si fou ? Relativité 1
          en: Why is π so crazy? Relativity 1
        date: 2016-02-12
        url: https://www.youtube.com/watch?v=PxRPpdzmbUQ
  - title: MrPhi
    url: https://www.youtube.com/@MonsieurPhi
    videos: []

contents_path (optional) chooses the directory that holds the transcripts and the generated Markdown. It defaults to contents. You can set it in the YAML file, with YT_TO_MD_CONTENTS_PATH, or with --contents-path; like the other settings, the flag wins over the environment variable, which wins over the YAML file. A relative path is always resolved against the directory of youtube_to_markdown.yaml, whichever way you set it. .gitignore only ignores the default contents/, so add your own path there if you move it.

folder_slug (optional, on a feed entry) stores that source's transcripts and Markdown in a subdirectory of contents_path, for example science-4-all. It is a relative path, so it stays inside contents_path; a source without folder_slug keeps its files at the root of contents_path. The reserved name _orphans is rejected. Change it whenever you like, then run youtube-to-markdown reorganize to move the existing files.

Playlists

A feed entry can point to a YouTube playlist instead of a channel:

feed:
  - title: Contre-histoire de la philosophie, vol. 9
    folder_slug: contre-histoire-philo-9
    url: https://www.youtube.com/playlist?list=OLAK5uy_lEyjyS840R2OkHNVgOt1fGjPzeBTs1xKI
    videos: []

The commands detect a playlist from its URL (the /playlist path); extract-video-metadata uses it as is instead of resolving the channel uploads playlist. title is filled with the playlist title when it is empty, and the videos keep the playlist order instead of being sorted by date. Each video gets an index field (1, 2, …) which becomes the filename prefix: contents/contre-histoire-philo-9/1-2019-01-04_quel-xixeme-siecle-i-un-temps-nouveau.fr.vtt. The index field is written by extract-video-metadata; do not edit it by hand. A video removed from the playlist is kept as an extra, without index, at the end of the list.

Download the transcripts of the videos

I mark the videos I want as transcripts with a download_vtt field:

  - title:
      fr: Pourquoi π est-il si fou ? Relativité 1
      en: Why is π so crazy? Relativity 1
    date: 2016-02-12
    url: https://www.youtube.com/watch?v=PxRPpdzmbUQ
    download_vtt:
      fr: true

Then:

$ youtube-to-markdown download-vtt
21 transcript(s) to check
[ 1/21] downloaded         2016-07-14_le-sol-accelere-t-il-vraiment-vers-le-haut-debattonsmieux.fr.vtt
[ 2/21] already downloaded 2016-08-25_les-synonymes-a-connotations-opposees-debattonsmieux.fr.vtt
[ 3/21] missing            2017-06-26_favoriser-l-honnetete-democratie-18.fr.vtt
…
summary: 1 downloaded, 1 already downloaded, 1 missing, 0 error

For each marked video, the command writes the subtitle to contents/<date>_<slug>.<lang>.vtt, for example contents/2016-02-12_pourquoi-est-il-si-fou-relativite-1.fr.vtt. It prefers manual subtitles and falls back to the auto-generated ones. A file that already exists is left untouched, so running the command again only fetches new transcripts. The extract-video-metadata command keeps the download_vtt field.

When a video has no subtitle at all, the command writes a <…>.vtt.missing marker and stops trying. I delete that marker to force a new attempt.

Use a PDF transcript instead of the YouTube one

Some channels publish a written transcript as a PDF. When I have that file, I prefer it to YouTube's automatic transcript. I declare it with transcript_pdf:

      - title:
          fr: "Example episode: a subtitle"
        date: 2026-01-01
        url: https://www.youtube.com/watch?v=example
        generate_markdown:
          fr: true
        transcript_pdf:
          fr: raws/example-channel/2026-01-01_example-episode.pdf

The path is relative to the YAML file. An absolute path also works. The CLI never downloads the PDF: I put the file in place myself.

PDF text extraction uses unpdf, a pure JavaScript build of Mozilla PDF.js. It comes with the npm package, so there is no extra system dependency.

generate_markdown remains the switch that authorises the LLM call. A transcript_pdf entry without generate_markdown produces no Markdown.

When both download_vtt and transcript_pdf exist for the same language, the PDF wins for generation. download_vtt still controls the separate download-vtt command; generate-markdown does not download a VTT for a PDF source.

transcript_pdf and transcript_html cannot both be set for the same language. The command stops with an explicit error instead of choosing silently.

If the declared PDF is missing, the generation fails with an explicit error. The command does not fall back to the VTT. If the PDF has no text layer (a scan), the command stops with an error because OCR is not supported.

The generated file keeps the usual name and layout. Its frontmatter records the source:

transcript_source: pdf
transcript_pdf: raws/example-channel/2026-01-01_example-episode.pdf

Use --force to regenerate a Markdown file after I update its PDF.

The labelling pass still needs a VTT for its speaker cues, so a PDF-only video does not produce a .dialogue.md file.

Use an HTML transcript instead of the YouTube one

Some shows publish the script of an episode as a web page. The page also carries the site chrome: header, sidebars, related links and footer. I declare the page URL with transcript_html:

      - title:
          fr: "Example episode: a subtitle"
        date: 2026-01-01
        url: https://www.youtube.com/watch?v=example
        generate_markdown:
          fr: true
        transcript_html:
          fr: https://example.com/example-episode/
        # Optional: impose the names behind the turn initials.
        speaker_names:
          G: Gilles
          M: Marina

The URL must use HTTP or HTTPS. The CLI fetches the page once and stores it in raws/<folder_slug>/<date>_<slug>.<lang>/page.html, next to a page.url file. Later runs read the local page and do not touch the network. Delete page.html to fetch the page again. --force regenerates the Markdown from the saved page, but does not refresh the page itself.

The article is extracted with Mozilla Readability and converted to Markdown with Turndown. Navigation, sidebars, related articles and the footer are removed. The page must contain the article in its server response: the command does not run JavaScript. If a site blocks the fetch or renders the article in the browser, save the page yourself as page.html and write its URL in page.url, in the same directory.

The content images are downloaded into the same directory as image-1.png, image-2.jpg, and so on. The extension follows the image format (png, jpg, webp, ...). A figcaption becomes the image alt text; an image without a caption keeps an empty alt. The Markdown points to the local files with a path relative to the YAML file, for example raws/example-channel/2026-01-01_example-episode.fr/image-1.png. The page and its images are retried on transient failures, with short delays; after that the job fails and no Markdown is written.

A YouTube embed becomes a link with its timestamp, for example [Vidéo YouTube — extrait à 0:07](https://www.youtube.com/watch?v=…&t=7s). The bold paragraph that names the quoted source stays where it is in the article. Other embedded videos become a simple link to their player URL.

The LLM pass keeps the source headings, the bold source labels and the turn markers such as G – and M –. It removes the production notes that are not spoken: bracketed stage directions, comments addressed to the editor and separator lines made of underscores. It does not rewrite the dialogue.

After the text pass, a small LLM request identifies the people behind the turn initials from the video title, the page byline, the known authors and the beginning of the transcript. The command applies only the names returned with high confidence, and writes Gilles – … instead of G – …. If the model is not sure, the initial stays in place. Set speaker_names in the YAML to impose the mapping and skip the inference.

The generated file keeps the usual name and layout. Its frontmatter records the source and the names that were applied:

transcript_source: html
transcript_html: https://example.com/example-episode/
speaker_names:
  G: Gilles
  M: Marina

generate_markdown remains the switch that authorises the LLM call. A transcript_html entry without generate_markdown produces no Markdown.

download_vtt may coexist with transcript_html. It still controls the separate download-vtt command, but generate-markdown uses the HTML page and does not fall back to the VTT when the page fails. Remove transcript_html if I want to use the VTT instead.

The labelling pass ignores HTML sources: the flat Markdown already carries its turn markers, replaced by names when the inference succeeds, so no .dialogue.md file is produced. The reorganize command does not move the raws bundle when folder_slug changes; move the directory yourself or regenerate with --force.

Generate Markdown text from the transcripts

I mark the videos I want as Markdown with generate_markdown. The transcript is downloaded first if it is not there yet, or read from its PDF or HTML page when transcript_pdf or transcript_html is set:

    download_vtt:
      fr: true
    generate_markdown:
      fr: true
    # Optional: force or disable dialogue labelling.
    dialogue: true
    # Optional: impose the speaker labels used by the labelling pass.
    # speakers: [Journaliste, Jean-Luc Mélenchon]

Before the first run, provide your API key through the OPENAI_API_KEY environment variable, or pass it with --api-key.

Then:

$ youtube-to-markdown generate-markdown
74 markdown(s) to generate with mimo-v2.5 (sources: 74 vtt)
✔ Prepare transcripts (73/74)
  › downloaded  2017-08-04_nietzsche-la-morale-des-winners-genealogie-de-la-morale-1-2.fr.md
  › skipped (no transcript)  2017-06-26_favoriser-l-honnetete-democratie-18.fr.md
✔ Generate markdown (73/74, 37 already)
  › generated [source: vtt]  2017-10-13_le-scepticisme-le-trilemme-d-agrippa-grain-de-philo-14-ep-2.fr.md  mimo-v2.5  llm 87.1s  4428 in / 3262 out  ~$0.000927
  …
summary: 36 generated, 37 already generated, 1 skipped, 0 error
total: 3135.6s, 159408 in / 117432 out, ~$0.033372

The startup line counts the transcript sources. Every generation progress line carries [source: vtt], [source: pdf] or [source: html], so a long generation says whether it reads a VTT, a PDF or an HTML page.

The command sends each transcript to an LLM through ai-sdk, configured with the API key (OPENAI_API_KEY or --api-key), the model (YT_TO_MD_MODEL_ID or --model) and the endpoint (YT_TO_MD_OPENAIAPI_ENDPOINT or --endpoint), and gets back Markdown prose with section headings when the talk needs them. Paragraphs are hard-wrapped at 80 columns. The flat text goes to contents/<date>_<slug>.<lang>.md; the frontmatter records likely_dialogue: true, false or null.

When the video is a dialogue, a second pass adds speaker labels and writes contents/<date>_<slug>.<lang>.dialogue.md. Each turn starts with a bold label inferred from the transcript, for example **Journaliste :** or **Jean-Luc Mélenchon :**. The flat .md is never modified by this pass, and the labelling pass refuses to write anything if its output changes the text.

Set dialogue: true in the feed to force labelling, dialogue: false to disable it, or leave it out to let the command detect the dialogue from an excerpt of the flat text. speakers is optional and fixes the labels used by the second pass; a non-empty list also marks the video as a dialogue. youtube-to-markdown label-speakers reruns only the labelling pass on existing flat files, without regenerating the text.

The command runs in three sequential phases. Prepare transcripts reports how many videos have a transcript (available/total) and fetches the missing VTT files, at most --ytdlp-concurrency at a time (default 2); only downloads, skips and errors are listed. A PDF source is checked in the same phase and is never downloaded. An HTML source is fetched and its images are downloaded in the same phase, at most --ytdlp-concurrency at a time; the phase shows fetching html page, extracting html article, then downloading N images or checking N images before prepared [source: html]. The Generate markdown phase converts the transcripts into flat text, at most --concurrency at a time (default 6), reporting the number of up-to-date Markdown files over the whole feed (ready/total, N already). It shows the source tag on reading, generating and generated. The Label speakers phase then labels the dialogue files, except for HTML sources. Each phase keeps only the last 20 events on screen, so it stays bounded even with a large feed.

Retryable API errors (HTTP 408, 409, 429 or >= 500) are retried with growing delays — 10 s, 30 s, 60 s by default, configurable with --retry-delays (comma-separated seconds, or YT_TO_MD_RETRY_DELAYS). A Retry-After header from the server is honored when longer than the schedule. Each retry line shows the reason reported by the API (status and response body), for example:

retrying in 30s (attempt 3/4) HTTP 429 rate limited  [source: vtt] david-cayla/....fr.md

After the last attempt the file is reported as an error and is retried on the next run. At the end of the run, a failures: block lists each failed file with its reason, so the cause stays visible even after the phase output has scrolled. The command exits with a non-zero status when at least one file failed.

Empty output

A model can finish with finish_reason: stop but return no text at all, for example when it spends its whole response on internal reasoning. Such a generation is reported as an error and no file is written:

error (empty output: part 1/1, finish=stop, text_tokens=1, reasoning_tokens=4001)  ....fr.md

The failures: block repeats the reason at the end of the run. Add --debug-llm (or YT_TO_MD_DEBUG_LLM=1) to log the request's max_tokens and reasoning_effort, plus the size of the provider's content and reasoning_content, which helps diagnose provider-side empty answers.

Reasoning effort

The command asks the model for a reasoning effort of low by default. Set reasoning in the YAML file, YT_TO_MD_REASONING, or --reasoning to change it. The accepted values are provider-default, none, minimal, low, medium, high and xhigh, as exposed by ai-sdk. none disables reasoning: on a DeepSeek endpoint it sends the provider-specific thinking: disabled option, elsewhere it sends reasoning: none. provider-default leaves the choice to the provider.

reasoning: "none"

The doctor command shows the effective value and applies it to its test request, so it reflects the real configuration.

Output budget and long transcripts

The model must rewrite the whole transcript, so the generation pass asks it for roughly twice the input size (maxOutputTokens). The speaker-labelling pass asks for three times the size of the flat text, because the model's reasoning tokens count against the same budget. That budget is capped per call: the command reads the model's advertised output limit from the pricing catalogs and uses it as the ceiling; if the catalog has no entry it falls back to 32768 tokens. --max-output-tokens (or YT_TO_MD_MAX_OUTPUT_TOKENS) overrides the ceiling by hand and still wins over the computed factor.

When the projected output would exceed the ceiling — a long video on a model with a small output limit — the transcript is split into chunks that each fit the budget, generated independently, then stitched together: immediately repeated headings are dropped and each junction is smoothed by a small extra LLM call that rewrites the beginning of the next section so it flows from the previous one. --chunk-target-tokens (or YT_TO_MD_CHUNK_TARGET_TOKENS, default 8000) sets the target input size of each chunk. The generation of a chunk is guaranteed to stop with stop; otherwise the file is reported as an error and nothing is written. The same happens when a part comes back with an empty body. The frontmatter records how many chunks were used.

Generated frontmatter

Each generated file starts with a YAML frontmatter describing the run:

---
source_url: https://www.youtube.com/watch?v=PxRPpdzmbUQ
video_title: Pourquoi π est-il si fou ? Relativité 1
generated_at: 2026-09-19T10:12:33.456Z
authors:
  - Lê Nguyên Hoang
original_published_date: 2016-02-12
likely_dialogue: false
llm:
  model: mimo-v2.5
  chunks: 1
  duration_seconds: 87.1
  input_tokens: 4428
  cached_input_tokens: 0
  output_tokens: 3262
  reasoning_tokens: 0
  text_tokens: 3262
  estimated_cost_usd: 0.000927
  finish_reason: stop
  raw_finish_reason: stop
  pricing:
    source: models.dev
    peak: null
---

authors copies the authors list of the feed entry and stays [] when the entry has none; a video can override it with its own authors field. original_published_date is the video's date from the feed. video_title is the original video title in the file's language, generated_at is the UTC time of the generation and likely_dialogue records whether the text looks like a dialogue between two or more people (null when the detection was inconclusive). pricing.source names the catalog the rates came from and pricing.peak tells whether the peak rate applied to the first call (null when the source has no peak/off-peak pricing). Existing files are left untouched: run youtube-to-markdown generate-markdown --force to regenerate every file, which is also the way to add the frontmatter to files generated before it existed.

Pricing

The estimated cost uses rates fetched at run time from models.dev and LiteLLM. The provider is resolved from openaiapi_endpoint; LiteLLM is preferred when it prices the model, because it carries DeepSeek's peak/off-peak windows, otherwise models.dev is used. Both catalogs are cached for one day under $XDG_CACHE_HOME/youtube-to-markdown (~/.cache/youtube-to-markdown by default). When a catalog or the model is unavailable, estimated_cost_usd is null and the run continues.

The rate is sampled at the start of every LLM call, so a run that straddles a peak/off-peak boundary is priced with the right rate on each side. The pricing block in the frontmatter describes the first call of the file.

Dialogue videos and speaker labels

The pipeline keeps the generated text and the speaker attribution separate:

  1. the flat file (...fr.md) is the reference text;
  2. the dialogue file (...fr.dialogue.md) is a derived annotation that only inserts **Speaker :** labels and blank lines.

The generation pass is a transcription pass, not a summary: it must preserve the speaker's words, keep direct speech direct, and never turn the interview into a third-person narrative. It must also preserve the oral syntax of the spoken language — repetitions, false starts, unusual word order — instead of correcting it into a more formal or more standard form; the model is only allowed to fix what comes from the automatic transcription (timestamps, broken cues, punctuation, capitalisation, misheard words). If the generated text looks like a summary (for example the journalist asks, he explains, L’entretien s’ouvre), the file is reported as an error and no .md is written.

The labelling pass does not ask the model to copy the text. It splits the flat body into numbered sentences and asks for a JSON list of speaker turns:

{ "turns": [{ "start": 0, "speaker": "Journaliste" }] }

start is the sentence index shown to the model, not a line number. Only the first sentence of a turn is listed; the following sentences belong to the same speaker until the next start. The renderer inserts the **Speaker :** labels into the frozen sentences, so the text cannot be rewritten or truncated. The model receives compact short-line VTT cues rather than the full transcript.

Headings are displayed in the numbered prompt but are never numbered or labelled. Invalid JSON, invalid indices, a missing first turn or a single speaker triggers one stricter retry; after that the command reports an error with an output preview. When a pass reaches its output limit, the command fails immediately with an explicit message showing max_tokens, output_tokens, reasoning_tokens and text_tokens, and suggests either a larger --max-output-tokens or a lower reasoning effort.

The dialogue key in feed.yaml is optional. Without it, a short LLM pass samples the beginning and the end of the flat text and writes likely_dialogue in the frontmatter. --label-uncertain also labels files whose detection returned null. Existing flat files are not migrated automatically: the new naming applies to files generated by this version.

The labelling pass ignores HTML sources. Their flat Markdown already contains the turn markers, and generate-markdown replaces the initials with the inferred names, so no .dialogue.md file is needed.

Organize the files into folders

A channel may set folder_slug to keep its files in their own subdirectory of contents_path. When you add, change or remove that setting, reorganize moves the already downloaded transcripts and generated Markdown to match. It runs for real by default; add --dry-run to preview:

$ youtube-to-markdown reorganize --dry-run
[ 1/38] moved     science-4-all/2016-07-14_le-sol-accelere….fr.vtt (dry run)
…
dry run: no file was moved
summary: 38 to move, 0 to orphan, 112 already in place, 0 conflict

A file that no longer matches any video of the feed is an orphan: the command moves it under contents_path/_orphans/, keeping its relative path. A file whose target already exists, or a filename shared by two channels with different folder_slug, is reported as a conflict and left untouched.

reorganize only walks contents_path. The raws/<folder>/<base>/ directory created for an HTML source is not moved, even when folder_slug changes.

Report the tokens, cost and time

markdown-stats reads the frontmatter of every *.md under contents_path (recursively), ignoring the *.dialogue.md derivatives to avoid counting the same video twice, and prints global totals — tokens, estimated cost, processing time — with a breakdown per model, per language and per folder (folder_slug, or (root) when the file sits at the root of contents_path):

$ youtube-to-markdown markdown-stats
contents/ — 43 file(s)
  with frontmatter     3
  without frontmatter  40

tokens
  input                16,134
  cached input         16,000
  output               14,486
  total                30,620

cost
  estimated            $0.004120
  unknown prices       0 file(s)

processing time
  total                395.6s
  mean                 131.9s
  min / max            111.8s / 165.3s

generated_at
  first                2026-09-19T08:56:54.497Z
  last                 2026-09-19T08:57:47.976Z

models
  mimo-v2.5           3 file(s)     16,134 in /    14,486 out  $0.004120

languages
  fr                  3 file(s)     16,134 in /    14,486 out  $0.004120

folders
  science-4-all       2 file(s)     10,134 in /     9,486 out  $0.002120
  (root)              1 file(s)      6,000 in /     5,000 out  $0.002000

Files without frontmatter (generated before the frontmatter existed) are counted but left out of the totals.

Set up the development environment

To work on this project, mise installs both yt-dlp and Node.js; npm install fetches the JavaScript dependencies:

$ mise install
$ npm install

The enter hook defines a youtube-to-markdown shell function that calls node src/cli.js, and loads the shell completion for bash and zsh; the leave hook removes both. Everything is set when you enter the project from an interactive bash or zsh shell, so it is only available in interactive shells; in scripts and CI, call node src/cli.js <command> instead. A function, rather than a shell alias, is what lets youtube-to-markdown <TAB> complete the subcommands: zsh expands aliases before dispatching completion, which would bypass compdef.

To generate Markdown without exporting OPENAI_API_KEY in your shell, copy .secret.sh.example to .secret.sh and put your API key in it; mise sources that file automatically:

$ cp .secret.sh.example .secret.sh
$ $EDITOR .secret.sh

Install the development version globally on your workstation

To run the CLI from other projects while working on its source, link the checkout into ~/.local/bin instead of installing the published package:

$ mise run install-cli-to-local-bin

Run npm install at the root of the repository first, because the linked script resolves its dependencies from node_modules at that root.

The task symlinks src/cli.js, so the command runs the working tree and every edit is active on the next call. It creates no global package state. Remove the link with mise run uninstall-cli-from-local-bin.

Inside this repository, the youtube-to-markdown function defined by the mise enter hook keeps precedence over the link. The link is for the other projects.

The link sits in ~/.local/bin, which comes before ~/.local/share/mise/shims in the PATH: it hides the globally installed npm package until mise run uninstall-cli-from-local-bin restores it.

Publish the package to npmjs

I publish the package to npmjs from this repository with mise:

$ npm login
$ npm version patch
$ mise run publish-to-npmjs

npm login authenticates against npmjs, once per machine. npm version patch bumps the version and creates the matching git tag (use minor or major for larger changes). mise run publish-to-npmjs first checks the authentication with npm whoami, then runs npm publish; it publishes the version written in package.json, so bump it first. The package is scoped, so publishConfig in package.json forces public access.