From 8fb49796e37d2bf955d8ffa521f6bcda4f36b766 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 2 Oct 2022 20:46:50 +0530 Subject: Automatically select nth search result with --auto-select flag --- mal/search.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'mal/search.go') diff --git a/mal/search.go b/mal/search.go index 1bad114..e6e416a 100644 --- a/mal/search.go +++ b/mal/search.go @@ -28,7 +28,13 @@ import ( func SearchAnime(searchString string, fields []string) []a.Anime { fields = append([]string{"title", "id"}, fields...) - res, err := animeClient.SearchAnime(searchString, SearchLength, SearchOffset, SearchNSFW, fields) + searchLength, searchOffset := SearchLength, SearchOffset + if AutoSel > 0 { + searchLength = 1 + searchOffset = AutoSel - 1 + } + + res, err := animeClient.SearchAnime(searchString, searchLength, searchOffset, SearchNSFW, fields) if err != nil { fmt.Println("MyAnimeList reported error while searching:", err.Error()) os.Exit(1) @@ -40,7 +46,13 @@ func SearchAnime(searchString string, fields []string) []a.Anime { func SearchManga(searchString string, fields []string) []m.Manga { fields = append([]string{"title", "id"}, fields...) - res, err := mangaClient.SearchManga(searchString, SearchLength, SearchOffset, SearchNSFW, fields) + searchLength, searchOffset := SearchLength, SearchOffset + if AutoSel > 0 { + searchLength = 1 + searchOffset = AutoSel - 1 + } + + res, err := mangaClient.SearchManga(searchString, searchLength, searchOffset, SearchNSFW, fields) if err != nil { fmt.Println("MyAnimeList reported error while searching:", err.Error()) os.Exit(1) -- cgit v1.2.3