-
Notifications
You must be signed in to change notification settings - Fork 1
/
ydl_test.go
92 lines (78 loc) · 2.19 KB
/
ydl_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
82
83
84
85
86
87
88
89
90
91
92
package ydl
import (
"strings"
"testing"
"time"
)
func TestBoolOption(t *testing.T) {
youtubeDl := NewYdl()
youtubeDl.Options.ExtractAudio.Value = true
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "-x") {
t.Fail()
}
}
func TestTimeOption(t *testing.T) {
youtubeDl := NewYdl()
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 := NewYdl()
youtubeDl.Options.BufferSize.Value = FileSizeRateFromString("5.5M")
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "--buffer-size 5.5M") {
t.Fail()
}
}
func TestFileSizeRateOption2(t *testing.T) {
youtubeDl := NewYdl()
youtubeDl.Options.BufferSize.Value = FileSizeRateFromValues(5.5, 'M')
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "--buffer-size 5.5M") {
t.Fail()
}
}
func TestIntOption(t *testing.T) {
youtubeDl := NewYdl()
youtubeDl.Options.SocketTimeout.Value = 5
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "--socket-timeout 5") {
t.Fail()
}
}
func TestIntOptionNegativeIsInfinite(t *testing.T) {
youtubeDl := NewYdl()
youtubeDl.Options.Retries.Value = -1
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "-R infinite") {
t.Fail()
}
}
func TestStringOption(t *testing.T) {
youtubeDl := NewYdl()
youtubeDl.Options.Username.Value = "testUser"
if !strings.Contains(youtubeDl.Options.OptionsToCliParameters(), "-u testUser") {
t.Fail()
}
}
func TestDownloadInfo(t *testing.T) {
youtubeDl := NewYdl()
info, err := youtubeDl.FetchInfo("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
if err != nil {
t.Error(err)
}
exp := "Rick Astley - Never Gonna Give You Up (Official Music Video)"
if info.Title != exp {
t.Errorf("Expected '%s', got '%s'", exp, info.Title)
}
}
/*
func TestDownload(t *testing.T) {
youtubeDl := NewYdl()
ch, err := youtubeDl.Download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
if err != nil {
t.Error(err)
}
for p := range ch {
fmt.Printf("%f%%, %d bytes, %d rate, %s eta\n", p.Percentage, p.Total, p.Rate, p.ETA)
}
}
*/