forked from kkdai/youtube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_test.go
108 lines (99 loc) · 2.33 KB
/
video_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package youtube
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestDownload_Regular(t *testing.T) {
testcases := []struct {
name string
url string
outputFile string
itagNo int
quality string
}{
{
// Video from issue #25
name: "default",
url: "https://www.youtube.com/watch?v=54e6lBE3BoQ",
outputFile: "default_test.mp4",
quality: "",
},
{
// Video from issue #25
name: "quality:medium",
url: "https://www.youtube.com/watch?v=54e6lBE3BoQ",
outputFile: "medium_test.mp4",
quality: "medium",
},
{
name: "without-filename",
url: "https://www.youtube.com/watch?v=n3kPvBCYT3E",
},
{
name: "Format",
url: "https://www.youtube.com/watch?v=54e6lBE3BoQ",
outputFile: "muxedstream_test.mp4",
itagNo: 18,
},
{
name: "AdaptiveFormat_video",
url: "https://www.youtube.com/watch?v=54e6lBE3BoQ",
outputFile: "adaptiveStream_video_test.m4v",
itagNo: 134,
},
{
name: "AdaptiveFormat_audio",
url: "https://www.youtube.com/watch?v=54e6lBE3BoQ",
outputFile: "adaptiveStream_audio_test.m4a",
itagNo: 140,
},
{
// Video from issue #138
name: "NotPlayableInEmbed",
url: "https://www.youtube.com/watch?v=gr-IqFcNExY",
outputFile: "not_playable_in_embed.mp4",
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
require := require.New(t)
video, err := testClient.GetVideo(tc.url)
require.NoError(err)
var format *Format
if tc.itagNo > 0 {
format = video.Formats.FindByItag(tc.itagNo)
require.NotNil(format)
} else {
format = &video.Formats[0]
}
url, err := testClient.GetStreamURL(video, format)
require.NoError(err)
require.NotEmpty(url)
})
}
}
func TestDownload_WhenPlayabilityStatusIsNotOK(t *testing.T) {
testcases := []struct {
issue string
videoID string
err string
}{
{
issue: "issue#65",
videoID: "9ja-K2FslBU",
err: `status: ERROR`,
},
{
issue: "issue#59",
videoID: "nINQjT7Zr9w",
err: `status: LOGIN_REQUIRED`,
},
}
for _, tc := range testcases {
t.Run(tc.issue, func(t *testing.T) {
_, err := testClient.GetVideo(tc.videoID)
require.Error(t, err)
require.Contains(t, err.Error(), tc.err)
})
}
}