yt_transcript

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2023 License: MIT Imports: 11 Imported by: 2

README

YT Transcript

This is a Go package for retrieving the transcript of a YouTube video. It provides a simple interface for fetching the transcript of a video by its ID.

Installation

You can install the package using Go modules:


go get github.com/chand1012/yt_transcript

Usage

Here is an example of how to use the package to fetch the transcript of a video:


package main

import (
    "fmt"
    "github.com/chand1012/yt_transcript"
)

func main() {
    videoURL := "https://youtu.be/wqbeCG-Y3Xk"
    videoId, err := yt_transcript.GetVideoId(videoURL)
    if err != nil {
        panic(err)
    }
	  transcripts, title, err := yt_transcript.FetchTranscript(videoId, "en", "US")
    if err != nil {
        fmt.Println(err)
    } else {
        fmt.Printf("Title: %s\n", title)
        for _, t := range transcript {
            fmt.Printf("[%d:%d] %s\n", t.Offset/1000, (t.Offset+t.Duration)/1000, t.Text)
        }
    }
}

The FetchTranscript method takes a YouTube video ID and a TranscriptConfig object as arguments. The TranscriptConfig object specifies the language and country of the transcript.

The method returns a slice of TranscriptResponse objects, which contain the text of each caption, along with the start time and duration of the caption. It also returns the title of the video.

License

This package is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetVideoID

func GetVideoID(url string) (string, error)

Gets the ID of a video given a URL

func GetVideoTitle

func GetVideoTitle(videoId string) (string, error)

Gets the title of a video given its ID

Types

type TranscriptResponse

type TranscriptResponse struct {
	Text     string
	Duration int
	Offset   int
}

func FetchTranscript

func FetchTranscript(videoID, lang, country string) ([]TranscriptResponse, string, error)

FetchTranscript fetches the transcript for a given video ID

type YoutubeTranscriptError

type YoutubeTranscriptError struct {
	Message string
}

func (*YoutubeTranscriptError) Error

func (e *YoutubeTranscriptError) Error() string

Jump to

Keyboard shortcuts

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