Documentation
¶
Overview ¶
Package youtube provides YouTube video transcript and comment extraction functionality.
Requirements: - yt-dlp: Required for transcript extraction (must be installed separately) - ffmpeg and tesseract: Required, with yt-dlp, for visual extraction - YouTube API key: Optional, only needed for comments, metadata, duration, and playlists
The implementation uses yt-dlp for transcript extraction and the YouTube API for comments/metadata.
Index ¶
- Constants
- type Options
- type VideoInfo
- type VideoMeta
- type VideoMetadata
- type YouTube
- func (o *YouTube) FetchAndPrintPlaylist(playlistID string) (err error)
- func (o *YouTube) FetchAndSavePlaylist(playlistID, filename string) (err error)
- func (o *YouTube) FetchPlaylistVideos(playlistID string) (ret []*VideoMeta, err error)
- func (o *YouTube) GetVideoOrPlaylistId(url string) (videoId string, playlistId string, err error)
- func (o *YouTube) Grab(url string, options *Options) (ret *VideoInfo, err error)
- func (o *YouTube) GrabByFlags() (ret *VideoInfo, err error)
- func (o *YouTube) GrabComments(videoId string) (ret []string, err error)
- func (o *YouTube) GrabDuration(videoId string) (ret int, err error)
- func (o *YouTube) GrabDurationForUrl(url string) (ret int, err error)
- func (o *YouTube) GrabMetadata(videoId string) (metadata *VideoMetadata, err error)
- func (o *YouTube) GrabTranscript(videoId string, language string) (ret string, err error)
- func (o *YouTube) GrabTranscriptForUrl(url string, language string) (ret string, err error)
- func (o *YouTube) GrabTranscriptWithArgs(videoId string, language string, additionalArgs string) (ret string, err error)
- func (o *YouTube) GrabTranscriptWithTimestamps(videoId string, language string) (ret string, err error)
- func (o *YouTube) GrabTranscriptWithTimestampsWithArgs(videoId string, language string, additionalArgs string) (ret string, err error)
- func (o *YouTube) GrabVisual(videoId string, language string, additionalArgs string, sensitivity float64, ...) (string, error)
- func (o *YouTube) SaveVideosToCSV(filename string, videos []*VideoMeta) (err error)
Constants ¶
const TimeGapForRepeats = 10 // seconds
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type VideoInfo ¶
type VideoInfo struct {
Transcript string `json:"transcript"`
VisualText string `json:"visualText,omitempty"`
Duration int `json:"duration"`
Comments []string `json:"comments"`
Metadata *VideoMetadata `json:"metadata,omitempty"`
}
type VideoMetadata ¶
type VideoMetadata struct {
Id string `json:"id"`
Title string `json:"title"`
Description string `json:"description"`
PublishedAt string `json:"publishedAt"`
ChannelId string `json:"channelId"`
ChannelTitle string `json:"channelTitle"`
CategoryId string `json:"categoryId"`
Tags []string `json:"tags"`
ViewCount uint64 `json:"viewCount"`
LikeCount uint64 `json:"likeCount"`
}
type YouTube ¶
type YouTube struct {
*plugins.PluginBase
ApiKey *plugins.SetupQuestion
// YtDlpArgs holds the yt-dlp arguments from the --yt-dlp-args flag or the
// config file. GrabTranscript and GrabTranscriptWithTimestamps use them.
YtDlpArgs string
// contains filtered or unexported fields
}
func NewYouTube ¶
func NewYouTube() (ret *YouTube)
func (*YouTube) FetchAndPrintPlaylist ¶
func (*YouTube) FetchAndSavePlaylist ¶
FetchAndSavePlaylist fetches all videos in a playlist and saves them to a CSV file.
func (*YouTube) FetchPlaylistVideos ¶
FetchPlaylistVideos fetches all videos from a YouTube playlist.
func (*YouTube) GetVideoOrPlaylistId ¶
func (*YouTube) GrabByFlags ¶
func (*YouTube) GrabComments ¶
func (*YouTube) GrabDurationForUrl ¶
func (*YouTube) GrabMetadata ¶
func (o *YouTube) GrabMetadata(videoId string) (metadata *VideoMetadata, err error)
func (*YouTube) GrabTranscript ¶
GrabTranscript retrieves the transcript for the specified video ID using yt-dlp and the arguments in the YtDlpArgs field. The language parameter specifies the preferred subtitle language code (e.g., "en", "es"). It returns the transcript text or an error if the transcript cannot be retrieved.
func (*YouTube) GrabTranscriptForUrl ¶
func (*YouTube) GrabTranscriptWithArgs ¶ added in v1.4.278
func (o *YouTube) GrabTranscriptWithArgs(videoId string, language string, additionalArgs string) (ret string, err error)
GrabTranscriptWithArgs retrieves the transcript for the specified video ID using yt-dlp with custom command-line arguments. The language parameter specifies the preferred subtitle language code. The additionalArgs parameter allows passing extra yt-dlp options like "--cookies-from-browser brave" for authentication. It returns the transcript text or an error if the transcript cannot be retrieved.
func (*YouTube) GrabTranscriptWithTimestamps ¶
func (o *YouTube) GrabTranscriptWithTimestamps(videoId string, language string) (ret string, err error)
GrabTranscriptWithTimestamps retrieves the transcript with timestamps for the specified video ID using yt-dlp and the arguments in the YtDlpArgs field. The language parameter specifies the preferred subtitle language code. Each line in the returned transcript is prefixed with a timestamp in [HH:MM:SS] format. It returns the timestamped transcript text or an error if the transcript cannot be retrieved.
func (*YouTube) GrabTranscriptWithTimestampsWithArgs ¶ added in v1.4.278
func (o *YouTube) GrabTranscriptWithTimestampsWithArgs(videoId string, language string, additionalArgs string) (ret string, err error)
GrabTranscriptWithTimestampsWithArgs retrieves the transcript with timestamps for the specified video ID using yt-dlp with custom command-line arguments. The language parameter specifies the preferred subtitle language code. The additionalArgs parameter allows passing extra yt-dlp options. Each line in the returned transcript is prefixed with a timestamp in [HH:MM:SS] format. It returns the timestamped transcript text or an error if the transcript cannot be retrieved.