ytt

package module
v0.0.0-...-664221d Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 8 Imported by: 1

README

ytt

Go Reference

Fetch YouTube transcripts. Adapted from youtube-transcript-api.

Install
go install github.com/deepakjois/ytt/cmd/ytt@latest

Make sure $HOME/go/bin is in path.

Usage
$ ytt -h
ytt <youtube_url>
  -lang string
        Language code for the desired transcript (default "en")
  -no-timestamps
        Don't print timestamps
  -o string
        Output filename (defaults to stdout)
Library
import "github.com/deepakjois/ytt"

For detailed API documentation, visit pkg.go.dev.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCharactersInVideoID = errors.New("invalid characters in video id")
	ErrVideoIDMinLength           = errors.New("the video id must be at least 10 characters long")
	ErrTranscriptsDisabled        = errors.New("transcripts disabled")
	ErrTranscriptsUnavailable     = errors.New("transcripts disabled or video unavailable")
	ErrNoTranscriptFound          = errors.New("no transcript found for the given language codes")
	ErrInvalidFormat              = errors.New("invalid captions tracks format")
)

Functions

func ExtractVideoID

func ExtractVideoID(videoID string) (string, error)

ExtractVideoID extracts the videoID from the given string for a YouTube URL.

Types

type Transcript

type Transcript struct {
	VideoID      string
	URL          string
	Language     string
	LanguageCode string
	IsGenerated  bool
}

Transcript represents a transcript for a YouTube video.

func (*Transcript) Fetch

func (t *Transcript) Fetch() ([]TranscriptEntry, error)

Fetch fetches the transcript from the transcript URL.

type TranscriptEntry

type TranscriptEntry struct {
	Text     string  `xml:",chardata"`
	Start    float64 `xml:"start,attr"`
	Duration float64 `xml:"dur,attr"`
}

TranscriptEntry represents a transcript entry for a YouTube video.

type TranscriptList

type TranscriptList struct {
	VideoID                    string
	ManuallyCreatedTranscripts map[string]*Transcript
	GeneratedTranscripts       map[string]*Transcript
}

TranscriptList represents a list of transcripts for a YouTube video.

func ListTranscripts

func ListTranscripts(videoID string) (*TranscriptList, error)

ListTranscripts lists the transcripts for the given videoID.

func (*TranscriptList) FindTranscript

func (tl *TranscriptList) FindTranscript(languageCodes ...string) (*Transcript, error)

FindTranscript finds the first transcript that matches the language codes.

Directories

Path Synopsis
cmd
ytt

Jump to

Keyboard shortcuts

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