youtube

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 22 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

func NewTranscriber added in v0.0.8

func NewTranscriber(sttConfig config.STTConfig, openRouterConfig config.OpenRouterConfig) sttClient

NewTranscriber constructs the configured STT backend.

Types

type CaptionKind added in v0.0.8

type CaptionKind string

CaptionKind identifies whether fetched YouTube captions were manual or ASR.

const (
	CaptionKindManual    CaptionKind = "manual"
	CaptionKindAutomatic CaptionKind = "automatic"
)

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"
	// ErrorKindNetworkBlocked reports a YouTube network block or bot-detection response.
	ErrorKindNetworkBlocked ErrorKind = "network_blocked"
)

type ExtractOptions

type ExtractOptions struct {
	TranscriptionPolicy TranscriptionPolicy
	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 NewExtractorWithConfig added in v0.0.8

func NewExtractorWithConfig(
	sttConfig config.STTConfig,
	openRouterConfig config.OpenRouterConfig,
	youtubeConfigs ...config.YouTubeConfig,
) *Extractor

NewExtractorWithConfig constructs an extractor with explicit STT provider configuration.

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 OpenAITranscriber added in v0.0.8

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

OpenAITranscriber calls OpenAI's audio transcriptions endpoint.

func NewOpenAITranscriber added in v0.0.8

func NewOpenAITranscriber(cfg config.STTConfig) *OpenAITranscriber

NewOpenAITranscriber constructs an OpenAI STT provider from runtime config.

func (*OpenAITranscriber) Configured added in v0.0.8

func (client *OpenAITranscriber) Configured() bool

func (*OpenAITranscriber) Model added in v0.0.8

func (client *OpenAITranscriber) Model() string

func (*OpenAITranscriber) Provider added in v0.0.8

func (client *OpenAITranscriber) Provider() string

func (*OpenAITranscriber) Transcribe added in v0.0.8

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

type OpenRouterClient

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

OpenRouterClient calls the OpenRouter chat completions API as an STT provider.

func NewOpenRouterClient

func NewOpenRouterClient(cfg config.OpenRouterConfig) *OpenRouterClient

NewOpenRouterClient constructs an STT client from runtime configuration.

func NewOpenRouterClientWithPrompt added in v0.0.8

func NewOpenRouterClientWithPrompt(cfg config.OpenRouterConfig, prompt string) *OpenRouterClient

func (*OpenRouterClient) Configured

func (client *OpenRouterClient) Configured() bool

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

func (*OpenRouterClient) Model added in v0.0.8

func (client *OpenRouterClient) Model() string

func (*OpenRouterClient) Provider added in v0.0.8

func (client *OpenRouterClient) Provider() string

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
	CaptionKind         CaptionKind
	TranscriptionPolicy TranscriptionPolicy
	STTProvider         string
	STTModel            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 an STT provider.
	TranscriptSourceSTT TranscriptSource = "stt"
)

type TranscriptionPolicy added in v0.0.8

type TranscriptionPolicy string

TranscriptionPolicy controls whether captions or STT are used.

const (
	TranscriptionPolicyCaptions TranscriptionPolicy = "captions"
	TranscriptionPolicyAuto     TranscriptionPolicy = "auto"
	TranscriptionPolicySTT      TranscriptionPolicy = "stt"
)

func ParseTranscriptionPolicy added in v0.0.8

func ParseTranscriptionPolicy(value string) (TranscriptionPolicy, error)

ParseTranscriptionPolicy validates a transcription policy string.

Jump to

Keyboard shortcuts

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