forked from BrianAllred/goydl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoydl_test.go
81 lines (67 loc) · 1.99 KB
/
goydl_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package goydl_test
import (
"testing"
"strings"
"time"
"github.com/BrianAllred/goydl"
)
func TestBoolOption(t *testing.T) {
youtubeDl := goydl.NewYoutubeDl()
youtubeDl.Options.ExtractAudio.Value = true
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "-x") {
t.Fail()
}
}
func TestTimeOption(t *testing.T) {
youtubeDl := goydl.NewYoutubeDl()
youtubeDl.Options.Date.Value = time.Date(2016, time.March, 19, 0, 0, 0, 0, time.UTC)
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "--date 20160319") {
t.Fail()
}
}
func TestFileSizeRateOption1(t *testing.T) {
youtubeDl := goydl.NewYoutubeDl()
youtubeDl.Options.BufferSize.Value = goydl.FileSizeRateFromString("5.5M")
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "--buffer-size 5.5M") {
t.Fail()
}
}
func TestFileSizeRateOption2(t *testing.T) {
youtubeDl := goydl.NewYoutubeDl()
youtubeDl.Options.BufferSize.Value = goydl.FileSizeRateFromValues(5.5, 'M')
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "--buffer-size 5.5M") {
t.Fail()
}
}
func TestIntOption(t *testing.T) {
youtubeDl := goydl.NewYoutubeDl()
youtubeDl.Options.SocketTimeout.Value = 5
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "--socket-timeout 5") {
t.Fail()
}
}
func TestIntOptionNegativeIsInfinite(t *testing.T) {
youtubeDl := goydl.NewYoutubeDl()
youtubeDl.Options.Retries.Value = -1
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "-R infinite") {
t.Fail()
}
}
func TestStringOption(t *testing.T) {
youtubeDl := goydl.NewYoutubeDl()
youtubeDl.Options.Username.Value = "testUser"
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "-u testUser") {
t.Fail()
}
}
func TestDownloadInfo(t *testing.T) {
youtubeDl := goydl.NewYoutubeDl()
youtubeDl.VideoURL = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
info, err := youtubeDl.GetInfo()
if err != nil {
t.Fail()
}
if info.Title != "Rick Astley - Never Gonna Give You Up" {
t.Fail()
}
}