diff options
Diffstat (limited to 'mal')
-rw-r--r-- | mal/episodes.go | 22 | ||||
-rw-r--r-- | mal/mal.go | 6 | ||||
-rw-r--r-- | mal/search.go | 32 | ||||
-rw-r--r-- | mal/status.go | 16 |
4 files changed, 58 insertions, 18 deletions
diff --git a/mal/episodes.go b/mal/episodes.go index 30fc5d2..255f8b0 100644 --- a/mal/episodes.go +++ b/mal/episodes.go @@ -19,30 +19,40 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. package mal import ( - "log" + "fmt" + "os" "strconv" ) func SetEpisodes(animeId int, ep string) { epValue, err := strconv.Atoi(ep) if err != nil { - log.Fatal("Error while parsing episode input", err) + fmt.Println("Error while parsing episode input", err) + os.Exit(1) } sign := ep[0:1] if sign == "+" || sign == "-" { - log.Printf("Cannot increment/decrement watched episodes by %d\n. Currently that doesn't wokr", epValue) - return + fmt.Printf("Cannot increment/decrement watched episodes by %d\n. Currently that doesn't wokr", epValue) + os.Exit(2) } userAnimeClient.SetWatchedEpisodes(animeId, epValue) } + func SetChapters(mangaId int, ch string) { chValue, err := strconv.Atoi(ch) if err != nil { - log.Fatal("Error while parsing chapter input", err) + fmt.Println("Error while parsing chapter input", err) + os.Exit(1) + } + + sign := ch[0:1] + if sign == "+" || sign == "-" { + fmt.Printf("Cannot increment/decrement read chapters by %d\n. Currently that doesn't wokr", chValue) + os.Exit(2) } - log.Printf("peeepee%s%d", ch[0:1], chValue) + userMangaClient.SetChaptersRead(mangaId, chValue) } @@ -23,11 +23,15 @@ import ( "os" a "github.com/MikunoNaka/MAL2Go/anime" + m "github.com/MikunoNaka/MAL2Go/manga" ua "github.com/MikunoNaka/MAL2Go/user/anime" + um "github.com/MikunoNaka/MAL2Go/user/manga" ) var animeClient a.Client +var mangaClient m.Client var userAnimeClient ua.Client +var userMangaClient um.Client func init() { // TODO: don't load access token from .env @@ -35,5 +39,7 @@ func init() { // initialise MAL2Go Client(s) animeClient.AuthToken = "Bearer " + accessToken + mangaClient.AuthToken = "Bearer " + accessToken userAnimeClient.AuthToken = "Bearer " + accessToken + userMangaClient.AuthToken = "Bearer " + accessToken } diff --git a/mal/search.go b/mal/search.go index 2968611..703cdb4 100644 --- a/mal/search.go +++ b/mal/search.go @@ -19,24 +19,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. package mal import ( - "log" + "fmt" + "os" a "github.com/MikunoNaka/MAL2Go/anime" + m "github.com/MikunoNaka/MAL2Go/manga" ) -func SearchAnime(searchString string, extraFields []string) []a.Anime { - // TODO: load limit, offset and (maybe) fields from config +func SearchAnime(searchString string) []a.Anime { + // TODO: read limit, offset from flags limit, offset := 10, 0 - - fields := []string{"title", "id"} - for _, i := range extraFields { - fields = append(fields, i) - } + fields := []string{"title", "id", "my_list_status"} res, err := animeClient.SearchAnime(searchString, limit, offset, fields) if err != nil { - log.Println(err) - return []a.Anime{} + fmt.Println("MyAnimeList reported error while searching:", err.Error()) + os.Exit(1) } return res.Animes } + +func SearchManga(searchString string) []m.Manga { + // TODO: read limit, offset from flags + limit, offset := 10, 0 + fields := []string{"title", "id", "my_list_status"} + + res, err := mangaClient.SearchManga(searchString, limit, offset, fields) + if err != nil { + fmt.Println("MyAnimeList reported error while searching:", err.Error()) + os.Exit(1) + } + + return res.Mangas +} diff --git a/mal/status.go b/mal/status.go index 422a838..1e11106 100644 --- a/mal/status.go +++ b/mal/status.go @@ -23,14 +23,26 @@ import ( "os" ) -func SetStatus(animeId int, status string) { +func SetAnimeStatus(animeId int, status string) { resp, err := userAnimeClient.SetStatus(animeId, status) if err != nil { fmt.Println("Error while parsing status:", err.Error()) os.Exit(1) } if resp.Error != "" { - fmt.Println("MyAnimeList reported error on SetStatus", resp.Error, resp.Message) + fmt.Println("MyAnimeList reported error on setting anime status", resp.Error, resp.Message) + os.Exit(1) + } +} + +func SetMangaStatus(mangaId int, status string) { + resp, err := userMangaClient.SetStatus(mangaId, status) + if err != nil { + fmt.Println("Error while parsing status:", err.Error()) + os.Exit(1) + } + if resp.Error != "" { + fmt.Println("MyAnimeList reported error on setting manga status", resp.Error, resp.Message) os.Exit(1) } } |