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 | |
parent | e0da6a5205169f34671addd533739b6242d5eff3 (diff) |
Automatically select nth search result with --auto-select flag
Diffstat (limited to 'mal')
-rw-r--r-- | mal/mal.go | 1 | ||||
-rw-r--r-- | mal/search.go | 16 |
2 files changed, 15 insertions, 2 deletions
@@ -39,6 +39,7 @@ var ( SearchLength, SearchOffset int SearchNSFW bool + AutoSel int ) // init() would kill the program prematurely on `macli login` command 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) |