Extract YouTube Channel IDs
A lightweight, robust Go tool and library to extract the Channel ID (UC...)
from any YouTube URL including videos, handles, and short links.
🔍 Universal Extraction
Works with Video URLs, Channel URLs, Handles, Custom URLs, and Short links (youtu.be).
⚡️ Fast & Lightweight
Written in Go. Minimal dependencies. Scrapes public HTML efficiently.
📦 Library or CLI
Use it as a standalone command-line tool or import it into your Go projects.
Installation
You can install the library via standard Go tools or run it directly.
Go Get
go get github.com/cedev-1/yt-id-scraper
Nix (Development)
nix develop
Usage
CLI Tool
Build and run the tool to extract an ID from a URL.
Or run quickly without building:
go run main.go https://www.youtube.com/watch?v=dQw4w9WgXcQ
Go Library
Import the package and use scraper.GetChannelID.
How it Works
The scraper employs a multi-strategy approach to ensure high reliability:
- Checks if the URL is already a canonical channel URL.
- Fetches the page HTML and looks for the
meta itemprop="channelId"tag. - Parses the
ytInitialDataJSON blob for the channel ID. - Falls back to canonical link tags if redirects occur.