yt-id-scraper
GitHub

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.

# Build
go build -o yt-scraper
# Run
./yt-scraper https://www.youtube.com/@YouTube
# Output
UCBR8-60-B28hp2BmDPdntcQ

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.

package main import ( "fmt" "log" "github.com/cedev-1/yt-id-scraper/scraper" ) func main() { id, err := scraper.GetChannelID("https://www.youtube.com/@YouTube") if err != nil { log.Fatal(err) } fmt.Println(id) // UCBR8-60-B28hp2BmDPdntcQ }

How it Works

The scraper employs a multi-strategy approach to ensure high reliability:

  1. Checks if the URL is already a canonical channel URL.
  2. Fetches the page HTML and looks for the meta itemprop="channelId" tag.
  3. Parses the ytInitialData JSON blob for the channel ID.
  4. Falls back to canonical link tags if redirects occur.