This commit is contained in:
2018-11-04 15:58:15 +01:00
commit f956bcee28
1178 changed files with 584552 additions and 0 deletions

BIN
youtube/test.mp4 Normal file

Binary file not shown.

32
youtube/youtube.go Normal file
View File

@ -0,0 +1,32 @@
package youtube
import (
"github.com/rylio/ytdl"
"os"
)
func Get(url string) (string, error) {
v, err := ytdl.GetVideoInfo(url)
if err != nil {
return "", err
}
u, err := v.GetDownloadURL(v.Formats.Best(ytdl.FormatResolutionKey)[0])
if err != nil {
return "", err
}
return u.String(), nil
}
func Download(url string, file string) error {
v, err := ytdl.GetVideoInfo(url)
if err != nil {
return err
}
format := v.Formats.Best(ytdl.FormatResolutionKey)[0]
f, err := os.Create(file)
if err != nil {
return err
}
defer f.Close()
return v.Download(format, f)
}

19
youtube/youtube_test.go Normal file
View File

@ -0,0 +1,19 @@
package youtube
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestGet(t *testing.T) {
u, err := Get("https://www.youtube.com/watch?v=1rZ-JorHJEY")
assert.NoError(t, err)
assert.NotEmpty(t, u)
fmt.Println(u)
}
func TestDownload(t *testing.T) {
err := Download("https://www.youtube.com/watch?v=1rZ-JorHJEY", "test.mp4")
assert.NoError(t, err)
}