Public id youtube scrapper https://cedev-1.github.io/yt-id-scraper/
  • Go 86.4%
  • Nix 13.6%
Find a file
2025-12-24 16:12:30 +01:00
.github/workflows add: simple github page 2025-12-24 16:12:30 +01:00
docs add: simple github page 2025-12-24 16:12:30 +01:00
scraper init: yt id scrapper 2025-12-24 15:58:49 +01:00
.envrc init: nix flake config 2025-12-24 15:58:25 +01:00
.gitignore gitignore 2025-12-24 15:58:58 +01:00
flake.lock init: nix flake config 2025-12-24 15:58:25 +01:00
flake.nix init: nix flake config 2025-12-24 15:58:25 +01:00
go.mod init: yt id scrapper 2025-12-24 15:58:49 +01:00
LICENSE Initial commit 2025-12-24 15:39:08 +01:00
main.go init: yt id scrapper 2025-12-24 15:58:49 +01:00
README.md README init 2025-12-24 15:59:14 +01:00

YouTube Channel ID Scraper

A lightweight Go tool and library to extract the YouTube Channel ID (e.g., UC...) from various YouTube URLs, including videos, handles, and short links.

Getting Started with Nix

This project provides a flake.nix for a reproducible development environment.

Prerequisites

  • Nix with flakes enabled.

Entering the Environment

To enter the development shell with Go pre-installed and configured:

nix develop

This will drop you into a shell with the correct Go version available.

Usage

CLI Tool

You can run the tool directly to scrape an ID from a URL.

Build:

go build -o yt-scraper

Run:

./yt-scraper <URL>
# OR
./yt-scraper -url <URL>

Quick Run (without building):

go run main.go <URL>

Examples:

$ ./yt-scraper https://www.youtube.com/watch?v=dQw4w9WgXcQ
UCuAXFkgsw1L7xaCfnd5JJOw

$ ./yt-scraper https://www.youtube.com/@YouTube
UCBR8-60-B28hp2BmDPdntcQ

Output Format:

  • Success: The tool prints the Channel ID (string starting with UC) to stdout and exits with code 0.
  • Error: The tool prints the error message to stdout (or stderr depending on implementation, currently stdout for simplicity in the main wrapper) and exits with code 1.

Library Integration

You can import the scraper package to use the logic in your own Go projects.

Installation:

go get github.com/cedev-1/yt-id-scraper

Code Example:

package main

import (
	"fmt"
	"log"

	"github.com/cedev-1/yt-id-scraper/scraper"
)

func main() {
	url := "https://www.youtube.com/@YouTube"
	
	channelID, err := scraper.GetChannelID(url)
	if err != nil {
		log.Fatalf("Failed to get channel ID: %v", err)
	}

	fmt.Printf("Channel ID: %s\n", channelID)
}

How it Works

The scraper fetches the public HTML of the provided YouTube URL and uses several strategies to locate the Channel ID:

  1. URL Parsing: Checks if the URL is already a canonical channel URL (/channel/UC...).
  2. HTML Scraping:
    • Looks for the <meta itemprop="channelId"> tag.
    • Searches for the ytInitialData JSON blob which often contains "channelId":"...".
    • Checks for the canonical <link> tag if the page redirects.

This approach works for:

  • Video URLs (/watch?v=...)
  • Handle URLs (/@Handle)
  • Custom URLs (/c/CustomName)
  • Short URLs (youtu.be/...)

License

LICENSE Apache License 2.0