To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit a3d8e2ca authored by Christof Gerber's avatar Christof Gerber
Browse files

Handle playlists with more than 50 videos. Handle youtube-dl private video error.

parent 1c0daf49
Pipeline #51828 failed with stages
in 60 minutes and 2 seconds
......@@ -12,6 +12,8 @@ require (
gitlab.ethz.ch/chgerber/monitor v0.0.0-20190527191251-2bb9dd731340
go.mongodb.org/mongo-driver v1.1.3
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d // indirect
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a // indirect
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e // indirect
golang.org/x/tools v0.0.0-20191204011308-9611592c72f6 // indirect
google.golang.org/api v0.14.0
)
......@@ -313,6 +313,8 @@ golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 h1:e6HwijUxhDe+hPNjZQQn9bA5PW3vNmnN64U2ZW759Lk=
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a h1:+HHJiFUXVOIS9mr1ThqkQD1N8vpFCfCShqADBM12KTc=
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
......@@ -364,6 +366,8 @@ golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 h1:ZBzSG/7F4eNKz2L3GE9o300RX0Az1Bw5HF7PDraD+qU=
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e h1:9vRrk9YW2BTzLP0VCB9ZDjU4cPqkg+IDWL7XgxA1yxQ=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
......@@ -400,6 +404,8 @@ golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d h1:/iIZNFGxc/a7C3yWjGcnboV+Tkc7mxr+p6fDztwoxuM=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191204011308-9611592c72f6 h1:BP62y4oUl8+/CvHuvVqHIPmVRixgDl6y6a+tR7pXXIA=
golang.org/x/tools v0.0.0-20191204011308-9611592c72f6/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk=
......
......@@ -82,6 +82,13 @@ func (e ErrYoutubeVideoUnavailable) Error() string {
return string(e)
}
// ErrYoutubePrivateVideo is thrown when video is private
type ErrYoutubePrivateVideo string
func (e ErrYoutubePrivateVideo) Error() string {
return string(e)
}
// ErrYoutubeDL are errors with related to the youtubedl pkg
type ErrYoutubeDL string
......@@ -97,6 +104,10 @@ func runYoutubeDL(args []string) (output []byte, err error) {
if err != nil && strings.Contains(string(output), "video is unavailable") {
return nil, ErrYoutubeVideoUnavailable(string(output))
}
if err != nil && strings.Contains(string(output), "video is private.") {
return nil, ErrYoutubePrivateVideo(string(output))
}
return output, err
}
......@@ -377,6 +388,22 @@ func GetPlaylistVideos(playListID string, apiKey string) (members []string, err
members = append(members, item.ContentDetails.VideoId)
}
// handle playlists with more than 50 videos
for nextPageToken := response.NextPageToken; nextPageToken != ""; {
call = call.PageToken(nextPageToken)
response, err := call.Do()
if err != nil {
return nil, err
}
for _, item := range response.Items {
members = append(members, item.ContentDetails.VideoId)
}
nextPageToken = response.NextPageToken
}
return members, nil
}
......
......@@ -34,6 +34,13 @@ func TestGetPlaylistVideos(t *testing.T) {
assert.Equal(t, 3, len(videos))
}
func TestGetPlaylistVideosLong(t *testing.T) {
assert.Equal(t, true, os.Getenv("YOUTUBE_DATA_API_KEY") != "")
videos, err := GetPlaylistVideos("PLyfE3pnEkrBMiCPLNDhft9hmeXK1wtkGF", os.Getenv("YOUTUBE_DATA_API_KEY"))
assert.Equal(t, nil, err)
assert.Equal(t, true, len(videos) > 50)
}
func TestGetYouTubeDownloadLink(t *testing.T) {
video, audio, err := GetVideoURL("OsFEV35tWsg")
assert.Equal(t, nil, err)
......@@ -135,7 +142,7 @@ func TestGetSubtitle(t *testing.T) {
func TestUnavailableVideo(t *testing.T) {
_, err := listSubs("vBc5vR5c_VE")
assert.IsType(t, ErrYoutubeVideoUnavailable(""), err)
assert.IsType(t, ErrYoutubePrivateVideo(""), err)
}
func TestYouTubeSRV3Loader(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment