diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-10-02 20:46:50 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-10-02 20:46:50 +0530 |
commit | 8fb49796e37d2bf955d8ffa521f6bcda4f36b766 (patch) | |
tree | e0728f19a33c2f8f71767472c10767548ce99e94 /mal/search.go | |
parent | e0da6a5205169f34671addd533739b6242d5eff3 (diff) |
Automatically select nth search result with --auto-select flag
Diffstat (limited to 'mal/search.go')
-rw-r--r-- | mal/search.go | 16 |
1 files changed, 14 insertions, 2 deletions
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) |