Skip to content

Commit

Permalink
Default quality filter config option
Browse files Browse the repository at this point in the history
  • Loading branch information
aQaTL committed Oct 31, 2018
1 parent 809ee15 commit 98fc000
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
7 changes: 7 additions & 0 deletions anilist_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,13 @@ func AniListApp(app *cli.App) *cli.App {
SkipFlagParsing: true,
Action: configChangeTorrent,
},
cli.Command{
Name: "nyaa-quality",
Usage: "Sets default quality filter for nyaa search",
UsageText: "mal cfg nyaa-quality [quality_text]",
SkipFlagParsing: true,
Action: configChangeNyaaQuality,
},
},
},
}
Expand Down
14 changes: 13 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"github.com/aqatl/mal/anilist"
"github.com/aqatl/mal/mal"
"github.com/fatih/color"
"github.com/urfave/cli"
"log"
"os"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/urfave/cli"
)

type Config struct {
Expand All @@ -26,6 +26,7 @@ type Config struct {
BrowserPath string
TorrentClientPath string
TorrentClientArgs []string
NyaaQuality string

SelectedID int
Status mal.MyStatus
Expand Down Expand Up @@ -230,3 +231,14 @@ func configChangeTorrent(ctx *cli.Context) error {

return nil
}

func configChangeNyaaQuality(ctx *cli.Context) error {
cfg := LoadConfig()

cfg.NyaaQuality = strings.Join(ctx.Args(), " ")
cfg.Save()

fmt.Fprintf(color.Output, "Changed nyaa default quality filter to %s\n", color.HiYellowString("%s", cfg.NyaaQuality))

return nil
}
7 changes: 7 additions & 0 deletions mal_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ func MalApp(app *cli.App) *cli.App {
SkipFlagParsing: true,
Action: configChangeTorrent,
},
cli.Command{
Name: "nyaa-quality",
Usage: "Sets default quality filter for nyaa search",
UsageText: "mal cfg nyaa-quality [quality_text]",
SkipFlagParsing: true,
Action: configChangeNyaaQuality,
},
},
},
cli.Command{
Expand Down
12 changes: 11 additions & 1 deletion nyaa_cui.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func malNyaaCui(ctx *cli.Context) error {
cfg,
entry.Title,
fmt.Sprintf("%s %d/%d", entry.Title, entry.WatchedEpisodes, entry.Episodes),
cfg.NyaaQuality,
)
}

Expand Down Expand Up @@ -60,15 +61,22 @@ func alNyaaCui(ctx *cli.Context) error {
cfg,
searchTerm,
fmt.Sprintf("%s %d/%d", searchTerm, entry.Progress, entry.Episodes),
cfg.NyaaQuality,
)
}

func startNyaaCui(cfg *Config, searchTerm, displayedInfo string) error {
func startNyaaCui(cfg *Config, searchTerm, displayedInfo, quality string) error {
gui, err := gocui.NewGui(gocui.Output256)
defer gui.Close()
if err != nil {
return fmt.Errorf("gocui error: %v", err)
}

qualityRe, err := regexp.Compile(regexp.QuoteMeta(quality))
if err != nil {
return fmt.Errorf("failed to parse your quality tag")
}

nc := &nyaaCui{
Gui: gui,
Cfg: cfg,
Expand All @@ -77,6 +85,8 @@ func startNyaaCui(cfg *Config, searchTerm, displayedInfo string) error {
DisplayedInfo: displayedInfo,
Category: ns.AnimeEnglishTranslated,
Filter: ns.TrustedOnly,

QualityFilter: qualityRe,
}
gui.SetManager(nc)
nc.setGuiKeyBindings(gui)
Expand Down

0 comments on commit 98fc000

Please sign in to comment.