kkdai/youtube

repository·master·Indexed 26 days ago

https://github.com/kkdai/youtube

A Go-based package and CLI tool (youtubedr) for downloading YouTube videos. It supports retrieving video and playlist metadata, downloading specific qualities/itags, and provides a Go library for integration into other projects. The tool includes features for filtering video formats by quality, mime-type, and language, and supports multiple client profiles (Web, Android, iOS, Embedded, AndroidVR) to mimic different devices.

Tokens
4.3K
Snippets
6
Records
44
Agent score
87%

What's inside kkdai/youtube

  1. Run youtubedr manually from source

    master

    If you want to run the tool without installing it globally, you can clone the repository and use go run.

    git clone https://github.com/kkdai/youtube.git && cd youtube
    go run ./cmd/youtubedr
  2. Use the youtube package in a Go program

    master
    You can import the github.com/kkdai/youtube/v2 package to use its functionality directly within your Go applications. Refer to example_test.go in the repository for implementation details.
  3. Install the youtubedr CLI

    master

    You can install the youtubedr binary using several methods depending on your environment. Ensure you have Go 1.26 or later installed if using go install.

    # Install via Go
    go install github.com/kkdai/youtube/v2/cmd/youtubedr@latest
    
    # Mac (Homebrew)
    brew install youtubedr
    
    # Termux
    pkg install youtubedr
  4. Get video information with youtubedr info

    master

    Use the info command to retrieve metadata about a video, including available streams, their itag, quality, and codec information.

    youtubedr info https://www.youtube.com/watch?v=rFejpH_tAHM
  5. Set the global log level via LOGLEVEL environment variable

    master
    The package initializes its global Logger using the LOGLEVEL environment variable. If LOGLEVEL is set, the logger will use that level; otherwise, it defaults to the standard slog default level.
  6. Download a video stream with GetStream

    master

    To download the actual video/audio data, use GetStream(video *Video, format *Format). This returns an io.ReadCloser and the total size in bytes.

    For context-aware downloads, use GetStreamContext(ctx context.Context, video *Video, format *Format). The client will automatically use chunked downloading if the format's ContentLength is known to improve speed.

  7. Fetch video metadata with GetVideo

    master

    Use GetVideo(url string) to fetch metadata for a specific YouTube video. This method uses context.Background() internally.

    For better control over request lifecycles, use GetVideoContext(ctx context.Context, url string) which allows you to pass a custom context.

  8. Fetch video transcripts with GetTranscript

    master

    Use GetTranscript to fetch the transcript for a specific video in a given language. Note that not all videos have transcripts available (typically only newer videos). If transcripts are disabled or unavailable, the method returns ErrTranscriptDisabled.

    Alternatively, use GetTranscriptCtx to provide a custom context.Context for request cancellation or timeouts.

  9. Filter video quality and sort formats

    master

    The *Video type provides a convenience method FilterQuality(quality string) to reduce the available formats to those matching a specific quality string and then sort them automatically.

    This method updates the Formats field on the Video object in-place.