mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 08:19:12 +00:00
Add support for using freeleech tokens if available
This commit is contained in:
parent
74f777340e
commit
1242c19883
21 changed files with 88 additions and 34 deletions
|
@ -447,6 +447,7 @@ type FilterExport struct {
|
||||||
// Media-specific fields
|
// Media-specific fields
|
||||||
Freeleech bool `json:"freeleech,omitempty"`
|
Freeleech bool `json:"freeleech,omitempty"`
|
||||||
FreeleechPercent string `json:"freeleech_percent,omitempty"`
|
FreeleechPercent string `json:"freeleech_percent,omitempty"`
|
||||||
|
FreeleechToken bool `json:"freeleech_token,omitempty"`
|
||||||
Shows string `json:"shows,omitempty"`
|
Shows string `json:"shows,omitempty"`
|
||||||
Seasons string `json:"seasons,omitempty"`
|
Seasons string `json:"seasons,omitempty"`
|
||||||
Episodes string `json:"episodes,omitempty"`
|
Episodes string `json:"episodes,omitempty"`
|
||||||
|
|
|
@ -210,6 +210,7 @@ func (r *FilterRepo) FindByID(ctx context.Context, filterID int) (*domain.Filter
|
||||||
"f.scene",
|
"f.scene",
|
||||||
"f.freeleech",
|
"f.freeleech",
|
||||||
"f.freeleech_percent",
|
"f.freeleech_percent",
|
||||||
|
"f.freeleech_token",
|
||||||
"f.smart_episode",
|
"f.smart_episode",
|
||||||
"f.shows",
|
"f.shows",
|
||||||
"f.seasons",
|
"f.seasons",
|
||||||
|
@ -438,6 +439,7 @@ func (r *FilterRepo) findByIndexerIdentifier(ctx context.Context, indexer string
|
||||||
"f.scene",
|
"f.scene",
|
||||||
"f.freeleech",
|
"f.freeleech",
|
||||||
"f.freeleech_percent",
|
"f.freeleech_percent",
|
||||||
|
"f.freeleech_token",
|
||||||
"f.smart_episode",
|
"f.smart_episode",
|
||||||
"f.shows",
|
"f.shows",
|
||||||
"f.seasons",
|
"f.seasons",
|
||||||
|
@ -832,6 +834,7 @@ func (r *FilterRepo) Store(ctx context.Context, filter *domain.Filter) error {
|
||||||
"scene",
|
"scene",
|
||||||
"freeleech",
|
"freeleech",
|
||||||
"freeleech_percent",
|
"freeleech_percent",
|
||||||
|
"freeleech_token",
|
||||||
"smart_episode",
|
"smart_episode",
|
||||||
"shows",
|
"shows",
|
||||||
"seasons",
|
"seasons",
|
||||||
|
@ -988,6 +991,7 @@ func (r *FilterRepo) Update(ctx context.Context, filter *domain.Filter) error {
|
||||||
Set("scene", filter.Scene).
|
Set("scene", filter.Scene).
|
||||||
Set("freeleech", filter.Freeleech).
|
Set("freeleech", filter.Freeleech).
|
||||||
Set("freeleech_percent", filter.FreeleechPercent).
|
Set("freeleech_percent", filter.FreeleechPercent).
|
||||||
|
Set("freeleech_token", filter.FreeleechToken).
|
||||||
Set("smart_episode", filter.SmartEpisode).
|
Set("smart_episode", filter.SmartEpisode).
|
||||||
Set("shows", filter.Shows).
|
Set("shows", filter.Shows).
|
||||||
Set("seasons", filter.Seasons).
|
Set("seasons", filter.Seasons).
|
||||||
|
@ -1128,6 +1132,9 @@ func (r *FilterRepo) UpdatePartial(ctx context.Context, filter domain.FilterUpda
|
||||||
if filter.FreeleechPercent != nil {
|
if filter.FreeleechPercent != nil {
|
||||||
q = q.Set("freeleech_percent", filter.FreeleechPercent)
|
q = q.Set("freeleech_percent", filter.FreeleechPercent)
|
||||||
}
|
}
|
||||||
|
if filter.FreeleechToken != nil {
|
||||||
|
q = q.Set("freeleech_token", filter.FreeleechToken)
|
||||||
|
}
|
||||||
if filter.SmartEpisode != nil {
|
if filter.SmartEpisode != nil {
|
||||||
q = q.Set("smart_episode", filter.SmartEpisode)
|
q = q.Set("smart_episode", filter.SmartEpisode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2018,5 +2018,9 @@ CREATE INDEX release_hybrid_index
|
||||||
FROM irc_network
|
FROM irc_network
|
||||||
WHERE server = 'irc.rocket-hd.cc'
|
WHERE server = 'irc.rocket-hd.cc'
|
||||||
);
|
);
|
||||||
|
`,
|
||||||
|
`ALTER TABLE filters
|
||||||
|
ADD COLUMN freeleach_tokens BOOLEAN
|
||||||
|
AFTER freeleech_percent;
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,7 @@ type Filter struct {
|
||||||
Bonus []string `json:"bonus,omitempty"`
|
Bonus []string `json:"bonus,omitempty"`
|
||||||
Freeleech bool `json:"freeleech,omitempty"`
|
Freeleech bool `json:"freeleech,omitempty"`
|
||||||
FreeleechPercent string `json:"freeleech_percent,omitempty"`
|
FreeleechPercent string `json:"freeleech_percent,omitempty"`
|
||||||
|
FreeleechToken bool `json:"freeleech_token,omitempty"`
|
||||||
SmartEpisode bool `json:"smart_episode"`
|
SmartEpisode bool `json:"smart_episode"`
|
||||||
Shows string `json:"shows,omitempty"`
|
Shows string `json:"shows,omitempty"`
|
||||||
Seasons string `json:"seasons,omitempty"`
|
Seasons string `json:"seasons,omitempty"`
|
||||||
|
@ -248,6 +249,7 @@ type FilterUpdate struct {
|
||||||
Bonus *[]string `json:"bonus,omitempty"`
|
Bonus *[]string `json:"bonus,omitempty"`
|
||||||
Freeleech *bool `json:"freeleech,omitempty"`
|
Freeleech *bool `json:"freeleech,omitempty"`
|
||||||
FreeleechPercent *string `json:"freeleech_percent,omitempty"`
|
FreeleechPercent *string `json:"freeleech_percent,omitempty"`
|
||||||
|
FreeleechToken *bool `json:"freeleech_token,omitempty"`
|
||||||
SmartEpisode *bool `json:"smart_episode,omitempty"`
|
SmartEpisode *bool `json:"smart_episode,omitempty"`
|
||||||
Shows *string `json:"shows,omitempty"`
|
Shows *string `json:"shows,omitempty"`
|
||||||
Seasons *string `json:"seasons,omitempty"`
|
Seasons *string `json:"seasons,omitempty"`
|
||||||
|
|
|
@ -558,7 +558,7 @@ func (s *service) AdditionalSizeCheck(ctx context.Context, f *domain.Filter, rel
|
||||||
if (release.Size == 0 && release.AdditionalSizeCheckRequired) || (release.Uploader == "" && release.AdditionalUploaderCheckRequired) || (release.RecordLabel == "" && release.AdditionalRecordLabelCheckRequired) {
|
if (release.Size == 0 && release.AdditionalSizeCheckRequired) || (release.Uploader == "" && release.AdditionalUploaderCheckRequired) || (release.RecordLabel == "" && release.AdditionalRecordLabelCheckRequired) {
|
||||||
l.Trace().Msgf("(%s) preparing to check size via api", f.Name)
|
l.Trace().Msgf("(%s) preparing to check size via api", f.Name)
|
||||||
|
|
||||||
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID)
|
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID, f.FreeleechToken)
|
||||||
if err != nil || torrentInfo == nil {
|
if err != nil || torrentInfo == nil {
|
||||||
l.Error().Err(err).Msgf("(%s) could not get torrent info from api: '%s' from: %s", f.Name, release.TorrentID, release.Indexer.Identifier)
|
l.Error().Err(err).Msgf("(%s) could not get torrent info from api: '%s' from: %s", f.Name, release.TorrentID, release.Indexer.Identifier)
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -643,7 +643,7 @@ func (s *service) AdditionalUploaderCheck(ctx context.Context, f *domain.Filter,
|
||||||
case "redacted", "ops", "mock":
|
case "redacted", "ops", "mock":
|
||||||
l.Trace().Msgf("(%s) preparing to check via api", f.Name)
|
l.Trace().Msgf("(%s) preparing to check via api", f.Name)
|
||||||
|
|
||||||
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID)
|
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID, f.FreeleechToken)
|
||||||
if err != nil || torrentInfo == nil {
|
if err != nil || torrentInfo == nil {
|
||||||
l.Error().Err(err).Msgf("(%s) could not get torrent info from api: '%s' from: %s", f.Name, release.TorrentID, release.Indexer.Identifier)
|
l.Error().Err(err).Msgf("(%s) could not get torrent info from api: '%s' from: %s", f.Name, release.TorrentID, release.Indexer.Identifier)
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -722,7 +722,7 @@ func (s *service) AdditionalRecordLabelCheck(ctx context.Context, f *domain.Filt
|
||||||
case "redacted", "ops", "mock":
|
case "redacted", "ops", "mock":
|
||||||
l.Trace().Msgf("(%s) preparing to check via api", f.Name)
|
l.Trace().Msgf("(%s) preparing to check via api", f.Name)
|
||||||
|
|
||||||
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID)
|
torrentInfo, err := s.apiService.GetTorrentByID(ctx, release.Indexer.Identifier, release.TorrentID, f.FreeleechToken)
|
||||||
if err != nil || torrentInfo == nil {
|
if err != nil || torrentInfo == nil {
|
||||||
l.Error().Err(err).Msgf("(%s) could not get torrent info from api: '%s' from: %s", f.Name, release.TorrentID, release.Indexer.Identifier)
|
l.Error().Err(err).Msgf("(%s) could not get torrent info from api: '%s' from: %s", f.Name, release.TorrentID, release.Indexer.Identifier)
|
||||||
return false, err
|
return false, err
|
||||||
|
|
|
@ -20,13 +20,13 @@ import (
|
||||||
|
|
||||||
type APIService interface {
|
type APIService interface {
|
||||||
TestConnection(ctx context.Context, req domain.IndexerTestApiRequest) (bool, error)
|
TestConnection(ctx context.Context, req domain.IndexerTestApiRequest) (bool, error)
|
||||||
GetTorrentByID(ctx context.Context, indexer string, torrentID string) (*domain.TorrentBasic, error)
|
GetTorrentByID(ctx context.Context, indexer string, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
|
||||||
AddClient(indexer string, settings map[string]string) error
|
AddClient(indexer string, settings map[string]string) error
|
||||||
RemoveClient(indexer string) error
|
RemoveClient(indexer string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type apiClient interface {
|
type apiClient interface {
|
||||||
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
|
GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
|
||||||
TestAPI(ctx context.Context) (bool, error)
|
TestAPI(ctx context.Context) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func NewAPIService(log logger.Logger) APIService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *apiService) GetTorrentByID(ctx context.Context, indexer string, torrentID string) (*domain.TorrentBasic, error) {
|
func (s *apiService) GetTorrentByID(ctx context.Context, indexer string, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error) {
|
||||||
client, err := s.getApiClient(indexer)
|
client, err := s.getApiClient(indexer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Error().Stack().Err(err).Msgf("could not get api client for: %s", indexer)
|
s.log.Error().Stack().Err(err).Msgf("could not get api client for: %s", indexer)
|
||||||
|
@ -51,7 +51,7 @@ func (s *apiService) GetTorrentByID(ctx context.Context, indexer string, torrent
|
||||||
|
|
||||||
s.log.Trace().Str("method", "GetTorrentByID").Msgf("%s fetching torrent from api...", indexer)
|
s.log.Trace().Str("method", "GetTorrentByID").Msgf("%s fetching torrent from api...", indexer)
|
||||||
|
|
||||||
torrent, err := client.GetTorrentByID(ctx, torrentID)
|
torrent, err := client.GetTorrentByID(ctx, torrentID, freeleechToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Error().Stack().Err(err).Msgf("could not get torrent: %s from: %s", torrentID, indexer)
|
s.log.Error().Stack().Err(err).Msgf("could not get torrent: %s from: %s", torrentID, indexer)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexerApiClient interface {
|
type IndexerApiClient interface {
|
||||||
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
|
GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
|
||||||
TestAPI(ctx context.Context) (bool, error)
|
TestAPI(ctx context.Context) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,12 +32,12 @@ func (c *Client) TestAPI(ctx context.Context) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error) {
|
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error) {
|
||||||
if torrentID == "" {
|
if torrentID == "" {
|
||||||
return nil, errors.New("btn client: must have torrentID")
|
return nil, errors.New("btn client: must have torrentID")
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err := c.rpcClient.CallCtx(ctx, "getTorrentById", [2]string{c.APIKey, torrentID})
|
res, err := c.rpcClient.CallCtx(ctx, "getTorrentById", [3]interface{}{c.APIKey, torrentID, freeleechToken})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "call getTorrentById failed")
|
return nil, errors.Wrap(err, "call getTorrentById failed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
const DefaultURL = "https://api.broadcasthe.net/"
|
const DefaultURL = "https://api.broadcasthe.net/"
|
||||||
|
|
||||||
type ApiClient interface {
|
type ApiClient interface {
|
||||||
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
|
GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
|
||||||
TestAPI(ctx context.Context) (bool, error)
|
TestAPI(ctx context.Context) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ var ErrForbidden = errors.New("forbidden")
|
||||||
var ErrTooManyRequests = errors.New("too many requests: rate-limit reached")
|
var ErrTooManyRequests = errors.New("too many requests: rate-limit reached")
|
||||||
|
|
||||||
type ApiClient interface {
|
type ApiClient interface {
|
||||||
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
|
GetTorrentByID(ctx context.Context, torrentID string, freelechToken bool) (*domain.TorrentBasic, error)
|
||||||
TestAPI(ctx context.Context) (bool, error)
|
TestAPI(ctx context.Context) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ func (c *Client) getJSON(ctx context.Context, params url.Values, data any) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error) {
|
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error) {
|
||||||
if torrentID == "" {
|
if torrentID == "" {
|
||||||
return nil, errors.New("ggn client: must have torrentID")
|
return nil, errors.New("ggn client: must have torrentID")
|
||||||
}
|
}
|
||||||
|
@ -253,6 +253,9 @@ func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("request", "torrent")
|
params.Add("request", "torrent")
|
||||||
params.Add("id", torrentID)
|
params.Add("id", torrentID)
|
||||||
|
if freeleechToken {
|
||||||
|
params.Add("usetoken", "1")
|
||||||
|
}
|
||||||
|
|
||||||
err := c.getJSON(ctx, params, &response)
|
err := c.getJSON(ctx, params, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -86,7 +86,7 @@ func Test_client_GetTorrentByID(t *testing.T) {
|
||||||
Url: ts.URL,
|
Url: ts.URL,
|
||||||
APIKey: key,
|
APIKey: key,
|
||||||
},
|
},
|
||||||
args: args{torrentID: "422368"},
|
args: args{torrentID: "422368", freeleechToken: false},
|
||||||
want: &domain.TorrentBasic{
|
want: &domain.TorrentBasic{
|
||||||
Id: "422368",
|
Id: "422368",
|
||||||
InfoHash: "78DA2811E6732012B8224198D4DC2FD49A5E950F",
|
InfoHash: "78DA2811E6732012B8224198D4DC2FD49A5E950F",
|
||||||
|
@ -100,7 +100,7 @@ func Test_client_GetTorrentByID(t *testing.T) {
|
||||||
Url: ts.URL,
|
Url: ts.URL,
|
||||||
APIKey: key,
|
APIKey: key,
|
||||||
},
|
},
|
||||||
args: args{torrentID: "100002"},
|
args: args{torrentID: "100002", freeleechToken: true},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
},
|
||||||
|
@ -109,7 +109,7 @@ func Test_client_GetTorrentByID(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
c := NewClient(tt.fields.APIKey, WithUrl(ts.URL))
|
c := NewClient(tt.fields.APIKey, WithUrl(ts.URL))
|
||||||
|
|
||||||
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID)
|
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID, tt.args.freeleechToken)
|
||||||
if tt.wantErr && assert.Error(t, err) {
|
if tt.wantErr && assert.Error(t, err) {
|
||||||
t.Logf("got err: %v", err)
|
t.Logf("got err: %v", err)
|
||||||
assert.Equal(t, tt.wantErr, err)
|
assert.Equal(t, tt.wantErr, err)
|
||||||
|
|
|
@ -23,7 +23,7 @@ import (
|
||||||
const DefaultURL = "https://orpheus.network/ajax.php"
|
const DefaultURL = "https://orpheus.network/ajax.php"
|
||||||
|
|
||||||
type ApiClient interface {
|
type ApiClient interface {
|
||||||
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
|
GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
|
||||||
TestAPI(ctx context.Context) (bool, error)
|
TestAPI(ctx context.Context) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ func (c *Client) getJSON(ctx context.Context, params url.Values, data any) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error) {
|
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error) {
|
||||||
if torrentID == "" {
|
if torrentID == "" {
|
||||||
return nil, errors.New("orpheus client: must have torrentID")
|
return nil, errors.New("orpheus client: must have torrentID")
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,9 @@ func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("action", "torrent")
|
params.Add("action", "torrent")
|
||||||
params.Add("id", torrentID)
|
params.Add("id", torrentID)
|
||||||
|
if freeleechToken {
|
||||||
|
params.Add("usetoken", "1")
|
||||||
|
}
|
||||||
|
|
||||||
err := c.getJSON(ctx, params, &response)
|
err := c.getJSON(ctx, params, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -70,7 +70,7 @@ func TestOrpheusClient_GetTorrentByID(t *testing.T) {
|
||||||
Url: ts.URL,
|
Url: ts.URL,
|
||||||
APIKey: key,
|
APIKey: key,
|
||||||
},
|
},
|
||||||
args: args{torrentID: "2156788"},
|
args: args{torrentID: "2156788", freeleechToken: false},
|
||||||
want: &domain.TorrentBasic{
|
want: &domain.TorrentBasic{
|
||||||
Id: "2156788",
|
Id: "2156788",
|
||||||
InfoHash: "",
|
InfoHash: "",
|
||||||
|
@ -86,7 +86,7 @@ func TestOrpheusClient_GetTorrentByID(t *testing.T) {
|
||||||
Url: ts.URL,
|
Url: ts.URL,
|
||||||
APIKey: key,
|
APIKey: key,
|
||||||
},
|
},
|
||||||
args: args{torrentID: "100002"},
|
args: args{torrentID: "100002", freeleechToken: false},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: "could not get torrent by id: 100002: status code: 400 status: failure error: bad id parameter",
|
wantErr: "could not get torrent by id: 100002: status code: 400 status: failure error: bad id parameter",
|
||||||
},
|
},
|
||||||
|
@ -96,16 +96,26 @@ func TestOrpheusClient_GetTorrentByID(t *testing.T) {
|
||||||
Url: ts.URL,
|
Url: ts.URL,
|
||||||
APIKey: "",
|
APIKey: "",
|
||||||
},
|
},
|
||||||
args: args{torrentID: "100002"},
|
args: args{torrentID: "100002", freeleechToken: false},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: "could not get torrent by id: 100002: orpheus client missing API key!",
|
wantErr: "could not get torrent by id: 100002: orpheus client missing API key!",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "get_by_id_1_freeleech_token",
|
||||||
|
fields: fields{
|
||||||
|
Url: ts.URL,
|
||||||
|
APIKey: "",
|
||||||
|
},
|
||||||
|
args: args{torrentID: "100002", freeleechToken: true},
|
||||||
|
want: nil,
|
||||||
|
wantErr: "could not get torrent by id: 1. freeleech token not supported or no tokens available",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
c := NewClient(tt.fields.APIKey, WithUrl(ts.URL))
|
c := NewClient(tt.fields.APIKey, WithUrl(ts.URL))
|
||||||
|
|
||||||
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID)
|
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID, tt.args.freeleechToken)
|
||||||
if tt.wantErr != "" && assert.Error(t, err) {
|
if tt.wantErr != "" && assert.Error(t, err) {
|
||||||
assert.EqualErrorf(t, err, tt.wantErr, "Error should be: %v, got: %v", tt.wantErr, err)
|
assert.EqualErrorf(t, err, tt.wantErr, "Error should be: %v, got: %v", tt.wantErr, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ var ErrForbidden = errors.New("forbidden")
|
||||||
var ErrTooManyRequests = errors.New("too many requests: rate-limit reached")
|
var ErrTooManyRequests = errors.New("too many requests: rate-limit reached")
|
||||||
|
|
||||||
type ApiClient interface {
|
type ApiClient interface {
|
||||||
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
|
GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
|
||||||
TestAPI(ctx context.Context) (bool, error)
|
TestAPI(ctx context.Context) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ func (c *Client) getJSON(ctx context.Context, params url.Values, data any) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error) {
|
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error) {
|
||||||
if torrentID == "" {
|
if torrentID == "" {
|
||||||
return nil, errors.New("ptp client: must have torrentID")
|
return nil, errors.New("ptp client: must have torrentID")
|
||||||
}
|
}
|
||||||
|
@ -189,6 +189,9 @@ func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.
|
||||||
|
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("torrentid", torrentID)
|
params.Add("torrentid", torrentID)
|
||||||
|
if freeleechToken {
|
||||||
|
params.Add("usetoken", "1")
|
||||||
|
}
|
||||||
|
|
||||||
err := c.getJSON(ctx, params, &response)
|
err := c.getJSON(ctx, params, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -72,7 +72,7 @@ func TestPTPClient_GetTorrentByID(t *testing.T) {
|
||||||
APIUser: user,
|
APIUser: user,
|
||||||
APIKey: key,
|
APIKey: key,
|
||||||
},
|
},
|
||||||
args: args{torrentID: "1"},
|
args: args{torrentID: "1", freeleechToken: false},
|
||||||
want: &domain.TorrentBasic{
|
want: &domain.TorrentBasic{
|
||||||
Id: "1",
|
Id: "1",
|
||||||
InfoHash: "F57AA86DFB03F87FCC7636E310D35918442EAE5C",
|
InfoHash: "F57AA86DFB03F87FCC7636E310D35918442EAE5C",
|
||||||
|
@ -87,7 +87,7 @@ func TestPTPClient_GetTorrentByID(t *testing.T) {
|
||||||
APIUser: user,
|
APIUser: user,
|
||||||
APIKey: key,
|
APIKey: key,
|
||||||
},
|
},
|
||||||
args: args{torrentID: "100002"},
|
args: args{torrentID: "100002", freeleechToken: false},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
@ -96,7 +96,7 @@ func TestPTPClient_GetTorrentByID(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
c := NewClient(tt.fields.APIUser, tt.fields.APIKey, WithUrl(ts.URL))
|
c := NewClient(tt.fields.APIUser, tt.fields.APIKey, WithUrl(ts.URL))
|
||||||
|
|
||||||
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID)
|
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID, tt.args.freeleechToken)
|
||||||
if tt.wantErr {
|
if tt.wantErr {
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,7 +23,7 @@ import (
|
||||||
const DefaultURL = "https://redacted.sh/ajax.php"
|
const DefaultURL = "https://redacted.sh/ajax.php"
|
||||||
|
|
||||||
type ApiClient interface {
|
type ApiClient interface {
|
||||||
GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error)
|
GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error)
|
||||||
TestAPI(ctx context.Context) (bool, error)
|
TestAPI(ctx context.Context) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ func (c *Client) getJSON(ctx context.Context, params url.Values, data any) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.TorrentBasic, error) {
|
func (c *Client) GetTorrentByID(ctx context.Context, torrentID string, freeleechToken bool) (*domain.TorrentBasic, error) {
|
||||||
if torrentID == "" {
|
if torrentID == "" {
|
||||||
return nil, errors.New("red client: must have torrentID")
|
return nil, errors.New("red client: must have torrentID")
|
||||||
}
|
}
|
||||||
|
@ -224,6 +224,9 @@ func (c *Client) GetTorrentByID(ctx context.Context, torrentID string) (*domain.
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
params.Add("action", "torrent")
|
params.Add("action", "torrent")
|
||||||
params.Add("id", torrentID)
|
params.Add("id", torrentID)
|
||||||
|
if freeleechToken {
|
||||||
|
params.Add("usetoken", "1")
|
||||||
|
}
|
||||||
|
|
||||||
err := c.getJSON(ctx, params, &response)
|
err := c.getJSON(ctx, params, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -70,7 +70,7 @@ func TestREDClient_GetTorrentByID(t *testing.T) {
|
||||||
Url: ts.URL,
|
Url: ts.URL,
|
||||||
APIKey: key,
|
APIKey: key,
|
||||||
},
|
},
|
||||||
args: args{torrentID: "29991962"},
|
args: args{torrentID: "29991962", freeleechToken: false},
|
||||||
want: &domain.TorrentBasic{
|
want: &domain.TorrentBasic{
|
||||||
Id: "29991962",
|
Id: "29991962",
|
||||||
InfoHash: "B2BABD3A361EAFC6C4E9142C422DF7DDF5D7E163",
|
InfoHash: "B2BABD3A361EAFC6C4E9142C422DF7DDF5D7E163",
|
||||||
|
@ -86,7 +86,7 @@ func TestREDClient_GetTorrentByID(t *testing.T) {
|
||||||
Url: ts.URL,
|
Url: ts.URL,
|
||||||
APIKey: key,
|
APIKey: key,
|
||||||
},
|
},
|
||||||
args: args{torrentID: "100002"},
|
args: args{torrentID: "100002", freeleechToken: false},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: "could not get torrent by id: 100002: status code: 400 status: failure error: bad id parameter",
|
wantErr: "could not get torrent by id: 100002: status code: 400 status: failure error: bad id parameter",
|
||||||
},
|
},
|
||||||
|
@ -96,7 +96,7 @@ func TestREDClient_GetTorrentByID(t *testing.T) {
|
||||||
Url: ts.URL,
|
Url: ts.URL,
|
||||||
APIKey: "",
|
APIKey: "",
|
||||||
},
|
},
|
||||||
args: args{torrentID: "100002"},
|
args: args{torrentID: "100002", freeleechToken: false},
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: "could not get torrent by id: 100002: RED client missing API key!",
|
wantErr: "could not get torrent by id: 100002: RED client missing API key!",
|
||||||
},
|
},
|
||||||
|
@ -105,7 +105,7 @@ func TestREDClient_GetTorrentByID(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
c := NewClient(tt.fields.APIKey, WithUrl(ts.URL))
|
c := NewClient(tt.fields.APIKey, WithUrl(ts.URL))
|
||||||
|
|
||||||
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID)
|
got, err := c.GetTorrentByID(context.Background(), tt.args.torrentID, tt.args.freeleechToken)
|
||||||
if tt.wantErr != "" && assert.Error(t, err) {
|
if tt.wantErr != "" && assert.Error(t, err) {
|
||||||
assert.EqualErrorf(t, err, tt.wantErr, "Error should be: %v, got: %v", tt.wantErr, err)
|
assert.EqualErrorf(t, err, tt.wantErr, "Error should be: %v, got: %v", tt.wantErr, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -437,6 +437,7 @@ export const FilterDetails = () => {
|
||||||
except_language: filter.except_language || [],
|
except_language: filter.except_language || [],
|
||||||
freeleech: filter.freeleech,
|
freeleech: filter.freeleech,
|
||||||
freeleech_percent: filter.freeleech_percent,
|
freeleech_percent: filter.freeleech_percent,
|
||||||
|
freeleech_token: filter.freeleech_token,
|
||||||
formats: filter.formats || [],
|
formats: filter.formats || [],
|
||||||
quality: filter.quality || [],
|
quality: filter.quality || [],
|
||||||
media: filter.media || [],
|
media: filter.media || [],
|
||||||
|
|
|
@ -14,6 +14,7 @@ export const FILTER_FIELDS: Record<string, string> = {
|
||||||
"scene": "boolean",
|
"scene": "boolean",
|
||||||
"smart_episode": "boolean",
|
"smart_episode": "boolean",
|
||||||
"freeleech": "boolean",
|
"freeleech": "boolean",
|
||||||
|
"freeleech_token": "boolean",
|
||||||
"perfect_flac": "boolean",
|
"perfect_flac": "boolean",
|
||||||
"download_duplicates": "boolean",
|
"download_duplicates": "boolean",
|
||||||
"cue": "boolean",
|
"cue": "boolean",
|
||||||
|
|
|
@ -354,7 +354,7 @@ const Freeleech = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CollapsibleSection
|
<CollapsibleSection
|
||||||
defaultOpen={values.freeleech || values.freeleech_percent !== undefined}
|
defaultOpen={values.freeleech || values.freeleech_token || values.freeleech_percent !== undefined}
|
||||||
title="Freeleech"
|
title="Freeleech"
|
||||||
subtitle="Match based off freeleech (if announced)"
|
subtitle="Match based off freeleech (if announced)"
|
||||||
>
|
>
|
||||||
|
@ -401,6 +401,21 @@ const Freeleech = () => {
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</FilterHalfRow>
|
</FilterHalfRow>
|
||||||
|
<FilterHalfRow>
|
||||||
|
<SwitchGroup
|
||||||
|
name="freeleech_token"
|
||||||
|
label="Freeleech Tokens"
|
||||||
|
className="py-0"
|
||||||
|
description="Use freeleech tokens."
|
||||||
|
tooltip={
|
||||||
|
<div>
|
||||||
|
<p>
|
||||||
|
Use freelech tokens for downloads if supported bt the tracker.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</FilterHalfRow>
|
||||||
</CollapsibleSection>
|
</CollapsibleSection>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
1
web/src/types/Filter.d.ts
vendored
1
web/src/types/Filter.d.ts
vendored
|
@ -32,6 +32,7 @@ interface Filter {
|
||||||
except_origins: string[];
|
except_origins: string[];
|
||||||
freeleech: boolean;
|
freeleech: boolean;
|
||||||
freeleech_percent: string;
|
freeleech_percent: string;
|
||||||
|
freeleech_token: boolean;
|
||||||
shows: string;
|
shows: string;
|
||||||
seasons: string;
|
seasons: string;
|
||||||
episodes: string;
|
episodes: string;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue