From 83a39dbebed42b9bd779d86b4fcf30a0f5348d87 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Wed, 6 Jul 2022 23:23:01 +0530 Subject: added manga and nsfw results in list command --- cmd/list.go | 8 ++++-- go.mod | 2 +- go.sum | 4 +-- mal/list.go | 4 +-- ui/animelist.go | 54 ------------------------------------- ui/list.go | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 95 insertions(+), 61 deletions(-) delete mode 100644 ui/animelist.go create mode 100644 ui/list.go diff --git a/cmd/list.go b/cmd/list.go index f0e4327..b9c82d9 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -66,8 +66,11 @@ var listCmd = &cobra.Command{ os.Exit(1) } - - ui.AnimeList(mal.AnimeList(user, status, sort, nsfw)) + if mangaMode { + ui.MangaList(mal.MangaList(user, status, sort, nsfw)) + } else { + ui.AnimeList(mal.AnimeList(user, status, sort, nsfw)) + } }, } @@ -78,4 +81,5 @@ func init() { listCmd.Flags().StringP("user", "", "@me", "User (@me or blank for self)") listCmd.Flags().StringP("sort", "", "list_score", "Sort the list") listCmd.Flags().BoolP("include-nsfw", "", false, "Include NSFW results") + listCmd.Flags().BoolVarP(&mangaMode, "manga", "m", false, "Use manga mode") } diff --git a/go.mod b/go.mod index 406df62..1811c55 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/MikunoNaka/macli go 1.18 require ( - github.com/MikunoNaka/MAL2Go/v4 v4.0.0 + github.com/MikunoNaka/MAL2Go/v4 v4.0.1 github.com/jedib0t/go-pretty/v6 v6.3.3 github.com/manifoldco/promptui v0.9.0 github.com/spf13/cobra v1.4.0 diff --git a/go.sum b/go.sum index 5779077..e44aa18 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/MikunoNaka/MAL2Go/v4 v4.0.0 h1:8T/JCs7vu5pANSCPCK1ab03LLDX6HLqypGB88MmeYnE= -github.com/MikunoNaka/MAL2Go/v4 v4.0.0/go.mod h1:SMOngKqH871nz/jWDUSD3t09ArGsPMrFH6l//diIhgw= +github.com/MikunoNaka/MAL2Go/v4 v4.0.1 h1:53XINjSE+V2UtKyddsFDOIySHREbkZsU9srRA98ONqU= +github.com/MikunoNaka/MAL2Go/v4 v4.0.1/go.mod h1:SMOngKqH871nz/jWDUSD3t09ArGsPMrFH6l//diIhgw= github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE= diff --git a/mal/list.go b/mal/list.go index ec0c634..82b4938 100644 --- a/mal/list.go +++ b/mal/list.go @@ -27,7 +27,7 @@ import ( // TODO: return all the list items using loop func AnimeList(user, status, sort string, nsfw bool) []a.Anime { - res, _, err := userAnimeClient.GetAnimeList(user, status, sort, 1000, 0, nsfw, []string{"title", "list_status", "num_episodes", "media_type"}) + res, _, err := userAnimeClient.GetAnimeList(user, status, sort, 1000, 0, nsfw, []string{"title", "num_episodes", "media_type"}) if err != nil { fmt.Println(err) os.Exit(1) @@ -37,7 +37,7 @@ func AnimeList(user, status, sort string, nsfw bool) []a.Anime { // TODO: return all the list items using loop func MangaList(user, status, sort string, nsfw bool) []m.Manga { - res, _, err := userMangaClient.GetMangaList(user, status, sort, 1000, 0, nsfw, []string{"title", "my_list_status", "num_chapters"}) + res, _, err := userMangaClient.GetMangaList(user, status, sort, 1000, 0, nsfw, []string{"title", "num_chapters", "num_volumes", "media_type"}) if err != nil { fmt.Println(err) os.Exit(1) diff --git a/ui/animelist.go b/ui/animelist.go deleted file mode 100644 index c256666..0000000 --- a/ui/animelist.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -macli - Unofficial CLI-Based MyAnimeList Client -Copyright © 2022 Vidhu Kant Sharma - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -package ui - -import ( - a "github.com/MikunoNaka/MAL2Go/v4/anime" - "github.com/jedib0t/go-pretty/v6/table" - "fmt" - "os" -) - -func AnimeList(animes []a.Anime) { - t := table.NewWriter() - t.SetOutputMirror(os.Stdout) - - t.AppendHeader(table.Row{"#", "Title", "ID", "Score", "Type", "Status", "Progress"}) - - for index, anime := range animes { - status := anime.ListStatus.Status - score := anime.ListStatus.Score - - formattedStatus := GetColorCodeByStatus(status) + FormatStatus(status) + "\x1b[0m" - formattedScore := FormatScore(score) - - // TODO: format it - formattedMediaType := anime.MediaType - - progress := fmt.Sprintf("%d/%d", anime.ListStatus.EpWatched, anime.NumEpisodes) - - t.AppendRow([]interface{}{ - index + 1, anime.Title, anime.Id, formattedScore, formattedMediaType, formattedStatus, progress, - }) - } - - t.AppendSeparator() - t.AppendFooter(table.Row{len(animes), "", "", ""}) - t.Render() -} diff --git a/ui/list.go b/ui/list.go new file mode 100644 index 0000000..f1eb10e --- /dev/null +++ b/ui/list.go @@ -0,0 +1,84 @@ +/* +macli - Unofficial CLI-Based MyAnimeList Client +Copyright © 2022 Vidhu Kant Sharma + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package ui + +import ( + a "github.com/MikunoNaka/MAL2Go/v4/anime" + m "github.com/MikunoNaka/MAL2Go/v4/manga" + "github.com/jedib0t/go-pretty/v6/table" + "fmt" + "os" +) + +func AnimeList(animes []a.Anime) { + t := table.NewWriter() + t.SetOutputMirror(os.Stdout) + + t.AppendHeader(table.Row{"#", "Title", "ID", "Score", "Type", "Status", "Progress"}) + + for index, anime := range animes { + status := anime.ListStatus.Status + score := anime.ListStatus.Score + + formattedStatus := GetColorCodeByStatus(status) + FormatStatus(status) + "\x1b[0m" + formattedScore := FormatScore(score) + + // TODO: format it + formattedMediaType := anime.MediaType + + progress := fmt.Sprintf("%d/%d", anime.ListStatus.EpWatched, anime.NumEpisodes) + + t.AppendRow([]interface{}{ + index + 1, anime.Title, anime.Id, formattedScore, formattedMediaType, formattedStatus, progress, + }) + } + + t.AppendSeparator() + t.AppendFooter(table.Row{len(animes), "", "", ""}) + t.Render() +} + +func MangaList(mangas []m.Manga) { + t := table.NewWriter() + t.SetOutputMirror(os.Stdout) + + t.AppendHeader(table.Row{"#", "Title", "ID", "Score", "Type", "Status", "Chapters", "Volumes"}) + + for index, manga := range mangas { + status := manga.ListStatus.Status + score := manga.ListStatus.Score + + formattedStatus := GetColorCodeByStatus(status) + FormatStatus(status) + "\x1b[0m" + formattedScore := FormatScore(score) + + // TODO: format it + formattedMediaType := manga.MediaType + + chapterProgress := fmt.Sprintf("%d/%d", manga.ListStatus.ChaptersRead, manga.NumChapters) + volumeProgress := fmt.Sprintf("%d/%d", manga.ListStatus.VolumesRead, manga.NumVolumes) + + t.AppendRow([]interface{}{ + index + 1, manga.Title, manga.Id, formattedScore, formattedMediaType, formattedStatus, chapterProgress, volumeProgress, + }) + } + + t.AppendSeparator() + t.AppendFooter(table.Row{len(mangas), "", "", ""}) + t.Render() +} -- cgit v1.2.3