diff --git a/downloader/downloader.go b/downloader/downloader.go index 43a7b06..f63ba4b 100644 --- a/downloader/downloader.go +++ b/downloader/downloader.go @@ -9,9 +9,20 @@ import ( "github.com/sirupsen/logrus" ) -func GetPlaylistVideoIDs(channelName string) ([]string, error) { +func GetPlaylistVideoIDs(channelName string, maxVideos int) ([]string, error) { args := []string{"--skip-download", "https://www.youtube.com/channel/" + channelName, "--get-id", "--flat-playlist"} - return run(args) + ids, err := run(args) + if err != nil { + return nil, errors.Err(err) + } + videoIDs := make([]string, maxVideos) + for i, v := range ids { + if i >= maxVideos { + break + } + videoIDs[i] = v + } + return videoIDs, nil } func run(args []string) ([]string, error) { diff --git a/downloader/downloader_test.go b/downloader/downloader_test.go index 6a5b5de..26e2aaf 100644 --- a/downloader/downloader_test.go +++ b/downloader/downloader_test.go @@ -9,12 +9,11 @@ import ( func TestRun(t *testing.T) { //args := []string{"--skip-download", "https://www.youtube.com/c/Electroboom", "--get-id", "--flat-playlist"} //videoIDs, err := GetPlaylistVideoIDs("Electroboom") - videoIDs, err := GetPlaylistVideoIDs("UCJ0-OtVpF0wOKEqT2Z1HEtA") + videoIDs, err := GetPlaylistVideoIDs("UCJ0-OtVpF0wOKEqT2Z1HEtA", 50) if err != nil { logrus.Error(err) } for _, id := range videoIDs { println(id) } - t.Error("just stop") } diff --git a/ytapi/ytapi.go b/ytapi/ytapi.go index 093fd80..a846b02 100644 --- a/ytapi/ytapi.go +++ b/ytapi/ytapi.go @@ -52,7 +52,10 @@ var mostRecentlyFailedChannel string // TODO: fix this hack! func GetVideosToSync(apiKey, channelID string, syncedVideos map[string]sdk.SyncedVideo, quickSync bool, maxVideos int, videoParams VideoParams) ([]Video, error) { var videos []Video - videoIDs, err := downloader.GetPlaylistVideoIDs(channelID) + if quickSync { + maxVideos = 50 + } + videoIDs, err := downloader.GetPlaylistVideoIDs(channelID, maxVideos) if err != nil { return nil, errors.Err(err) }