Skip to content
This repository was archived by the owner on Dec 26, 2024. It is now read-only.

Commit 5169e09

Browse files
authored
feat(lists): steam wishlist (#85)
1 parent d644ee3 commit 5169e09

File tree

7 files changed

+124
-1
lines changed

7 files changed

+124
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
dist
44
.dev
55
.DS_Store
6+
config/
67

78
# Binaries for programs and plugins
89
*.exe

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ lists:
112112
url: https://api.autobrr.com/lists/metacritic/upcoming-albums
113113
filters:
114114
- 20 # Change me
115+
116+
- name: Steam Wishlist
117+
type: steam
118+
url: https://store.steampowered.com/wishlist/id/USERNAME/wishlistdata
119+
filters:
120+
- 20 # Change me
115121
```
116122
117123
If you're trying to reach radarr or sonarr hosted on swizzin from some other location, you need to do it like this with basic auth:

internal/domain/config.go

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var (
3838
ListTypeMdblist ListType = "mdblist"
3939
ListTypeMetacritic ListType = "metacritic"
4040
ListTypePlaintext ListType = "plaintext"
41+
ListTypeSteam ListType = "steam"
4142
)
4243

4344
type ArrConfig struct {
@@ -319,4 +320,10 @@ lists:
319320
# url: https://api.autobrr.com/lists/metacritic/upcoming-albums
320321
# filters:
321322
# - 20 # Change me
323+
324+
#- name: Steam Wishlist
325+
# type: steam
326+
# url: https://store.steampowered.com/wishlist/id/USERNAME/wishlistdata
327+
# filters:
328+
# - 20 # Change me
322329
`

internal/processor/service.go

+7
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ func (s Service) ProcessLists(ctx context.Context, dryRun bool) []string {
127127
log.Error().Err(err).Str("type", "plaintext").Str("client", listsClient.Name).Msg("error while processing Plaintext list, continuing with other lists")
128128
processingErrors = append(processingErrors, fmt.Sprintf("Plaintext - %s: %v", listsClient.Name, err))
129129
}
130+
131+
case domain.ListTypeSteam:
132+
if err := s.steam(ctx, listsClient, dryRun, a); err != nil {
133+
log.Error().Err(err).Str("type", "steam").Str("client", listsClient.Name).Msg("error while processing Steam wishlist, continuing with other lists")
134+
processingErrors = append(processingErrors, fmt.Sprintf("Steam - %s: %v", listsClient.Name, err))
135+
}
136+
130137
}
131138
}
132139
}

internal/processor/steam.go

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package processor
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"net/http"
8+
"strings"
9+
10+
"github.com/autobrr/omegabrr/internal/domain"
11+
"github.com/autobrr/omegabrr/pkg/autobrr"
12+
"github.com/rs/zerolog/log"
13+
)
14+
15+
func (s Service) steam(ctx context.Context, cfg *domain.ListConfig, dryRun bool, brr *autobrr.Client) error {
16+
l := log.With().Str("type", "steam").Str("client", cfg.Name).Logger()
17+
18+
if cfg.URL == "" {
19+
errMsg := "no URL provided for Steam wishlist"
20+
l.Error().Msg(errMsg)
21+
return fmt.Errorf(errMsg)
22+
}
23+
24+
l.Debug().Msgf("fetching titles from %s", cfg.URL)
25+
26+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, cfg.URL, nil)
27+
if err != nil {
28+
l.Error().Err(err).Msg("could not create new request")
29+
return err
30+
}
31+
32+
for k, v := range cfg.Headers {
33+
req.Header.Set(k, v)
34+
}
35+
36+
setUserAgent(req)
37+
38+
resp, err := s.httpClient.Do(req)
39+
if err != nil {
40+
l.Error().Err(err).Msg("failed to fetch titles")
41+
return err
42+
}
43+
defer resp.Body.Close()
44+
45+
if resp.StatusCode != http.StatusOK {
46+
l.Error().Msg("failed to fetch titles, non-OK HTTP status received")
47+
return fmt.Errorf("failed to fetch titles, non-OK HTTP status received")
48+
}
49+
50+
var data map[string]struct {
51+
Name string `json:"name"`
52+
}
53+
54+
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
55+
l.Error().Err(err).Msg("failed to decode JSON data")
56+
return err
57+
}
58+
59+
var titles []string
60+
for _, item := range data {
61+
titles = append(titles, item.Name)
62+
}
63+
64+
for _, filterID := range cfg.Filters {
65+
filterTitles := []string{}
66+
for _, title := range titles {
67+
filterTitles = append(filterTitles, processTitle(title, cfg.MatchRelease)...)
68+
}
69+
70+
joinedTitles := strings.Join(filterTitles, ",")
71+
72+
l.Trace().Msgf("%s", joinedTitles)
73+
74+
if len(joinedTitles) == 0 {
75+
l.Debug().Msgf("no titles found for filter: %v", filterID)
76+
continue
77+
}
78+
79+
f := autobrr.UpdateFilter{MatchReleases: joinedTitles}
80+
81+
if !dryRun {
82+
if err := brr.UpdateFilterByID(ctx, filterID, f); err != nil {
83+
l.Error().Err(err).Msgf("error updating filter: %v", filterID)
84+
return err
85+
}
86+
}
87+
88+
l.Debug().Msgf("successfully updated filter: %v", filterID)
89+
}
90+
91+
return nil
92+
}

internal/processor/title.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func processTitle(title string, matchRelease bool) []string {
2121
// Regex patterns
2222
// https://www.regular-expressions.info/unicode.html#category
2323
// https://www.ncbi.nlm.nih.gov/staff/beck/charents/hex.html
24-
replaceRegexp := regexp.MustCompile(`[\p{P}\p{Z}\x{00C0}-\x{017E}]`)
24+
replaceRegexp := regexp.MustCompile(`[\p{P}\p{Z}\x{00C0}-\x{017E}\x{00AE}]`)
2525
questionmarkRegexp := regexp.MustCompile(`[?]{2,}`)
2626
regionCodeRegexp := regexp.MustCompile(`\(.+\)$`)
2727
parenthesesEndRegexp := regexp.MustCompile(`\)$`)

internal/processor/title_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ func Test_processTitle(t *testing.T) {
216216
},
217217
want: []string{"Sh?gun*2024?", "Sh?gun*2024", "Sh?gun"},
218218
},
219+
{
220+
name: "test_26",
221+
args: args{
222+
title: "Pinball FX3 - Bethesda® Pinball",
223+
matchRelease: false,
224+
},
225+
want: []string{
226+
"Pinball?FX3*Bethesda*Pinball",
227+
},
228+
},
219229
}
220230
for _, tt := range tests {
221231
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)