Skip to content

Commit

Permalink
feat(macros): add IndexerName (#1511)
Browse files Browse the repository at this point in the history
* feat(macros): add IndexerName

* fix: tests

* fix: tests
  • Loading branch information
zze0s committed Apr 16, 2024
1 parent c43e2c7 commit 3c3b47f
Show file tree
Hide file tree
Showing 37 changed files with 310 additions and 235 deletions.
2 changes: 1 addition & 1 deletion internal/action/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *service) execCmd(ctx context.Context, action *domain.Action, release do

duration := time.Since(start)

s.log.Info().Msgf("executed command: '%s', args: '%s' %s,%s, total time %v", cmd, args, release.TorrentName, release.Indexer, duration)
s.log.Info().Msgf("executed command: '%s', args: '%s' %s,%s, total time %v", cmd, args, release.TorrentName, release.Indexer.Name, duration)

return nil
}
6 changes: 5 additions & 1 deletion internal/action/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ func Test_service_execCmd(t *testing.T) {
release: domain.Release{
TorrentName: "This is a test",
TorrentTmpFile: "tmp-10000",
Indexer: "mock",
Indexer: domain.IndexerMinimal{
ID: 0,
Name: "Mock Indexer",
Identifier: "mock",
},
},
action: &domain.Action{
Name: "echo",
Expand Down
2 changes: 1 addition & 1 deletion internal/action/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *service) lidarr(ctx context.Context, action *domain.Action, release dom
DownloadUrl: release.DownloadURL,
MagnetUrl: release.MagnetURI,
Size: int64(release.Size),
Indexer: release.Indexer,
Indexer: release.Indexer.Identifier,
DownloadClientId: externalClientId,
DownloadClient: externalClient,
DownloadProtocol: string(release.Protocol),
Expand Down
2 changes: 1 addition & 1 deletion internal/action/radarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *service) radarr(ctx context.Context, action *domain.Action, release dom
DownloadUrl: release.DownloadURL,
MagnetUrl: release.MagnetURI,
Size: int64(release.Size),
Indexer: release.Indexer,
Indexer: release.Indexer.Identifier,
DownloadClientId: externalClientId,
DownloadClient: externalClient,
DownloadProtocol: string(release.Protocol),
Expand Down
2 changes: 1 addition & 1 deletion internal/action/readarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *service) readarr(ctx context.Context, action *domain.Action, release do
DownloadUrl: release.DownloadURL,
MagnetUrl: release.MagnetURI,
Size: int64(release.Size),
Indexer: release.Indexer,
Indexer: release.Indexer.Identifier,
DownloadClientId: externalClientId,
DownloadClient: externalClient,
DownloadProtocol: string(release.Protocol),
Expand Down
2 changes: 1 addition & 1 deletion internal/action/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (s *service) RunAction(ctx context.Context, action *domain.Action, release
Event: domain.NotificationEventPushApproved,
ReleaseName: release.TorrentName,
Filter: release.FilterName,
Indexer: release.Indexer,
Indexer: release.Indexer.Name,
InfoHash: release.TorrentHash,
Size: release.Size,
Status: domain.ReleasePushStatusApproved,
Expand Down
2 changes: 1 addition & 1 deletion internal/action/sonarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *service) sonarr(ctx context.Context, action *domain.Action, release dom
DownloadUrl: release.DownloadURL,
MagnetUrl: release.MagnetURI,
Size: int64(release.Size),
Indexer: release.Indexer,
Indexer: release.Indexer.Identifier,
DownloadClientId: externalClientId,
DownloadClient: externalClient,
DownloadProtocol: string(release.Protocol),
Expand Down
2 changes: 1 addition & 1 deletion internal/action/whisparr.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *service) whisparr(ctx context.Context, action *domain.Action, release d
DownloadUrl: release.DownloadURL,
MagnetUrl: release.MagnetURI,
Size: int64(release.Size),
Indexer: release.Indexer,
Indexer: release.Indexer.Identifier,
DownloadClientId: externalClientId,
DownloadClient: externalClient,
DownloadProtocol: string(release.Protocol),
Expand Down
2 changes: 1 addition & 1 deletion internal/announce/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (a *announceProcessor) processQueue(queue chan string) {
continue
}

rls := domain.NewRelease(a.indexer.Identifier)
rls := domain.NewRelease(domain.IndexerMinimal{ID: a.indexer.ID, Name: a.indexer.Name, Identifier: a.indexer.Identifier})
rls.Protocol = domain.ReleaseProtocol(a.indexer.Protocol)

// on lines matched
Expand Down
12 changes: 9 additions & 3 deletions internal/database/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ func (r *FeedRepo) FindByID(ctx context.Context, id int) (*domain.Feed, error) {
queryBuilder := r.db.squirrel.
Select(
"f.id",
"i.id",
"i.identifier",
"i.name",
"f.name",
"f.type",
"f.enabled",
Expand Down Expand Up @@ -64,7 +66,7 @@ func (r *FeedRepo) FindByID(ctx context.Context, id int) (*domain.Feed, error) {

var apiKey, cookie, settings sql.NullString

if err := row.Scan(&f.ID, &f.Indexer, &f.Name, &f.Type, &f.Enabled, &f.URL, &f.Interval, &f.Timeout, &f.MaxAge, &apiKey, &cookie, &settings, &f.CreatedAt, &f.UpdatedAt); err != nil {
if err := row.Scan(&f.ID, &f.Indexer.ID, &f.Indexer.Identifier, &f.Indexer.Name, &f.Name, &f.Type, &f.Enabled, &f.URL, &f.Interval, &f.Timeout, &f.MaxAge, &apiKey, &cookie, &settings, &f.CreatedAt, &f.UpdatedAt); err != nil {
return nil, errors.Wrap(err, "error scanning row")
}

Expand All @@ -87,7 +89,9 @@ func (r *FeedRepo) FindByIndexerIdentifier(ctx context.Context, indexer string)
queryBuilder := r.db.squirrel.
Select(
"f.id",
"i.id",
"i.identifier",
"i.name",
"f.name",
"f.type",
"f.enabled",
Expand Down Expand Up @@ -119,7 +123,7 @@ func (r *FeedRepo) FindByIndexerIdentifier(ctx context.Context, indexer string)

var apiKey, cookie, settings sql.NullString

if err := row.Scan(&f.ID, &f.Indexer, &f.Name, &f.Type, &f.Enabled, &f.URL, &f.Interval, &f.Timeout, &f.MaxAge, &apiKey, &cookie, &settings, &f.CreatedAt, &f.UpdatedAt); err != nil {
if err := row.Scan(&f.ID, &f.Indexer.ID, &f.Indexer.Identifier, &f.Indexer.Name, &f.Name, &f.Type, &f.Enabled, &f.URL, &f.Interval, &f.Timeout, &f.MaxAge, &apiKey, &cookie, &settings, &f.CreatedAt, &f.UpdatedAt); err != nil {
return nil, errors.Wrap(err, "error scanning row")
}

Expand All @@ -140,7 +144,9 @@ func (r *FeedRepo) Find(ctx context.Context) ([]domain.Feed, error) {
queryBuilder := r.db.squirrel.
Select(
"f.id",
"i.id",
"i.identifier",
"i.name",
"f.name",
"f.type",
"f.enabled",
Expand Down Expand Up @@ -179,7 +185,7 @@ func (r *FeedRepo) Find(ctx context.Context) ([]domain.Feed, error) {
var apiKey, cookie, lastRunData, settings sql.NullString
var lastRun sql.NullTime

if err := rows.Scan(&f.ID, &f.Indexer, &f.Name, &f.Type, &f.Enabled, &f.URL, &f.Interval, &f.Timeout, &f.MaxAge, &apiKey, &cookie, &lastRun, &lastRunData, &settings, &f.CreatedAt, &f.UpdatedAt); err != nil {
if err := rows.Scan(&f.ID, &f.Indexer.ID, &f.Indexer.Identifier, &f.Indexer.Name, &f.Name, &f.Type, &f.Enabled, &f.URL, &f.Interval, &f.Timeout, &f.MaxAge, &apiKey, &cookie, &lastRun, &lastRunData, &settings, &f.CreatedAt, &f.UpdatedAt); err != nil {
return nil, errors.Wrap(err, "error scanning row")
}

Expand Down
1 change: 0 additions & 1 deletion internal/database/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func (r *IndexerRepo) FindByID(ctx context.Context, id int) (*domain.Indexer, er
i.Settings = settingsMap

return &i, nil

}

func (r *IndexerRepo) FindByFilterID(ctx context.Context, id int) ([]domain.Indexer, error) {
Expand Down
6 changes: 3 additions & 3 deletions internal/database/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (repo *ReleaseRepo) Store(ctx context.Context, r *domain.Release) error {
queryBuilder := repo.db.squirrel.
Insert("release").
Columns("filter_status", "rejections", "indexer", "filter", "protocol", "implementation", "timestamp", "group_id", "torrent_id", "info_url", "download_url", "torrent_name", "size", "title", "category", "season", "episode", "year", "resolution", "source", "codec", "container", "hdr", "release_group", "proper", "repack", "website", "type", "origin", "tags", "uploader", "pre_time", "filter_id").
Values(r.FilterStatus, pq.Array(r.Rejections), r.Indexer, r.FilterName, r.Protocol, r.Implementation, r.Timestamp.Format(time.RFC3339), r.GroupID, r.TorrentID, r.InfoURL, r.DownloadURL, r.TorrentName, r.Size, r.Title, r.Category, r.Season, r.Episode, r.Year, r.Resolution, r.Source, codecStr, r.Container, hdrStr, r.Group, r.Proper, r.Repack, r.Website, r.Type, r.Origin, pq.Array(r.Tags), r.Uploader, r.PreTime, r.FilterID).
Values(r.FilterStatus, pq.Array(r.Rejections), r.Indexer.Identifier, r.FilterName, r.Protocol, r.Implementation, r.Timestamp.Format(time.RFC3339), r.GroupID, r.TorrentID, r.InfoURL, r.DownloadURL, r.TorrentName, r.Size, r.Title, r.Category, r.Season, r.Episode, r.Year, r.Resolution, r.Source, codecStr, r.Container, hdrStr, r.Group, r.Proper, r.Repack, r.Website, r.Type, r.Origin, pq.Array(r.Tags), r.Uploader, r.PreTime, r.FilterID).
Suffix("RETURNING id").RunWith(repo.db.handler)

// return values
Expand Down Expand Up @@ -291,7 +291,7 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain
continue
}

rls.Indexer = rlsindexer.String
rls.Indexer.Identifier = rlsindexer.String
rls.FilterName = rlsfilter.String
rls.ActionStatus = make([]domain.ReleaseActionStatus, 0)
rls.InfoURL = infoUrl.String
Expand Down Expand Up @@ -443,7 +443,7 @@ func (repo *ReleaseRepo) Get(ctx context.Context, req *domain.GetReleaseRequest)
return nil, errors.Wrap(err, "error scanning row")
}

rls.Indexer = indexerName.String
rls.Indexer.Identifier = indexerName.String
rls.FilterName = filterName.String
rls.FilterID = int(filterId.Int64)
rls.ActionStatus = make([]domain.ReleaseActionStatus, 0)
Expand Down
10 changes: 7 additions & 3 deletions internal/database/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ import (

func getMockRelease() *domain.Release {
return &domain.Release{
FilterStatus: domain.ReleaseStatusFilterApproved,
Rejections: []string{"test", "not-a-match"},
Indexer: "BTN",
FilterStatus: domain.ReleaseStatusFilterApproved,
Rejections: []string{"test", "not-a-match"},
Indexer: domain.IndexerMinimal{
ID: 0,
Name: "BTN",
Identifier: "btn",
},
FilterName: "ExampleFilter",
Protocol: domain.ReleaseProtocolTorrent,
Implementation: domain.ReleaseImplementationIRC,
Expand Down
3 changes: 1 addition & 2 deletions internal/domain/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type FeedRepo interface {
type Feed struct {
ID int `json:"id"`
Name string `json:"name"`
Indexer string `json:"indexer"`
Indexer IndexerMinimal `json:"indexer"`
Type string `json:"type"`
Enabled bool `json:"enabled"`
URL string `json:"url"`
Expand All @@ -50,7 +50,6 @@ type Feed struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
IndexerID int `json:"indexer_id,omitempty"`
Indexerr FeedIndexer `json:"-"`
LastRun time.Time `json:"last_run"`
LastRunData string `json:"last_run_data"`
NextRun time.Time `json:"next_run"`
Expand Down
6 changes: 6 additions & 0 deletions internal/domain/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ type Indexer struct {
Settings map[string]string `json:"settings,omitempty"`
}

type IndexerMinimal struct {
ID int `json:"id"`
Name string `json:"name"`
Identifier string `json:"identifier"`
}

type IndexerDefinition struct {
ID int `json:"id,omitempty"`
Name string `json:"name"`
Expand Down
12 changes: 6 additions & 6 deletions internal/domain/indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func TestIRCParserGazelleGames_Parse(t *testing.T) {
{
name: "",
args: args{
rls: NewRelease("ggn"),
rls: NewRelease(IndexerMinimal{0, "GazelleGames", "ggn"}),
vars: map[string]string{
"torrentName": "Trouble.in.Paradise-GROUP in Trouble in Paradise",
},
Expand All @@ -267,7 +267,7 @@ func TestIRCParserGazelleGames_Parse(t *testing.T) {
{
name: "",
args: args{
rls: NewRelease("ggn"),
rls: NewRelease(IndexerMinimal{0, "GazelleGames", "ggn"}),
vars: map[string]string{
"torrentName": "F.I.L.F. Game Walkthrough v.0.18 in F.I.L.F.",
},
Expand All @@ -280,7 +280,7 @@ func TestIRCParserGazelleGames_Parse(t *testing.T) {
{
name: "",
args: args{
rls: NewRelease("ggn"),
rls: NewRelease(IndexerMinimal{0, "GazelleGames", "ggn"}),
vars: map[string]string{
"torrentName": "Ni no Kuni: Dominion of the Dark Djinn in Ni no Kuni: Dominion of the Dark Djinn",
},
Expand All @@ -293,7 +293,7 @@ func TestIRCParserGazelleGames_Parse(t *testing.T) {
{
name: "",
args: args{
rls: NewRelease("ggn"),
rls: NewRelease(IndexerMinimal{0, "GazelleGames", "ggn"}),
vars: map[string]string{
"torrentName": "Year 2 Remastered by Insaneintherainmusic",
"category": "OST",
Expand Down Expand Up @@ -332,7 +332,7 @@ func TestIRCParserOrpheus_Parse(t *testing.T) {
{
name: "",
args: args{
rls: NewRelease("ops"),
rls: NewRelease(IndexerMinimal{0, "Orpheus", "ops"}),
vars: map[string]string{
"torrentName": "Busta Rhymes – BEACH BALL (feat. BIA) – [2023] [Single] WEB/FLAC/24bit Lossless",
"title": "Busta Rhymes – BEACH BALL (feat. BIA)",
Expand All @@ -348,7 +348,7 @@ func TestIRCParserOrpheus_Parse(t *testing.T) {
{
name: "",
args: args{
rls: NewRelease("ops"),
rls: NewRelease(IndexerMinimal{0, "Orpheus", "ops"}),
vars: map[string]string{
"torrentName": "Busta Rhymes – BEACH BALL (feat. BIA) – [2023] [Single] CD/FLAC/Lossless",
"title": "Busta Rhymes – BEACH BALL (feat. BIA)",
Expand Down
6 changes: 5 additions & 1 deletion internal/domain/macros.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Macro struct {
DownloadUrl string
InfoUrl string
Indexer string
IndexerName string
IndexerIdentifier string
Title string
Type string
Category string
Expand Down Expand Up @@ -67,7 +69,9 @@ func NewMacro(release Release) Macro {
GroupID: release.GroupID,
InfoUrl: release.InfoURL,
DownloadUrl: release.DownloadURL,
Indexer: release.Indexer,
Indexer: release.Indexer.Identifier,
IndexerName: release.Indexer.Name,
IndexerIdentifier: release.Indexer.Identifier,
Title: release.Title,
Type: release.Type,
Category: release.Category,
Expand Down

0 comments on commit 3c3b47f

Please sign in to comment.