Skip to content

Commit

Permalink
Merge pull request #69 from arrow2nd/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
arrow2nd authored Jan 21, 2024
2 parents 88b6480 + 3157347 commit 658b8e6
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 31 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## [Unreleased]

## [v1.3.0] - 2024-01-21

### Added

- 未視聴の作品を `record` した際に、視聴ステータスを WATTCING
にするか確認するように
- 作品名の入力にローマ字が使用できるように
- 日本語入力ができない端末があるので…

## [v1.2.1] - 2023-11-11

### Security
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

## インストール

> **Warning**
> [!Warning]
>
> 以下の方法以外でインストールした場合、クライアントトークンが内蔵されていません
>
Expand All @@ -47,7 +47,8 @@ scoop install arrow2nd/anct

### バイナリ

[Releases](https://github.com/arrow2nd/anct/releases) からお使いの環境にあったものをダウンロードしてください
[Releases](https://github.com/arrow2nd/anct/releases)
からお使いの環境にあったものをダウンロードしてください

## 初期設定

Expand All @@ -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=<API Key>
Expand Down
4 changes: 2 additions & 2 deletions cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
49 changes: 41 additions & 8 deletions cmd/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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 : 未視聴のエピソードから選択
Expand Down
27 changes: 18 additions & 9 deletions cmdutil/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,53 @@ import (
"github.com/arrow2nd/anct/gen"
"github.com/arrow2nd/anct/view"
"github.com/spf13/cobra"
"github.com/usk81/r2h"
)

// 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 !useEditor {
result, err := r2h.ConvertStrict(query)
if err == nil {
query = result
}
}

// 条件指定が無い場合はエラー
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)
}
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,26 @@ 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
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
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
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
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
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -58,14 +62,20 @@ 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=
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=
Expand Down
10 changes: 5 additions & 5 deletions view/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 : エピソードを選択
Expand Down

0 comments on commit 658b8e6

Please sign in to comment.