Skip to content

Commit

Permalink
fix space escape for nyaa query
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalys committed Feb 10, 2024
1 parent 02c3209 commit 8235a5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions integrations/nyaa/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,24 @@ func filterNotEmpty(entries []string) []string {
return notEmpty
}

func quoteEntriesWithSpace(entries []string) []string {
out := make([]string, 0, len(entries))
for i := range entries {
if strings.Contains(entries[i], " ") {
out = append(out, fmt.Sprintf("\"%s\"", entries[i]))
continue
}
out = append(out, entries[i])
}
return out
}

func (entries OrQuery) Apply(req *http.Request) {
query := req.URL.Query()
prevQuery := query.Get("q")

entries = filterNotEmpty(entries)
entries = quoteEntriesWithSpace(entries)
curQuery := fmt.Sprintf("(%s)", strings.Join(entries, "|"))

if prevQuery == "" {
Expand Down
6 changes: 3 additions & 3 deletions internal/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func filterNyaaFeed(entries []nyaa.Entry, latestTag string, animeStatus animelis
return episodeFilter(parseNyaaEntries(entries), latestTag, !useBatch)
}

func ForEach[T any](in []T, f func(T) T) []T {
out := make([]T, 0, len(in))
func ForEach[T, T1 any](in []T, f func(T) T1) []T1 {
out := make([]T1, 0, len(in))
for i := range in {
out = append(out, f(in[i]))
}
Expand All @@ -124,7 +124,7 @@ func ForEach[T any](in []T, f func(T) T) []T {
func (c *Controller) DigestAnimeListEntry(ctx context.Context, entry animelist.Entry) (count int, err error) {
// Build search query for Nyaa.
// For title we filter for english and original titles.
titleQuery := nyaa.OrQuery(ForEach(entry.Titles, func(title string) string { return parser.TitleStrip(title) }))
titleQuery := nyaa.OrQuery(ForEach(entry.Titles, parser.TitleStrip))
sourceQuery := nyaa.OrQuery(c.dep.Config.Sources)
qualityQuery := nyaa.OrQuery(c.dep.Config.Qualitites)

Expand Down

0 comments on commit 8235a5b

Please sign in to comment.