Skip to content

Getting Started

RequirementVersionPurpose
Python3.12+Runtime
uvlatestDependency management
YouTube Data API v3 keyChannel and video data

Get an API key from the Google Cloud Console. Enable the YouTube Data API v3 for the project associated with that key.

Terminal window
git clone https://github.com/mlorentedev/yt-metrics-cli.git
cd yt-metrics-cli
make install

make install creates a venv and runs uv pip install -e ".[dev]" with all dependencies.

Create a .env file in the project root:

# Required
YOUTUBE_API_KEY=your-api-key-here
# Optional
MAX_RESULTS_PER_CHANNEL=100 # Videos fetched per channel (default: 50)
OUTPUT_DIR=./output # Report output directory (default: ./output)
VIDEO_ID=dQw4w9WgXcQ # Default video ID for transcript mode

The API key is validated before every run. If it is missing, expired, or over quota, you get a descriptive error with a link to the console.

Create a channels.yml file in the project root. Each entry needs exactly one identifier:

# By @handle (most common)
- custom_url: "@technotim"
- custom_url: "@christianlempa"
# By legacy username
- username: "GoogleDevelopers"
# By raw channel ID
- channel_id: "UCxxxxxxxxxxxxxx"
Terminal window
yt-metrics channels

This fetches videos from every channel in channels.yml (up to MAX_RESULTS_PER_CHANNEL per channel), computes engagement metrics, and writes a timestamped report folder under output/. Each batch request retrieves statistics for 50 videos at a time to stay within API limits. API calls automatically retry with exponential backoff on rate limit errors (HTTP 403/429).

Generated files per run:

FileFormatContents
youtube_channels_videos_<ts>.csvCSVAll videos with 15 columns: channel, subscribers, title, date, URL, views, likes, comments, duration, and 6 calculated metrics
youtube_channel_stats_<ts>.txtTXTPer-channel breakdown: metadata, upload frequency, averages, top 5 by views, top 5 by engagement, performance distribution
youtube_engagement_trends_<ts>.txtTXTCross-channel rankings by engagement and view rate, content performance by duration category (short < 5 min, medium 5-15 min, long > 15 min), top 10 engagement, top 5 viral
youtube_best_videos_<ts>.txtURL listTop 15 videos per channel by engagement rate, one URL per line
youtube_latest_videos_<ts>.txtURL list15 most recent videos per channel, one URL per line
README.mdMarkdownSelf-documenting index explaining every file in the folder
Terminal window
yt-metrics transcript -v dQw4w9WgXcQ
yt-metrics transcript -v dQw4w9WgXcQ -l en,es

The downloader tries your preferred languages first, falls back to the first available transcript, and finally checks a local fixtures directory (YOUTUBE_TRANSCRIPT_FIXTURES_DIR) for offline use.

Output: <video_id>_transcript.txt in the output directory.

Every video in the CSV and reports includes these computed fields:

MetricFormulaInterpretation
Engagement Rate (Views)(likes + comments) / views * 100Audience interaction relative to reach
Engagement Rate (Subscribers)(likes + comments) / subscribers * 100Interaction relative to channel size
View Rateviews / subscribers * 100Viral signal when above 100%
Like Ratelikes / views * 100Content satisfaction
Comment Ratecomments / views * 100Discussion intensity
Views per Minuteviews / (duration_seconds / 60)Content efficiency — higher means more views per unit of content