wader / goutubedl

Go wrapper for youtube-dl and yt-dlp

Home Page:https://pkg.go.dev/github.com/wader/goutubedl?tab=doc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

goutubedl

Go wrapper for youtube-dl and yt-dlp. Currently only tested and developed using yt-dlp. API documentation can be found at godoc.org.

See yt-dlp documentation for how to install and what is recommended to install in addition to yt-dl.

goutubedl default uses PATH to find youtube-dl or yt-dlp (in that order) but can be configured with the goutubedl.Path variable.

Due to the nature of and frequent updates of yt-dl only the latest version is tested. But it seems to work well with older versions also.

Usage

From cmd/example/main.go

package main

import (
	"context"
	"io"
	"log"
	"os"

	"github.com/wader/goutubedl"
)

func main() {
	result, err := goutubedl.New(context.Background(), "https://www.youtube.com/watch?v=jgVhBThJdXc", goutubedl.Options{})
	if err != nil {
		log.Fatal(err)
	}
	downloadResult, err := result.Download(context.Background(), "best")
	if err != nil {
		log.Fatal(err)
	}
	defer downloadResult.Close()
	f, err := os.Create("output")
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	io.Copy(f, downloadResult)
}

See goutubedl cmd tool or ydls for usage examples.

Development

docker build --target dev -t goutubedl-dev .
docker run --rm -ti -v "$PWD:$PWD" -w "$PWD" goutubedl-dev
go test -v -race -cover

About

Go wrapper for youtube-dl and yt-dlp

https://pkg.go.dev/github.com/wader/goutubedl?tab=doc

License:MIT License


Languages

Language:Go 98.0%Language:Dockerfile 2.0%