From d05521160ee28d428185574740b6cfaf46505946 Mon Sep 17 00:00:00 2001 From: arrow2nd <44780846+arrow2nd@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:51:30 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=93=A6=20=E4=BE=9D=E5=AD=98=E9=96=A2?= =?UTF-8?q?=E4=BF=82=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 8 ++++---- go.sum | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 8b46716..c3352cb 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.16.0 // indirect - github.com/google/uuid v1.4.0 // indirect + github.com/google/uuid v1.5.0 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -24,17 +24,17 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/soniakeys/quant v1.0.0 // indirect github.com/sosodev/duration v1.2.0 // indirect - golang.org/x/image v0.14.0 // indirect + golang.org/x/image v0.15.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) require ( - github.com/99designs/gqlgen v0.17.40 // indirect + github.com/99designs/gqlgen v0.17.43 // indirect github.com/Yamashou/gqlgenc v0.16.2 github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/spf13/pflag v1.0.5 - github.com/vektah/gqlparser/v2 v2.5.10 // indirect + github.com/vektah/gqlparser/v2 v2.5.11 // indirect golang.org/x/sync v0.6.0 ) diff --git a/go.sum b/go.sum index 768e1a7..3d5f7e3 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/99designs/gqlgen v0.17.40 h1:/l8JcEVQ93wqIfmH9VS1jsAkwm6eAF1NwQn3N+SDqBY= github.com/99designs/gqlgen v0.17.40/go.mod h1:b62q1USk82GYIVjC60h02YguAZLqYZtvWml8KkhJps4= +github.com/99designs/gqlgen v0.17.43 h1:I4SYg6ahjowErAQcHFVKy5EcWuwJ3+Xw9z2fLpuFCPo= +github.com/99designs/gqlgen v0.17.43/go.mod h1:lO0Zjy8MkZgBdv4T1U91x09r0e0WFOdhVUutlQs1Rsc= github.com/AlecAivazis/survey/v2 v2.3.7 h1:6I/u8FvytdGsgonrYsVn2t8t4QiRnh6QSTqkkhIiSjQ= github.com/AlecAivazis/survey/v2 v2.3.7/go.mod h1:xUTIdE4KCOIjsBAE1JYsUPoCqYdZ1reCfTwbto0Fduo= github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= @@ -24,6 +26,8 @@ github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4Nij github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= +github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog= github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= @@ -60,12 +64,16 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/vektah/gqlparser/v2 v2.5.10 h1:6zSM4azXC9u4Nxy5YmdmGu4uKamfwsdKTwp5zsEealU= github.com/vektah/gqlparser/v2 v2.5.10/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc= +github.com/vektah/gqlparser/v2 v2.5.11 h1:JJxLtXIoN7+3x6MBdtIP59TP1RANnY7pXOaDnADQSf8= +github.com/vektah/gqlparser/v2 v2.5.11/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= +golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= +golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= From 6557c8030bf54d90f9958a34592be8e9a38f2f62 Mon Sep 17 00:00:00 2001 From: arrow2nd <44780846+arrow2nd@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:03:27 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=91=8D=20=E6=9C=AA=E8=A6=96=E8=81=B4?= =?UTF-8?q?=E3=81=AE=E4=BD=9C=E5=93=81=E3=81=AE=E3=82=A8=E3=83=94=E3=82=BD?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=82=92=E8=A8=98=E9=8C=B2=E3=81=97=E3=81=9F?= =?UTF-8?q?=E9=9A=9B=E3=81=AB=E8=A6=96=E8=81=B4=E3=82=B9=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=82=B9=E3=82=82=E6=9B=B4=E6=96=B0=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/info.go | 4 ++-- cmd/record.go | 49 +++++++++++++++++++++++++++++++++++++++-------- cmdutil/search.go | 18 ++++++++--------- view/select.go | 10 +++++----- 4 files changed, 57 insertions(+), 24 deletions(-) diff --git a/cmd/info.go b/cmd/info.go index 6aa034f..db01cd6 100644 --- a/cmd/info.go +++ b/cmd/info.go @@ -20,13 +20,13 @@ func (c *Command) newCmdInfo() *cobra.Command { } func (c *Command) infoRun(cmd *cobra.Command, args []string) error { - annictID, _, err := cmdutil.SearchWorks(c.api, cmd, args) + work, _, err := cmdutil.SearchWorks(c.api, cmd, args) if err != nil { return err } spinner := view.SpinnerStart(cmd.OutOrStdout(), "Loading information the work") - info, err := c.api.FetchWorkInfo(annictID) + info, err := c.api.FetchWorkInfo(work.AnnictID) if err != nil { return err } diff --git a/cmd/record.go b/cmd/record.go index 64ca51b..db4d149 100644 --- a/cmd/record.go +++ b/cmd/record.go @@ -2,6 +2,7 @@ package cmd import ( "github.com/arrow2nd/anct/cmdutil" + "github.com/arrow2nd/anct/gen" "github.com/arrow2nd/anct/view" "github.com/spf13/cobra" ) @@ -25,7 +26,10 @@ func (c *Command) newCmdRecord() *cobra.Command { } func (c *Command) recordRun(cmd *cobra.Command, args []string) error { - episodeIDs := []string{} + var ( + work *gen.WorkFragment = nil + episodeIDs = []string{} + ) // 記録するエピソードを選択 if unwatch, _ := cmd.Flags().GetBool("unwatch"); unwatch { @@ -36,11 +40,12 @@ func (c *Command) recordRun(cmd *cobra.Command, args []string) error { episodeIDs = []string{id} } else { - ids, err := c.recordSelectEpisodes(cmd, args) + w, ids, err := c.recordSelectEpisodes(cmd, args) if err != nil { return err } + work = w episodeIDs = ids } @@ -80,22 +85,50 @@ func (c *Command) recordRun(cmd *cobra.Command, args []string) error { spinner.Stop() view.PrintDone(cmd.OutOrStdout(), "Recorded!") + // 初めての視聴でないならここで終了 + if work == nil || (work.ViewerStatusState != nil && *work.ViewerStatusState != gen.StatusStateNoState) { + return nil + } + + // 視聴ステータスの変更を確認 + changeStatus, err := view.Confirm("Change your viewing status to Watching?") + if err != nil { + return err + } + if !changeStatus { + view.PrintCanceled(cmd.ErrOrStderr()) + return nil + } + + spinner = view.SpinnerStart(cmd.OutOrStdout(), "Updating status") + if err := c.api.UpdateWorkState(work.ID, gen.StatusStateWatching); err != nil { + return err + } + + spinner.Stop() + view.PrintDone(cmd.OutOrStdout(), "Updated status!") + return nil } // recordSelectEpisodes : 検索結果から記録するエピソードを選択 -func (c *Command) recordSelectEpisodes(cmd *cobra.Command, args []string) ([]string, error) { - annictID, _, err := cmdutil.SearchWorks(c.api, cmd, args) +func (c *Command) recordSelectEpisodes(cmd *cobra.Command, args []string) (*gen.WorkFragment, []string, error) { + work, _, err := cmdutil.SearchWorks(c.api, cmd, args) + if err != nil { + return nil, nil, err + } + + episode, err := c.api.FetchWorkEpisodes(work.AnnictID) if err != nil { - return nil, err + return nil, nil, err } - work, err := c.api.FetchWorkEpisodes(annictID) + ids, err := view.SelectEpisodes(episode) if err != nil { - return nil, err + return nil, nil, err } - return view.SelectEpisodes(work) + return work, ids, nil } // recordSelectUnwatchEpisord : 未視聴のエピソードから選択 diff --git a/cmdutil/search.go b/cmdutil/search.go index c4a81df..8cf42ca 100644 --- a/cmdutil/search.go +++ b/cmdutil/search.go @@ -10,41 +10,41 @@ import ( ) // SearchWorks : 作品を検索してIDを取得 -func SearchWorks(api *api.API, cmd *cobra.Command, args []string) (int64, string, error) { +func SearchWorks(api *api.API, cmd *cobra.Command, args []string) (*gen.WorkFragment, string, error) { states, seasons, limit, useEditor, err := getAllSearchFlags(cmd.Flags()) if err != nil { - return 0, "", err + return nil, "", err } // 検索クエリ query, err := receiveQuery("Search query", args, useEditor) if err != nil { - return 0, "", err + return nil, "", err } query = StripWhiteSpace(query) // 条件指定が無い場合はエラー if query == "" && len(states) == 0 && len(seasons) == 0 { - return 0, "", errors.New("query or `--library` or `--seasons` is required") + return nil, "", errors.New("query or `--library` or `--seasons` is required") } spinner := view.SpinnerStart(cmd.OutOrStdout(), "Searching for works") - list := []*gen.WorkFragment{} + works := []*gen.WorkFragment{} err = nil // 作品を検索 if len(states) == 0 { - list, err = api.SearchWorks(query, seasons, limit) + works, err = api.SearchWorks(query, seasons, limit) } else { - list, err = api.SearchWorksFromLibrary(query, states, seasons, limit) + works, err = api.SearchWorksFromLibrary(query, states, seasons, limit) } spinner.Stop() if err != nil { - return 0, "", err + return nil, "", err } - return view.SelectWork(list) + return view.SelectWork(works) } diff --git a/view/select.go b/view/select.go index 444b60a..5b9ed5c 100644 --- a/view/select.go +++ b/view/select.go @@ -56,7 +56,7 @@ func SelectRating(m string) (string, error) { } // SelectWork : 作品を選択 -func SelectWork(works []*gen.WorkFragment) (int64, string, error) { +func SelectWork(works []*gen.WorkFragment) (*gen.WorkFragment, string, error) { opts := []string{} for _, work := range works { opts = append(opts, work.Title) @@ -81,17 +81,17 @@ func SelectWork(works []*gen.WorkFragment) (int64, string, error) { selectedTitle := "" if err := survey.AskOne(prompt, &selectedTitle); err != nil { - return 0, "", err + return nil, "", err } - // 選択した作品のIDを返す + // 選択した作品を返す for _, work := range works { if work.Title == selectedTitle { - return work.AnnictID, work.ID, nil + return work, work.ID, nil } } - return 0, "", fmt.Errorf("failed to retrieve the selected work ID (title: %s)", selectedTitle) + return nil, "", fmt.Errorf("failed to retrieve the selected work ID (title: %s)", selectedTitle) } // SelectEpisodes : エピソードを選択 From 40f4dac0a797aeaa94cd6044f96e7087ea163999 Mon Sep 17 00:00:00 2001 From: arrow2nd <44780846+arrow2nd@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:12:16 +0900 Subject: [PATCH 3/5] =?UTF-8?q?=E2=9C=A8=20=E3=83=AD=E3=83=BC=E3=83=9E?= =?UTF-8?q?=E5=AD=97=E3=81=A7=E3=81=AE=E6=A4=9C=E7=B4=A2=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmdutil/search.go | 7 +++++++ go.mod | 1 + go.sum | 2 ++ 3 files changed, 10 insertions(+) diff --git a/cmdutil/search.go b/cmdutil/search.go index 8cf42ca..9bdc03d 100644 --- a/cmdutil/search.go +++ b/cmdutil/search.go @@ -7,6 +7,7 @@ import ( "github.com/arrow2nd/anct/gen" "github.com/arrow2nd/anct/view" "github.com/spf13/cobra" + "github.com/usk81/r2h" ) // SearchWorks : 作品を検索してIDを取得 @@ -24,6 +25,12 @@ func SearchWorks(api *api.API, cmd *cobra.Command, args []string) (*gen.WorkFrag query = StripWhiteSpace(query) + // ローマ字 -> ひらがな変換 + convertResult, err := r2h.ConvertStrict(query) + if err == nil { + query = convertResult + } + // 条件指定が無い場合はエラー if query == "" && len(states) == 0 && len(seasons) == 0 { return nil, "", errors.New("query or `--library` or `--seasons` is required") diff --git a/go.mod b/go.mod index c3352cb..d008056 100644 --- a/go.mod +++ b/go.mod @@ -24,6 +24,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/soniakeys/quant v1.0.0 // indirect github.com/sosodev/duration v1.2.0 // indirect + github.com/usk81/r2h v0.0.3 // indirect golang.org/x/image v0.15.0 // indirect golang.org/x/sys v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect diff --git a/go.sum b/go.sum index 3d5f7e3..d727804 100644 --- a/go.sum +++ b/go.sum @@ -62,6 +62,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/usk81/r2h v0.0.3 h1:WfbHB/vTNnrmVbg+Oe4HaB3ETAAKPEyVss9m3V1XQF8= +github.com/usk81/r2h v0.0.3/go.mod h1:E82pLV21DIIapOm1g5bc55fE8AQXCD6xdHc48J10d00= github.com/vektah/gqlparser/v2 v2.5.10 h1:6zSM4azXC9u4Nxy5YmdmGu4uKamfwsdKTwp5zsEealU= github.com/vektah/gqlparser/v2 v2.5.10/go.mod h1:1rCcfwB2ekJofmluGWXMSEnPMZgbxzwj6FaZ/4OT8Cc= github.com/vektah/gqlparser/v2 v2.5.11 h1:JJxLtXIoN7+3x6MBdtIP59TP1RANnY7pXOaDnADQSf8= From bcdbe795336dd51528a3ec99eba6befdd7da37e4 Mon Sep 17 00:00:00 2001 From: arrow2nd <44780846+arrow2nd@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:13:51 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=91=8D=20=E3=82=A8=E3=83=87=E3=82=A3?= =?UTF-8?q?=E3=82=BF=E7=B5=8C=E7=94=B1=E3=81=A7=E3=81=AE=E5=85=A5=E5=8A=9B?= =?UTF-8?q?=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=84=E3=81=A8=E3=81=8D=E3=81=AE?= =?UTF-8?q?=E3=81=BF=E3=83=AD=E3=83=BC=E3=83=9E=E5=AD=97=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E3=82=92=E8=A1=8C=E3=81=86=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmdutil/search.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmdutil/search.go b/cmdutil/search.go index 9bdc03d..8685508 100644 --- a/cmdutil/search.go +++ b/cmdutil/search.go @@ -26,9 +26,11 @@ func SearchWorks(api *api.API, cmd *cobra.Command, args []string) (*gen.WorkFrag query = StripWhiteSpace(query) // ローマ字 -> ひらがな変換 - convertResult, err := r2h.ConvertStrict(query) - if err == nil { - query = convertResult + if !useEditor { + result, err := r2h.ConvertStrict(query) + if err == nil { + query = result + } } // 条件指定が無い場合はエラー From 315734714f6ce60b176946c955abe0a9e77f5faf Mon Sep 17 00:00:00 2001 From: arrow2nd <44780846+arrow2nd@users.noreply.github.com> Date: Sun, 21 Jan 2024 17:19:03 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=93=9D=20=E3=83=89=E3=82=AD=E3=83=A5?= =?UTF-8?q?=E3=83=A1=E3=83=B3=E3=83=88=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 9 +++++++++ README.md | 8 +++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6ddbd2..8fafc3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## [Unreleased] +## [v1.3.0] - 2024-01-21 + +### Added + +- 未視聴の作品を `record` した際に、視聴ステータスを WATTCING + にするか確認するように +- 作品名の入力にローマ字が使用できるように + - 日本語入力ができない端末があるので… + ## [v1.2.1] - 2023-11-11 ### Security diff --git a/README.md b/README.md index b704abb..d40cded 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ ## インストール -> **Warning** +> [!Warning] > > 以下の方法以外でインストールした場合、クライアントトークンが内蔵されていません > @@ -47,7 +47,8 @@ scoop install arrow2nd/anct ### バイナリ -[Releases](https://github.com/arrow2nd/anct/releases) からお使いの環境にあったものをダウンロードしてください +[Releases](https://github.com/arrow2nd/anct/releases) +からお使いの環境にあったものをダウンロードしてください ## 初期設定 @@ -74,7 +75,8 @@ https://annict.com/oauth/applications から作成することができます ### API クライアントのコードを生成 -[Annict の個人用アクセストークン](https://annict.com/settings/apps) (スコープ : 読み込み) を環境変数に設定して +[Annict の個人用アクセストークン](https://annict.com/settings/apps) (スコープ : +読み込み) を環境変数に設定して ``` export ANNICT_KEY=