Schedule icon
VideoStats icon
Script icon
Process icon
DiscordIncomingWebhook icon

Snapshot YouTube Stats into Warehouse-Ready JSONL

Snapshot YouTube video stats to JSONL with Kestra. Fetch views and likes, reshape rows with Python, and stage a warehouse-ready file daily.

Categories
Business

The YouTube API tells you where a video stands right now; it does not keep history for you. This blueprint builds that history: io.kestra.plugin.youtube.VideoStats snapshots view, like, and comment counts for a tracked catalog, a small Python step reshapes the per-video array into snake_case JSONL rows stamped with the capture time, and the file lands in Kestra's internal storage ready for any warehouse loader. Run it daily and you get the time series YouTube Studio never exports.

How it works

  1. fetch_stats (io.kestra.plugin.youtube.VideoStats) pulls statistics and snippet metadata for every video in the video_ids input, outputting a videos array plus aggregate totals.
  2. reshape_to_jsonl (io.kestra.plugin.scripts.python.Script on the Process task runner, no container required) receives the array through inputFiles rendered with toJson, flattens each video into a snake_case row, stamps every row with a UTC captured_at, and declares videos.jsonl as an output file.
  3. notify posts the aggregate scalars to Discord; the JSONL extract stays attached to the execution.
  4. The errors block posts a distinct Discord alert on failure, protecting the continuity of the time series.
  5. A disabled-by-default Schedule trigger captures one snapshot every day at 05:00.

What you get

  • A daily, timestamped extract turning point-in-time API reads into a growing time series.
  • Warehouse-friendly snake_case JSONL that loads into DuckDB, BigQuery, Snowflake, or Postgres without preprocessing.
  • The reshape running as a plain process, no Docker dependency in the flow itself.
  • Aggregate numbers in Discord for a quick daily health read on the catalog.

Who it's for

  • Analytics engineers adding YouTube performance to an existing warehouse and BI stack.
  • Content teams who want week-over-week growth queries instead of screenshots from YouTube Studio.
  • Data teams building marketing attribution models that need video engagement history.

Why orchestrate this with Kestra

A snapshot pipeline is only as good as its regularity, one missed day is a permanent hole in the series. Kestra provides the schedule, retries, a durable file per run in internal storage, execution history to audit exactly what was captured when, and an alert the morning a token expires instead of a gap discovered weeks later.

Prerequisites

  • A Google Cloud project with the YouTube Data API v3 enabled and an OAuth2 access token with read scope. Pair with the YouTube token refresh blueprint to keep it fresh.
  • Python available on the Kestra host for the Process task runner, or switch the task to a Docker task runner.
  • A Discord incoming webhook for confirmations and alerts.

Secrets

  • YOUTUBE_ACCESS_TOKEN: OAuth2 bearer token for the YouTube Data API.
  • DISCORD_WEBHOOK_URL: Discord incoming webhook URL.

Quick start

  1. Add the two secrets to your Kestra namespace.
  2. Replace the default video_ids with your tracked catalog.
  3. Execute the flow and download videos.jsonl from the execution's Outputs tab to inspect the rows.
  4. Set disabled: false on the daily trigger.

How to extend

  • Load the extract into DuckDB with io.kestra.plugin.jdbc.duckdb.Query reading the output file URI, following the pattern in the dlt REST API to DuckDB blueprint.
  • Hand the file to a dlt pipeline for merge semantics and schema evolution when the row shape grows.
  • Upload the JSONL to S3 or GCS first if your warehouse loads from object storage.
  • Add includeContentDetails: true and extend the Python rows with duration and definition.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.