youtube

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package youtube extracts transcripts and metadata from YouTube videos.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Kind    ErrorKind
	URL     string
	VideoID string
	Message string
	Err     error
}

Error carries structured failure details for callers that need to branch on YouTube-specific failure modes.

func (*Error) Error

func (err *Error) Error() string

Error formats a human-readable error message.

func (*Error) Unwrap

func (err *Error) Unwrap() error

Unwrap returns the underlying cause.

type ErrorKind

type ErrorKind string

ErrorKind categorizes user-facing YouTube extraction failures.

const (
	// ErrorKindInvalidURL reports a malformed or unsupported YouTube URL.
	ErrorKindInvalidURL ErrorKind = "invalid_url"
	// ErrorKindUnavailable reports a video that cannot be accessed.
	ErrorKindUnavailable ErrorKind = "unavailable"
	// ErrorKindPrivate reports a private video.
	ErrorKindPrivate ErrorKind = "private"
	// ErrorKindAgeRestricted reports a video that requires login/age confirmation.
	ErrorKindAgeRestricted ErrorKind = "age_restricted"
	// ErrorKindTranscriptUnavailable reports missing or disabled captions.
	ErrorKindTranscriptUnavailable ErrorKind = "transcript_unavailable"
	// ErrorKindAudioUnavailable reports that no supported audio stream could be downloaded.
	ErrorKindAudioUnavailable ErrorKind = "audio_unavailable"
)

type ExtractOptions

type ExtractOptions struct {
	EnableSTTFallback  bool
	PreferredLanguages []string
}

ExtractOptions controls transcript extraction behavior.

type Extractor

type Extractor struct {
	// contains filtered or unexported fields
}

Extractor orchestrates transcript extraction and optional STT fallback.

func NewExtractor

func NewExtractor(cfg config.OpenRouterConfig) *Extractor

NewExtractor constructs a default extractor backed by kkdai/youtube and the OpenRouter STT client.

func (*Extractor) Extract

func (extractor *Extractor) Extract(ctx context.Context, rawURL string, options ExtractOptions) (*Result, error)

Extract fetches video metadata and transcript markdown from a YouTube URL.

type Metadata

type Metadata struct {
	VideoID     string
	URL         string
	Title       string
	Channel     string
	Duration    time.Duration
	PublishDate time.Time
}

Metadata contains normalized video metadata.

type OpenRouterClient

type OpenRouterClient struct {
	// contains filtered or unexported fields
}

OpenRouterClient calls the OpenRouter chat completions API for STT fallback.

func NewOpenRouterClient

func NewOpenRouterClient(cfg config.OpenRouterConfig) *OpenRouterClient

NewOpenRouterClient constructs an STT client from runtime configuration.

func (*OpenRouterClient) Configured

func (client *OpenRouterClient) Configured() bool

Configured reports whether the client has the credentials needed to call the OpenRouter API.

func (*OpenRouterClient) Transcribe

func (client *OpenRouterClient) Transcribe(ctx context.Context, audio []byte, format string) (string, error)

Transcribe sends audio bytes to OpenRouter and returns the transcript text.

type Result

type Result struct {
	Metadata Metadata
	Markdown string
	Source   TranscriptSource
	Language string
}

Result contains the extracted metadata and transcript markdown.

type TranscriptSource

type TranscriptSource string

TranscriptSource identifies how the transcript was produced.

const (
	// TranscriptSourceCaptions means YouTube captions were fetched directly.
	TranscriptSourceCaptions TranscriptSource = "captions"
	// TranscriptSourceSTT means audio was transcribed through OpenRouter.
	TranscriptSourceSTT TranscriptSource = "stt"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL