mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 16:59:12 +00:00
feat: improve release parsing and filtering (#257)
* feat(releases): improve parsing * refactor: extend filtering add more tests * feat: improve macro * feat: add and remove fields * feat: add freeleech percent to bonus * feat: filter by origin
This commit is contained in:
parent
bb62e724a1
commit
e6c151a029
26 changed files with 3210 additions and 3201 deletions
|
@ -2,6 +2,7 @@ package action
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
|
@ -14,6 +15,7 @@ type Macro struct {
|
|||
TorrentHash string
|
||||
TorrentUrl string
|
||||
Indexer string
|
||||
Title string
|
||||
Resolution string
|
||||
Source string
|
||||
HDR string
|
||||
|
@ -36,9 +38,10 @@ func NewMacro(release domain.Release) Macro {
|
|||
TorrentPathName: release.TorrentTmpFile,
|
||||
TorrentHash: release.TorrentHash,
|
||||
Indexer: release.Indexer,
|
||||
Title: release.Title,
|
||||
Resolution: release.Resolution,
|
||||
Source: release.Source,
|
||||
HDR: release.HDR,
|
||||
HDR: strings.Join(release.HDR, ", "),
|
||||
Season: release.Season,
|
||||
Episode: release.Episode,
|
||||
Year: currentTime.Year(),
|
||||
|
|
|
@ -133,7 +133,7 @@ func TestMacros_Parse(t *testing.T) {
|
|||
TorrentURL: "https://some.site/download/fakeid",
|
||||
Indexer: "mock1",
|
||||
Resolution: "2160p",
|
||||
HDR: "DV",
|
||||
HDR: []string{"DV"},
|
||||
},
|
||||
args: args{text: "movies-{{.Resolution}}{{ if .HDR }}-{{.HDR}}{{ end }}"},
|
||||
want: "movies-2160p-DV",
|
||||
|
@ -146,7 +146,7 @@ func TestMacros_Parse(t *testing.T) {
|
|||
TorrentURL: "https://some.site/download/fakeid",
|
||||
Indexer: "mock1",
|
||||
Resolution: "2160p",
|
||||
HDR: "HDR",
|
||||
HDR: []string{"HDR"},
|
||||
},
|
||||
args: args{text: "movies-{{.Resolution}}{{ if .HDR }}-{{.HDR}}{{ end }}"},
|
||||
want: "movies-2160p-HDR",
|
||||
|
|
|
@ -98,21 +98,21 @@ func (a *announceProcessor) processQueue(queue chan string) {
|
|||
continue
|
||||
}
|
||||
|
||||
newRelease, err := domain.NewRelease(a.indexer.Identifier, "")
|
||||
rls, err := domain.NewRelease(a.indexer.Identifier)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not create new release")
|
||||
continue
|
||||
}
|
||||
|
||||
// on lines matched
|
||||
err = a.onLinesMatched(a.indexer, tmpVars, newRelease)
|
||||
err = a.onLinesMatched(a.indexer, tmpVars, rls)
|
||||
if err != nil {
|
||||
log.Debug().Msgf("error match line: %v", "")
|
||||
continue
|
||||
}
|
||||
|
||||
// process release in a new go routine
|
||||
go a.releaseSvc.Process(newRelease)
|
||||
go a.releaseSvc.Process(rls)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,24 +166,24 @@ func (a *announceProcessor) parseExtract(pattern string, vars []string, tmpVars
|
|||
}
|
||||
|
||||
// onLinesMatched process vars into release
|
||||
func (a *announceProcessor) onLinesMatched(def domain.IndexerDefinition, vars map[string]string, release *domain.Release) error {
|
||||
func (a *announceProcessor) onLinesMatched(def domain.IndexerDefinition, vars map[string]string, rls *domain.Release) error {
|
||||
var err error
|
||||
|
||||
err = release.MapVars(def, vars)
|
||||
err = rls.MapVars(def, vars)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("announce: could not map vars for release")
|
||||
return err
|
||||
}
|
||||
|
||||
// parse fields
|
||||
err = release.Parse()
|
||||
err = rls.ParseString(rls.TorrentName)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("announce: could not parse release")
|
||||
return err
|
||||
}
|
||||
|
||||
// parse torrentUrl
|
||||
err = release.ParseTorrentUrl(def.Parse.Match.TorrentURL, vars, def.SettingsMap, def.Parse.Match.Encode)
|
||||
err = def.Parse.ParseTorrentUrl(vars, def.SettingsMap, rls)
|
||||
if err != nil {
|
||||
log.Error().Stack().Err(err).Msg("announce: could not parse torrent url")
|
||||
return err
|
||||
|
@ -235,41 +235,6 @@ func (a *announceProcessor) processTorrentUrl(match string, vars map[string]stri
|
|||
return b.String(), nil
|
||||
}
|
||||
|
||||
func split(r rune) bool {
|
||||
return r == ' ' || r == '.'
|
||||
}
|
||||
|
||||
func Splitter(s string, splits string) []string {
|
||||
m := make(map[rune]int)
|
||||
for _, r := range splits {
|
||||
m[r] = 1
|
||||
}
|
||||
|
||||
splitter := func(r rune) bool {
|
||||
return m[r] == 1
|
||||
}
|
||||
|
||||
return strings.FieldsFunc(s, splitter)
|
||||
}
|
||||
|
||||
func canonicalizeString(s string) []string {
|
||||
//a := strings.FieldsFunc(s, split)
|
||||
a := Splitter(s, " .")
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func cleanReleaseName(input string) string {
|
||||
// Make a Regex to say we only want letters and numbers
|
||||
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
||||
if err != nil {
|
||||
//log.Fatal(err)
|
||||
}
|
||||
processedString := reg.ReplaceAllString(input, " ")
|
||||
|
||||
return processedString
|
||||
}
|
||||
|
||||
func removeElement(s []string, i int) ([]string, error) {
|
||||
// s is [1,2,3,4,5,6], i is 2
|
||||
|
||||
|
|
|
@ -3,10 +3,9 @@ package database
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/lib/pq"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
|
@ -100,6 +99,8 @@ func (r *FilterRepo) FindByID(ctx context.Context, filterID int) (*domain.Filter
|
|||
"containers",
|
||||
"match_hdr",
|
||||
"except_hdr",
|
||||
"match_other",
|
||||
"except_other",
|
||||
"years",
|
||||
"artists",
|
||||
"albums",
|
||||
|
@ -117,6 +118,7 @@ func (r *FilterRepo) FindByID(ctx context.Context, filterID int) (*domain.Filter
|
|||
"except_uploaders",
|
||||
"tags",
|
||||
"except_tags",
|
||||
"origins",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
).
|
||||
|
@ -140,7 +142,7 @@ func (r *FilterRepo) FindByID(ctx context.Context, filterID int) (*domain.Filter
|
|||
var useRegex, scene, freeleech, hasLog, hasCue, perfectFlac sql.NullBool
|
||||
var delay, logScore sql.NullInt32
|
||||
|
||||
if err := row.Scan(&f.ID, &f.Enabled, &f.Name, &minSize, &maxSize, &delay, &f.Priority, &matchReleases, &exceptReleases, &useRegex, &matchReleaseGroups, &exceptReleaseGroups, &scene, &freeleech, &freeleechPercent, &shows, &seasons, &episodes, pq.Array(&f.Resolutions), pq.Array(&f.Codecs), pq.Array(&f.Sources), pq.Array(&f.Containers), pq.Array(&f.MatchHDR), pq.Array(&f.ExceptHDR), &years, &artists, &albums, pq.Array(&f.MatchReleaseTypes), pq.Array(&f.Formats), pq.Array(&f.Quality), pq.Array(&f.Media), &logScore, &hasLog, &hasCue, &perfectFlac, &matchCategories, &exceptCategories, &matchUploaders, &exceptUploaders, &tags, &exceptTags, &f.CreatedAt, &f.UpdatedAt); err != nil {
|
||||
if err := row.Scan(&f.ID, &f.Enabled, &f.Name, &minSize, &maxSize, &delay, &f.Priority, &matchReleases, &exceptReleases, &useRegex, &matchReleaseGroups, &exceptReleaseGroups, &scene, &freeleech, &freeleechPercent, &shows, &seasons, &episodes, pq.Array(&f.Resolutions), pq.Array(&f.Codecs), pq.Array(&f.Sources), pq.Array(&f.Containers), pq.Array(&f.MatchHDR), pq.Array(&f.ExceptHDR), pq.Array(&f.MatchOther), pq.Array(&f.ExceptOther), &years, &artists, &albums, pq.Array(&f.MatchReleaseTypes), pq.Array(&f.Formats), pq.Array(&f.Quality), pq.Array(&f.Media), &logScore, &hasLog, &hasCue, &perfectFlac, &matchCategories, &exceptCategories, &matchUploaders, &exceptUploaders, &tags, &exceptTags, pq.Array(&f.Origins), &f.CreatedAt, &f.UpdatedAt); err != nil {
|
||||
log.Error().Stack().Err(err).Msgf("filter.findByID: %v : error scanning row", filterID)
|
||||
return nil, err
|
||||
}
|
||||
|
@ -204,6 +206,8 @@ func (r *FilterRepo) FindByIndexerIdentifier(indexer string) ([]domain.Filter, e
|
|||
"f.containers",
|
||||
"f.match_hdr",
|
||||
"f.except_hdr",
|
||||
"f.match_other",
|
||||
"f.except_other",
|
||||
"f.years",
|
||||
"f.artists",
|
||||
"f.albums",
|
||||
|
@ -221,6 +225,7 @@ func (r *FilterRepo) FindByIndexerIdentifier(indexer string) ([]domain.Filter, e
|
|||
"f.except_uploaders",
|
||||
"f.tags",
|
||||
"f.except_tags",
|
||||
"f.origins",
|
||||
"f.created_at",
|
||||
"f.updated_at",
|
||||
).
|
||||
|
@ -254,7 +259,7 @@ func (r *FilterRepo) FindByIndexerIdentifier(indexer string) ([]domain.Filter, e
|
|||
var useRegex, scene, freeleech, hasLog, hasCue, perfectFlac sql.NullBool
|
||||
var delay, logScore sql.NullInt32
|
||||
|
||||
if err := rows.Scan(&f.ID, &f.Enabled, &f.Name, &minSize, &maxSize, &delay, &f.Priority, &matchReleases, &exceptReleases, &useRegex, &matchReleaseGroups, &exceptReleaseGroups, &scene, &freeleech, &freeleechPercent, &shows, &seasons, &episodes, pq.Array(&f.Resolutions), pq.Array(&f.Codecs), pq.Array(&f.Sources), pq.Array(&f.Containers), pq.Array(&f.MatchHDR), pq.Array(&f.ExceptHDR), &years, &artists, &albums, pq.Array(&f.MatchReleaseTypes), pq.Array(&f.Formats), pq.Array(&f.Quality), pq.Array(&f.Media), &logScore, &hasLog, &hasCue, &perfectFlac, &matchCategories, &exceptCategories, &matchUploaders, &exceptUploaders, &tags, &exceptTags, &f.CreatedAt, &f.UpdatedAt); err != nil {
|
||||
if err := rows.Scan(&f.ID, &f.Enabled, &f.Name, &minSize, &maxSize, &delay, &f.Priority, &matchReleases, &exceptReleases, &useRegex, &matchReleaseGroups, &exceptReleaseGroups, &scene, &freeleech, &freeleechPercent, &shows, &seasons, &episodes, pq.Array(&f.Resolutions), pq.Array(&f.Codecs), pq.Array(&f.Sources), pq.Array(&f.Containers), pq.Array(&f.MatchHDR), pq.Array(&f.ExceptHDR), pq.Array(&f.MatchOther), pq.Array(&f.ExceptOther), &years, &artists, &albums, pq.Array(&f.MatchReleaseTypes), pq.Array(&f.Formats), pq.Array(&f.Quality), pq.Array(&f.Media), &logScore, &hasLog, &hasCue, &perfectFlac, &matchCategories, &exceptCategories, &matchUploaders, &exceptUploaders, &tags, &exceptTags, pq.Array(&f.Origins), &f.CreatedAt, &f.UpdatedAt); err != nil {
|
||||
log.Error().Stack().Err(err).Msg("filter.findByIndexerIdentifier: error scanning row")
|
||||
return nil, err
|
||||
}
|
||||
|
@ -320,6 +325,8 @@ func (r *FilterRepo) Store(ctx context.Context, filter domain.Filter) (*domain.F
|
|||
"containers",
|
||||
"match_hdr",
|
||||
"except_hdr",
|
||||
"match_other",
|
||||
"except_other",
|
||||
"years",
|
||||
"match_categories",
|
||||
"except_categories",
|
||||
|
@ -337,6 +344,7 @@ func (r *FilterRepo) Store(ctx context.Context, filter domain.Filter) (*domain.F
|
|||
"has_log",
|
||||
"has_cue",
|
||||
"perfect_flac",
|
||||
"origins",
|
||||
).
|
||||
Values(
|
||||
filter.Name,
|
||||
|
@ -362,6 +370,8 @@ func (r *FilterRepo) Store(ctx context.Context, filter domain.Filter) (*domain.F
|
|||
pq.Array(filter.Containers),
|
||||
pq.Array(filter.MatchHDR),
|
||||
pq.Array(filter.ExceptHDR),
|
||||
pq.Array(filter.MatchOther),
|
||||
pq.Array(filter.ExceptOther),
|
||||
filter.Years,
|
||||
filter.MatchCategories,
|
||||
filter.ExceptCategories,
|
||||
|
@ -379,6 +389,7 @@ func (r *FilterRepo) Store(ctx context.Context, filter domain.Filter) (*domain.F
|
|||
filter.Log,
|
||||
filter.Cue,
|
||||
filter.PerfectFlac,
|
||||
pq.Array(filter.Origins),
|
||||
).
|
||||
Suffix("RETURNING id").RunWith(r.db.handler)
|
||||
|
||||
|
@ -424,6 +435,8 @@ func (r *FilterRepo) Update(ctx context.Context, filter domain.Filter) (*domain.
|
|||
Set("containers", pq.Array(filter.Containers)).
|
||||
Set("match_hdr", pq.Array(filter.MatchHDR)).
|
||||
Set("except_hdr", pq.Array(filter.ExceptHDR)).
|
||||
Set("match_other", pq.Array(filter.MatchOther)).
|
||||
Set("except_other", pq.Array(filter.ExceptOther)).
|
||||
Set("years", filter.Years).
|
||||
Set("match_categories", filter.MatchCategories).
|
||||
Set("except_categories", filter.ExceptCategories).
|
||||
|
@ -441,6 +454,7 @@ func (r *FilterRepo) Update(ctx context.Context, filter domain.Filter) (*domain.
|
|||
Set("has_log", filter.Log).
|
||||
Set("has_cue", filter.Cue).
|
||||
Set("perfect_flac", filter.PerfectFlac).
|
||||
Set("origins", pq.Array(filter.Origins)).
|
||||
Set("updated_at", time.Now().Format(time.RFC3339)).
|
||||
Where("id = ?", filter.ID)
|
||||
|
||||
|
@ -596,14 +610,14 @@ func (r *FilterRepo) Delete(ctx context.Context, filterID int) error {
|
|||
}
|
||||
|
||||
// Split string to slice. We store comma separated strings and convert to slice
|
||||
func stringToSlice(str string) []string {
|
||||
if str == "" {
|
||||
return []string{}
|
||||
} else if !strings.Contains(str, ",") {
|
||||
return []string{str}
|
||||
}
|
||||
|
||||
split := strings.Split(str, ",")
|
||||
|
||||
return split
|
||||
}
|
||||
//func stringToSlice(str string) []string {
|
||||
// if str == "" {
|
||||
// return []string{}
|
||||
// } else if !strings.Contains(str, ",") {
|
||||
// return []string{str}
|
||||
// }
|
||||
//
|
||||
// split := strings.Split(str, ",")
|
||||
//
|
||||
// return split
|
||||
//}
|
||||
|
|
|
@ -81,6 +81,8 @@ CREATE TABLE filter
|
|||
containers TEXT [] DEFAULT '{}' NOT NULL,
|
||||
match_hdr TEXT [] DEFAULT '{}',
|
||||
except_hdr TEXT [] DEFAULT '{}',
|
||||
match_other TEXT [] DEFAULT '{}',
|
||||
except_other TEXT [] DEFAULT '{}',
|
||||
years TEXT,
|
||||
artists TEXT,
|
||||
albums TEXT,
|
||||
|
@ -99,6 +101,7 @@ CREATE TABLE filter
|
|||
except_uploaders TEXT,
|
||||
tags TEXT,
|
||||
except_tags TEXT,
|
||||
origins TEXT [] DEFAULT '{}' NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
@ -169,7 +172,6 @@ CREATE TABLE "release"
|
|||
torrent_id TEXT,
|
||||
torrent_name TEXT,
|
||||
size INTEGER,
|
||||
raw TEXT,
|
||||
title TEXT,
|
||||
category TEXT,
|
||||
season INTEGER,
|
||||
|
@ -180,28 +182,13 @@ CREATE TABLE "release"
|
|||
codec TEXT,
|
||||
container TEXT,
|
||||
hdr TEXT,
|
||||
audio TEXT,
|
||||
release_group TEXT,
|
||||
region TEXT,
|
||||
language TEXT,
|
||||
edition TEXT,
|
||||
unrated BOOLEAN,
|
||||
hybrid BOOLEAN,
|
||||
group TEXT,
|
||||
proper BOOLEAN,
|
||||
repack BOOLEAN,
|
||||
website TEXT,
|
||||
artists TEXT [] DEFAULT '{}' NOT NULL,
|
||||
type TEXT,
|
||||
format TEXT,
|
||||
quality TEXT,
|
||||
log_score INTEGER,
|
||||
has_log BOOLEAN,
|
||||
has_cue BOOLEAN,
|
||||
is_scene BOOLEAN,
|
||||
origin TEXT,
|
||||
tags TEXT [] DEFAULT '{}' NOT NULL,
|
||||
freeleech BOOLEAN,
|
||||
freeleech_percent INTEGER,
|
||||
uploader TEXT,
|
||||
pre_time TEXT
|
||||
);
|
||||
|
@ -595,6 +582,68 @@ ALTER TABLE release_action_status_dg_tmp
|
|||
ALTER TABLE indexer
|
||||
ADD COLUMN implementation TEXT;
|
||||
`,
|
||||
`
|
||||
ALTER TABLE release
|
||||
RENAME COLUMN release_group TO "group";
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN raw;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN audio;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN region;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN language;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN edition;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN unrated;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN hybrid;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN artists;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN format;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN quality;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN log_score;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN has_log;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN has_cue;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN is_scene;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN freeleech;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN freeleech_percent;
|
||||
|
||||
ALTER TABLE "filter"
|
||||
ADD COLUMN origins TEXT [] DEFAULT '{}';
|
||||
`,
|
||||
`
|
||||
ALTER TABLE "filter"
|
||||
ADD COLUMN match_other TEXT [] DEFAULT '{}';
|
||||
|
||||
ALTER TABLE "filter"
|
||||
ADD COLUMN except_other TEXT [] DEFAULT '{}';
|
||||
`,
|
||||
}
|
||||
|
||||
const postgresSchema = `
|
||||
|
@ -678,6 +727,8 @@ CREATE TABLE filter
|
|||
containers TEXT [] DEFAULT '{}' NOT NULL,
|
||||
match_hdr TEXT [] DEFAULT '{}',
|
||||
except_hdr TEXT [] DEFAULT '{}',
|
||||
match_other TEXT [] DEFAULT '{}',
|
||||
except_other TEXT [] DEFAULT '{}',
|
||||
years TEXT,
|
||||
artists TEXT,
|
||||
albums TEXT,
|
||||
|
@ -696,6 +747,7 @@ CREATE TABLE filter
|
|||
except_uploaders TEXT,
|
||||
tags TEXT,
|
||||
except_tags TEXT,
|
||||
origins TEXT [] DEFAULT '{}',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
@ -926,4 +978,66 @@ var postgresMigrations = []string{
|
|||
ALTER TABLE indexer
|
||||
ADD COLUMN implementation TEXT;
|
||||
`,
|
||||
`
|
||||
ALTER TABLE release
|
||||
RENAME COLUMN release_group TO "group";
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN raw;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN audio;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN region;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN language;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN edition;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN unrated;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN hybrid;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN artists;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN format;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN quality;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN log_score;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN has_log;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN has_cue;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN is_scene;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN freeleech;
|
||||
|
||||
ALTER TABLE release
|
||||
DROP COLUMN freeleech_percent;
|
||||
|
||||
ALTER TABLE "filter"
|
||||
ADD COLUMN origins TEXT [] DEFAULT '{}';
|
||||
`,
|
||||
`
|
||||
ALTER TABLE "filter"
|
||||
ADD COLUMN match_other TEXT [] DEFAULT '{}';
|
||||
|
||||
ALTER TABLE "filter"
|
||||
ADD COLUMN except_other TEXT [] DEFAULT '{}';
|
||||
`,
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package database
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strings"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/autobrr/autobrr/internal/domain"
|
||||
"github.com/lib/pq"
|
||||
|
@ -18,10 +20,13 @@ func NewReleaseRepo(db *DB) domain.ReleaseRepo {
|
|||
}
|
||||
|
||||
func (repo *ReleaseRepo) Store(ctx context.Context, r *domain.Release) (*domain.Release, error) {
|
||||
codecStr := strings.Join(r.Codec, ",")
|
||||
hdrStr := strings.Join(r.HDR, ",")
|
||||
|
||||
queryBuilder := repo.db.squirrel.
|
||||
Insert("release").
|
||||
Columns("filter_status", "rejections", "indexer", "filter", "protocol", "implementation", "timestamp", "group_id", "torrent_id", "torrent_name", "size", "raw", "title", "category", "season", "episode", "year", "resolution", "source", "codec", "container", "hdr", "audio", "release_group", "region", "language", "edition", "unrated", "hybrid", "proper", "repack", "website", "artists", "type", "format", "quality", "log_score", "has_log", "has_cue", "is_scene", "origin", "tags", "freeleech", "freeleech_percent", "uploader", "pre_time").
|
||||
Values(r.FilterStatus, pq.Array(r.Rejections), r.Indexer, r.FilterName, r.Protocol, r.Implementation, r.Timestamp, r.GroupID, r.TorrentID, r.TorrentName, r.Size, r.Raw, r.Title, r.Category, r.Season, r.Episode, r.Year, r.Resolution, r.Source, r.Codec, r.Container, r.HDR, r.Audio, r.Group, r.Region, r.Language, r.Edition, r.Unrated, r.Hybrid, r.Proper, r.Repack, r.Website, pq.Array(r.Artists), r.Type, r.Format, r.Quality, r.LogScore, r.HasLog, r.HasCue, r.IsScene, r.Origin, pq.Array(r.Tags), r.Freeleech, r.FreeleechPercent, r.Uploader, r.PreTime).
|
||||
Columns("filter_status", "rejections", "indexer", "filter", "protocol", "implementation", "timestamp", "group_id", "torrent_id", "torrent_name", "size", "title", "category", "season", "episode", "year", "resolution", "source", "codec", "container", "hdr", "group", "proper", "repack", "website", "type", "origin", "tags", "uploader", "pre_time").
|
||||
Values(r.FilterStatus, pq.Array(r.Rejections), r.Indexer, r.FilterName, r.Protocol, r.Implementation, r.Timestamp, r.GroupID, r.TorrentID, 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).
|
||||
Suffix("RETURNING id").RunWith(repo.db.handler)
|
||||
|
||||
// return values
|
||||
|
|
|
@ -2,7 +2,13 @@ package domain
|
|||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/autobrr/autobrr/pkg/wildcard"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
)
|
||||
|
||||
/*
|
||||
|
@ -39,7 +45,7 @@ type Filter struct {
|
|||
MatchReleaseGroups string `json:"match_release_groups"`
|
||||
ExceptReleaseGroups string `json:"except_release_groups"`
|
||||
Scene bool `json:"scene"`
|
||||
Origins string `json:"origins"`
|
||||
Origins []string `json:"origins"`
|
||||
Freeleech bool `json:"freeleech"`
|
||||
FreeleechPercent string `json:"freeleech_percent"`
|
||||
Shows string `json:"shows"`
|
||||
|
@ -51,6 +57,8 @@ type Filter struct {
|
|||
Containers []string `json:"containers"`
|
||||
MatchHDR []string `json:"match_hdr"`
|
||||
ExceptHDR []string `json:"except_hdr"`
|
||||
MatchOther []string `json:"match_other"`
|
||||
ExceptOther []string `json:"except_other"`
|
||||
Years string `json:"years"`
|
||||
Artists string `json:"artists"`
|
||||
Albums string `json:"albums"`
|
||||
|
@ -74,3 +82,433 @@ type Filter struct {
|
|||
Actions []*Action `json:"actions"`
|
||||
Indexers []Indexer `json:"indexers"`
|
||||
}
|
||||
|
||||
func (f Filter) CheckFilter(r *Release) ([]string, bool) {
|
||||
// reset rejections first to clean previous checks
|
||||
r.resetRejections()
|
||||
|
||||
if f.Freeleech && r.Freeleech != f.Freeleech {
|
||||
r.addRejection("wanted: freeleech")
|
||||
}
|
||||
|
||||
if f.FreeleechPercent != "" && !checkFreeleechPercent(r.FreeleechPercent, f.FreeleechPercent) {
|
||||
r.addRejectionF("freeleech percent not matching. got: %v want: %v", r.FreeleechPercent, f.FreeleechPercent)
|
||||
}
|
||||
|
||||
if len(f.Origins) > 0 && !containsSlice(r.Origin, f.Origins) {
|
||||
r.addRejectionF("origin not matching. got: %v want: %v", r.Origin, f.Origins)
|
||||
}
|
||||
|
||||
// title is the parsed title
|
||||
if f.Shows != "" && !contains(r.Title, f.Shows) {
|
||||
r.addRejectionF("shows not matching. got: %v want: %v", r.Title, f.Shows)
|
||||
}
|
||||
|
||||
if f.Seasons != "" && !containsIntStrings(r.Season, f.Seasons) {
|
||||
r.addRejectionF("season not matching. got: %d want: %v", r.Season, f.Seasons)
|
||||
}
|
||||
|
||||
if f.Episodes != "" && !containsIntStrings(r.Episode, f.Episodes) {
|
||||
r.addRejectionF("episodes not matching. got: %d want: %v", r.Episode, f.Episodes)
|
||||
}
|
||||
|
||||
// matchRelease
|
||||
// TODO allow to match against regex
|
||||
if f.MatchReleases != "" && !containsFuzzy(r.TorrentName, f.MatchReleases) {
|
||||
r.addRejectionF("match release not matching. got: %v want: %v", r.TorrentName, f.MatchReleases)
|
||||
}
|
||||
|
||||
if f.ExceptReleases != "" && containsFuzzy(r.TorrentName, f.ExceptReleases) {
|
||||
r.addRejectionF("except releases: unwanted release. got: %v want: %v", r.TorrentName, f.ExceptReleases)
|
||||
}
|
||||
|
||||
if f.MatchReleaseGroups != "" && !contains(r.Group, f.MatchReleaseGroups) {
|
||||
r.addRejectionF("release groups not matching. got: %v want: %v", r.Group, f.MatchReleaseGroups)
|
||||
}
|
||||
|
||||
if f.ExceptReleaseGroups != "" && contains(r.Group, f.ExceptReleaseGroups) {
|
||||
r.addRejectionF("unwanted release group. got: %v unwanted: %v", r.Group, f.ExceptReleaseGroups)
|
||||
}
|
||||
|
||||
if f.MatchUploaders != "" && !contains(r.Uploader, f.MatchUploaders) {
|
||||
r.addRejectionF("uploaders not matching. got: %v want: %v", r.Uploader, f.MatchUploaders)
|
||||
}
|
||||
|
||||
if f.ExceptUploaders != "" && contains(r.Uploader, f.ExceptUploaders) {
|
||||
r.addRejectionF("unwanted uploaders. got: %v unwanted: %v", r.Uploader, f.ExceptUploaders)
|
||||
}
|
||||
|
||||
if len(f.Resolutions) > 0 && !containsSlice(r.Resolution, f.Resolutions) {
|
||||
r.addRejectionF("resolution not matching. got: %v want: %v", r.Resolution, f.Resolutions)
|
||||
}
|
||||
|
||||
if len(f.Codecs) > 0 && !sliceContainsSlice(r.Codec, f.Codecs) {
|
||||
r.addRejectionF("codec not matching. got: %v want: %v", r.Codec, f.Codecs)
|
||||
}
|
||||
|
||||
if len(f.Sources) > 0 && !containsSlice(r.Source, f.Sources) {
|
||||
r.addRejectionF("source not matching. got: %v want: %v", r.Source, f.Sources)
|
||||
}
|
||||
|
||||
if len(f.Containers) > 0 && !containsSlice(r.Container, f.Containers) {
|
||||
r.addRejectionF("container not matching. got: %v want: %v", r.Container, f.Containers)
|
||||
}
|
||||
|
||||
// HDR is parsed into the Codec slice from rls
|
||||
if len(f.MatchHDR) > 0 && !sliceContainsSlice(r.HDR, f.MatchHDR) {
|
||||
r.addRejectionF("hdr not matching. got: %v want: %v", r.HDR, f.MatchHDR)
|
||||
}
|
||||
|
||||
// HDR is parsed into the Codec slice from rls
|
||||
if len(f.ExceptHDR) > 0 && sliceContainsSlice(r.HDR, f.ExceptHDR) {
|
||||
r.addRejectionF("hdr unwanted. got: %v want: %v", r.HDR, f.ExceptHDR)
|
||||
}
|
||||
|
||||
if f.Years != "" && !containsIntStrings(r.Year, f.Years) {
|
||||
r.addRejectionF("year not matching. got: %d want: %v", r.Year, f.Years)
|
||||
}
|
||||
|
||||
if f.MatchCategories != "" && !contains(r.Category, f.MatchCategories) {
|
||||
r.addRejectionF("category not matching. got: %v want: %v", r.Category, f.MatchCategories)
|
||||
}
|
||||
|
||||
if f.ExceptCategories != "" && contains(r.Category, f.ExceptCategories) {
|
||||
r.addRejectionF("category unwanted. got: %v want: %v", r.Category, f.ExceptCategories)
|
||||
}
|
||||
|
||||
if len(f.MatchReleaseTypes) > 0 && !containsSlice(r.Category, f.MatchReleaseTypes) {
|
||||
r.addRejectionF("release type not matching. got: %v want: %v", r.Category, f.MatchReleaseTypes)
|
||||
}
|
||||
|
||||
if (f.MinSize != "" || f.MaxSize != "") && !f.checkSizeFilter(r, f.MinSize, f.MaxSize) {
|
||||
r.addRejectionF("size not matching. got: %v want min: %v max: %v", r.Size, f.MinSize, f.MaxSize)
|
||||
}
|
||||
|
||||
if f.Tags != "" && !containsAny(r.Tags, f.Tags) {
|
||||
r.addRejectionF("tags not matching. got: %v want: %v", r.Tags, f.Tags)
|
||||
}
|
||||
|
||||
if f.ExceptTags != "" && containsAny(r.Tags, f.ExceptTags) {
|
||||
r.addRejectionF("tags unwanted. got: %v want: %v", r.Tags, f.ExceptTags)
|
||||
}
|
||||
|
||||
if len(f.Artists) > 0 && !containsFuzzy(r.TorrentName, f.Artists) {
|
||||
r.addRejectionF("artists not matching. got: %v want: %v", r.TorrentName, f.Artists)
|
||||
}
|
||||
|
||||
if len(f.Albums) > 0 && !containsFuzzy(r.TorrentName, f.Albums) {
|
||||
r.addRejectionF("albums not matching. got: %v want: %v", r.TorrentName, f.Albums)
|
||||
}
|
||||
|
||||
// Perfect flac requires Cue, Log, Log Score 100, FLAC and 24bit Lossless
|
||||
if f.PerfectFlac && !f.isPerfectFLAC(r) {
|
||||
r.addRejectionF("wanted: perfect flac. got: %v", r.Audio)
|
||||
}
|
||||
|
||||
if len(f.Formats) > 0 && !sliceContainsSlice(r.Audio, f.Formats) {
|
||||
r.addRejectionF("formats not matching. got: %v want: %v", r.Audio, f.Formats)
|
||||
}
|
||||
|
||||
if len(f.Quality) > 0 && !sliceContainsSlice(r.Audio, f.Quality) {
|
||||
r.addRejectionF("quality not matching. got: %v want: %v", r.Audio, f.Quality)
|
||||
}
|
||||
|
||||
if len(f.Media) > 0 && !containsSlice(r.Source, f.Media) {
|
||||
r.addRejectionF("media not matching. got: %v want: %v", r.Source, f.Media)
|
||||
}
|
||||
|
||||
if f.Cue && !containsAny(r.Audio, "Cue") {
|
||||
r.addRejection("wanted: cue")
|
||||
}
|
||||
|
||||
if f.Log && !containsAny(r.Audio, "Log") {
|
||||
r.addRejection("wanted: log")
|
||||
}
|
||||
|
||||
if f.Log && f.LogScore != 0 && r.LogScore != f.LogScore {
|
||||
r.addRejectionF("log score. got: %v want: %v", r.LogScore, f.LogScore)
|
||||
}
|
||||
|
||||
if len(r.Rejections) > 0 {
|
||||
return r.Rejections, false
|
||||
}
|
||||
|
||||
return nil, true
|
||||
}
|
||||
|
||||
// isPerfectFLAC Perfect is "CD FLAC Cue Log 100% Lossless or 24bit Lossless"
|
||||
func (f Filter) isPerfectFLAC(r *Release) bool {
|
||||
if !contains(r.Source, "CD") {
|
||||
return false
|
||||
}
|
||||
if !containsAny(r.Audio, "Cue") {
|
||||
return false
|
||||
}
|
||||
if !containsAny(r.Audio, "Log") {
|
||||
return false
|
||||
}
|
||||
if !containsAny(r.Audio, "Log100") {
|
||||
return false
|
||||
}
|
||||
if !containsAny(r.Audio, "FLAC") {
|
||||
return false
|
||||
}
|
||||
if !containsAnySlice(r.Audio, []string{"Lossless", "24bit Lossless"}) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// checkSizeFilter additional size check
|
||||
// for indexers that doesn't announce size, like some gazelle based
|
||||
// set flag r.AdditionalSizeCheckRequired if there's a size in the filter, otherwise go a head
|
||||
// implement API for ptp,btn,ggn to check for size if needed
|
||||
// for others pull down torrent and do check
|
||||
func (f Filter) checkSizeFilter(r *Release, minSize string, maxSize string) bool {
|
||||
|
||||
if r.Size == 0 {
|
||||
r.AdditionalSizeCheckRequired = true
|
||||
|
||||
return true
|
||||
} else {
|
||||
r.AdditionalSizeCheckRequired = false
|
||||
}
|
||||
|
||||
// if r.Size parse filter to bytes and compare
|
||||
// handle both min and max
|
||||
if minSize != "" {
|
||||
// string to bytes
|
||||
minSizeBytes, err := humanize.ParseBytes(minSize)
|
||||
if err != nil {
|
||||
// log could not parse into bytes
|
||||
}
|
||||
|
||||
if r.Size <= minSizeBytes {
|
||||
r.addRejection("size: smaller than min size")
|
||||
return false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if maxSize != "" {
|
||||
// string to bytes
|
||||
maxSizeBytes, err := humanize.ParseBytes(maxSize)
|
||||
if err != nil {
|
||||
// log could not parse into bytes
|
||||
}
|
||||
|
||||
if r.Size >= maxSizeBytes {
|
||||
r.addRejection("size: larger than max size")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// checkFilterIntStrings "1,2,3-20"
|
||||
func containsIntStrings(value int, filterList string) bool {
|
||||
filters := strings.Split(filterList, ",")
|
||||
|
||||
for _, s := range filters {
|
||||
s = strings.Replace(s, "%", "", -1)
|
||||
s = strings.Trim(s, " ")
|
||||
|
||||
if strings.Contains(s, "-") {
|
||||
minMax := strings.Split(s, "-")
|
||||
|
||||
// to int
|
||||
min, err := strconv.ParseInt(minMax[0], 10, 32)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
max, err := strconv.ParseInt(minMax[1], 10, 32)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if min > max {
|
||||
// handle error
|
||||
return false
|
||||
} else {
|
||||
// if announcePercent is greater than min and less than max return true
|
||||
if value >= int(min) && value <= int(max) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filterInt, err := strconv.ParseInt(s, 10, 32)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if int(filterInt) == value {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func contains(tag string, filter string) bool {
|
||||
return containsMatch([]string{tag}, strings.Split(filter, ","))
|
||||
}
|
||||
|
||||
func containsFuzzy(tag string, filter string) bool {
|
||||
return containsMatchFuzzy([]string{tag}, strings.Split(filter, ","))
|
||||
}
|
||||
|
||||
func containsSlice(tag string, filters []string) bool {
|
||||
return containsMatch([]string{tag}, filters)
|
||||
}
|
||||
|
||||
func containsAny(tags []string, filter string) bool {
|
||||
return containsMatch(tags, strings.Split(filter, ","))
|
||||
}
|
||||
|
||||
func sliceContainsSlice(tags []string, filters []string) bool {
|
||||
return containsMatchBasic(tags, filters)
|
||||
}
|
||||
|
||||
func containsMatchFuzzy(tags []string, filters []string) bool {
|
||||
for _, tag := range tags {
|
||||
tag = strings.ToLower(tag)
|
||||
|
||||
for _, filter := range filters {
|
||||
filter = strings.ToLower(filter)
|
||||
filter = strings.Trim(filter, " ")
|
||||
// check if line contains * or ?, if so try wildcard match, otherwise try substring match
|
||||
a := strings.ContainsAny(filter, "?|*")
|
||||
if a {
|
||||
match := wildcard.Match(filter, tag)
|
||||
if match {
|
||||
return true
|
||||
}
|
||||
} else if strings.Contains(tag, filter) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func containsMatch(tags []string, filters []string) bool {
|
||||
for _, tag := range tags {
|
||||
tag = strings.ToLower(tag)
|
||||
|
||||
for _, filter := range filters {
|
||||
filter = strings.ToLower(filter)
|
||||
filter = strings.Trim(filter, " ")
|
||||
// check if line contains * or ?, if so try wildcard match, otherwise try substring match
|
||||
a := strings.ContainsAny(filter, "?|*")
|
||||
if a {
|
||||
match := wildcard.Match(filter, tag)
|
||||
if match {
|
||||
return true
|
||||
}
|
||||
} else if tag == filter {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func containsMatchBasic(tags []string, filters []string) bool {
|
||||
for _, tag := range tags {
|
||||
tag = strings.ToLower(tag)
|
||||
|
||||
for _, filter := range filters {
|
||||
filter = strings.ToLower(filter)
|
||||
filter = strings.Trim(filter, " ")
|
||||
|
||||
if tag == filter {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func containsAnySlice(tags []string, filters []string) bool {
|
||||
for _, tag := range tags {
|
||||
tag = strings.ToLower(tag)
|
||||
|
||||
for _, filter := range filters {
|
||||
filter = strings.ToLower(filter)
|
||||
filter = strings.Trim(filter, " ")
|
||||
// check if line contains * or ?, if so try wildcard match, otherwise try substring match
|
||||
wild := strings.ContainsAny(filter, "?|*")
|
||||
if wild {
|
||||
match := wildcard.Match(filter, tag)
|
||||
if match {
|
||||
return true
|
||||
}
|
||||
} else if tag == filter {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func checkFreeleechPercent(announcePercent int, filterPercent string) bool {
|
||||
filters := strings.Split(filterPercent, ",")
|
||||
|
||||
// remove % and trim spaces
|
||||
//announcePercent = strings.Replace(announcePercent, "%", "", -1)
|
||||
//announcePercent = strings.Trim(announcePercent, " ")
|
||||
|
||||
//announcePercentInt, err := strconv.ParseInt(announcePercent, 10, 32)
|
||||
//if err != nil {
|
||||
// return false
|
||||
//}
|
||||
|
||||
for _, s := range filters {
|
||||
s = strings.Replace(s, "%", "", -1)
|
||||
s = strings.Trim(s, " ")
|
||||
|
||||
if strings.Contains(s, "-") {
|
||||
minMax := strings.Split(s, "-")
|
||||
|
||||
// to int
|
||||
min, err := strconv.ParseInt(minMax[0], 10, 32)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
max, err := strconv.ParseInt(minMax[1], 10, 32)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if min > max {
|
||||
// handle error
|
||||
return false
|
||||
} else {
|
||||
// if announcePercent is greater than min and less than max return true
|
||||
if announcePercent >= int(min) && announcePercent <= int(max) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
filterPercentInt, err := strconv.ParseInt(s, 10, 32)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
if int(filterPercentInt) == announcePercent {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
1537
internal/domain/filter_test.go
Normal file
1537
internal/domain/filter_test.go
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,9 +1,13 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"net/url"
|
||||
"text/template"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type IndexerRepo interface {
|
||||
|
@ -115,6 +119,56 @@ type IndexerParseMatch struct {
|
|||
Encode []string `json:"encode"`
|
||||
}
|
||||
|
||||
func (p *IndexerParse) ParseTorrentUrl(vars map[string]string, extraVars map[string]string, release *Release) error {
|
||||
tmpVars := map[string]string{}
|
||||
|
||||
// copy vars to new tmp map
|
||||
for k, v := range vars {
|
||||
tmpVars[k] = v
|
||||
}
|
||||
|
||||
// merge extra vars with vars
|
||||
if extraVars != nil {
|
||||
for k, v := range extraVars {
|
||||
tmpVars[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
// handle url encode of values
|
||||
if p.Match.Encode != nil {
|
||||
for _, e := range p.Match.Encode {
|
||||
if v, ok := tmpVars[e]; ok {
|
||||
// url encode value
|
||||
t := url.QueryEscape(v)
|
||||
tmpVars[e] = t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// setup text template to inject variables into
|
||||
tmpl, err := template.New("torrenturl").Parse(p.Match.TorrentURL)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not create torrent url template")
|
||||
return err
|
||||
}
|
||||
|
||||
var urlBytes bytes.Buffer
|
||||
err = tmpl.Execute(&urlBytes, &tmpVars)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not write torrent url template output")
|
||||
return err
|
||||
}
|
||||
|
||||
release.TorrentURL = urlBytes.String()
|
||||
|
||||
// handle cookies
|
||||
if v, ok := extraVars["cookie"]; ok {
|
||||
release.RawCookie = v
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type TorrentBasic struct {
|
||||
Id string `json:"Id"`
|
||||
TorrentId string `json:"TorrentId,omitempty"`
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
377
internal/domain/releasetags.go
Normal file
377
internal/domain/releasetags.go
Normal file
|
@ -0,0 +1,377 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var types map[string][]*TagInfo
|
||||
|
||||
func init() {
|
||||
types = make(map[string][]*TagInfo)
|
||||
|
||||
audio := []*TagInfo{
|
||||
{tag: "24BIT", title: "", regexp: "(?-i:24BIT)", re: nil},
|
||||
{tag: "24BIT Lossless", title: "", regexp: "(?:24BIT lossless)", re: nil},
|
||||
{tag: "16BIT", title: "", regexp: "(?-i:16BIT)", re: nil},
|
||||
{tag: "320", title: "320 Kbps", regexp: "320[\\\\-\\\\._ kbps]?", re: nil},
|
||||
{tag: "256", title: "256 Kbps", regexp: "256[\\\\-\\\\._ kbps]?", re: nil},
|
||||
{tag: "192", title: "192 Kbps", regexp: "192[\\\\-\\\\._ kbps]?", re: nil},
|
||||
{tag: "128", title: "128 Kbps", regexp: "128[\\\\-\\\\._ kbps]?", re: nil},
|
||||
{tag: "AAC-LC", title: "Advanced Audio Coding (LC)", regexp: "aac[\\-\\._ ]?lc", re: nil},
|
||||
{tag: "AAC", title: "Advanced Audio Coding (LC)", regexp: "", re: nil},
|
||||
{tag: "AC3D", title: "", regexp: "ac[\\-\\._ ]?3d", re: nil},
|
||||
{tag: "Atmos", title: "Dolby Atmos", regexp: "", re: nil},
|
||||
{tag: "CBR", title: "Constant Bit Rate", regexp: "", re: nil},
|
||||
{tag: "Cue", title: "Cue File", regexp: "", re: nil},
|
||||
{tag: "DDPA", title: "Dolby Digital+ Atmos (E-AC-3+Atmos)", regexp: "dd[p\\+]a", re: nil},
|
||||
{tag: "DDP", title: "Dolby Digital+ (E-AC-3)", regexp: "dd[p\\+]|e[\\-\\._ ]?ac3", re: nil},
|
||||
{tag: "DD", title: "Dolby Digital (AC-3)", regexp: "dd|ac3|dolby[\\-\\._ ]?digital", re: nil},
|
||||
{tag: "DTS-HD.HRA", title: "DTS (HD HRA)", regexp: "dts[\\-\\._ ]?hd[\\-\\._ ]?hra", re: nil},
|
||||
{tag: "DTS-HD.HR", title: "DTS (HD HR)", regexp: "dts[\\-\\._ ]?hd[\\-\\._ ]?hr", re: nil},
|
||||
{tag: "DTS-HD.MA", title: "DTS (HD MA)", regexp: "dts[\\-\\._ ]?hd[\\-\\._ ]?ma", re: nil},
|
||||
{tag: "DTS-HD", title: "DTS (HD)", regexp: "dts[\\-\\._ ]?hd[\\-\\._ ]?", re: nil},
|
||||
{tag: "DTS-MA", title: "DTS (MA)", regexp: "dts[\\-\\._ ]?ma[\\-\\._ ]?", re: nil},
|
||||
{tag: "DTS-X", title: "DTS (X)", regexp: "dts[\\-\\._ ]?x", re: nil},
|
||||
{tag: "DTS", title: "", regexp: "", re: nil},
|
||||
{tag: "DUAL.AUDIO", title: "Dual Audio", regexp: "dual(?:[\\-\\._ ]?audio)?", re: nil},
|
||||
{tag: "EAC3D", title: "", regexp: "", re: nil},
|
||||
{tag: "ES", title: "Dolby Digital (ES)", regexp: "(?-i:ES)", re: nil},
|
||||
{tag: "EX", title: "Dolby Digital (EX)", regexp: "(?-i:EX)", re: nil},
|
||||
{tag: "FLAC", title: "Free Lossless Audio Codec", regexp: "", re: nil},
|
||||
{tag: "LiNE", title: "Line", regexp: "(?-i:L[iI]NE)", re: nil},
|
||||
{tag: "Lossless", title: "", regexp: "(?i:Lossless)", re: nil},
|
||||
{tag: "Log100", title: "", regexp: "(log 100%)", re: nil},
|
||||
{tag: "Log", title: "", regexp: "(?:log)", re: nil},
|
||||
{tag: "LPCM", title: "Linear Pulse-Code Modulation", regexp: "", re: nil},
|
||||
{tag: "MP3", title: "", regexp: "", re: nil},
|
||||
{tag: "OGG", title: "", regexp: "", re: nil},
|
||||
{tag: "OPUS", title: "", regexp: "", re: nil},
|
||||
{tag: "TrueHD", title: "Dolby TrueHD", regexp: "(?:dolby[\\-\\._ ]?)?true[\\-\\._ ]?hd", re: nil},
|
||||
{tag: "VBR", title: "Variable Bit Rate", regexp: "", re: nil},
|
||||
}
|
||||
types["audio"] = audio
|
||||
|
||||
bonus := []*TagInfo{
|
||||
{tag: "Freeleech", title: "Freeleech", regexp: "freeleech", re: nil},
|
||||
}
|
||||
types["bonus"] = bonus
|
||||
|
||||
channels := []*TagInfo{
|
||||
{tag: "7.1", title: "", regexp: "7\\.1(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "6.1", title: "", regexp: "6\\.1(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "6.0", title: "", regexp: "6\\.0(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "5.1", title: "", regexp: "5\\.1(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "5.0", title: "", regexp: "5\\.0(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "4.1", title: "", regexp: "4\\.1(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "4.0", title: "", regexp: "4\\.0(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "3.1", title: "", regexp: "3\\.1(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "3.0", title: "", regexp: "3\\.0(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "2.1", title: "", regexp: "2\\.1(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "2.0", title: "", regexp: "2\\.0(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
{tag: "1.0", title: "", regexp: "1\\.0(?:[\\-\\._ ]?audios)?", re: nil},
|
||||
}
|
||||
types["channels"] = channels
|
||||
|
||||
codecs := []*TagInfo{
|
||||
{tag: "DiVX.SBC", title: "DivX SBC", regexp: "(?:divx[\\-\\._ ]?)?sbc", re: nil},
|
||||
{tag: "x264.HQ", title: "x264 (HQ)", regexp: "x[\\\\-\\\\._ ]?264[\\\\-\\\\._ ]?hq", re: nil},
|
||||
{tag: "MPEG-2", title: "", regexp: "mpe?g(?:[\\-\\._ ]?2)?", re: nil},
|
||||
{tag: "H.265", title: "", regexp: "h[\\-\\._ ]?265", re: nil},
|
||||
{tag: "H.264", title: "", regexp: "h[\\-\\._ ]?264", re: nil},
|
||||
{tag: "H.263", title: "", regexp: "h[\\-\\._ ]?263", re: nil},
|
||||
{tag: "H.262", title: "", regexp: "h[\\-\\._ ]?2[26]2", re: nil},
|
||||
{tag: "H.261", title: "", regexp: "h[\\-\\._ ]?261", re: nil},
|
||||
{tag: "dxva", title: "Direct-X Video Acceleration", regexp: "", re: nil},
|
||||
{tag: "HEVC", title: "High Efficiency Video Coding", regexp: "", re: nil},
|
||||
{tag: "VC-1", title: "", regexp: "vc[\\-\\._ ]?1", re: nil},
|
||||
{tag: "x265", title: "", regexp: "x[\\-\\._ ]?265", re: nil},
|
||||
{tag: "x264", title: "", regexp: "x[\\-\\._ ]?264", re: nil},
|
||||
{tag: "XViD", title: "Xvid", regexp: "", re: nil},
|
||||
{tag: "AVC", title: "Advanced Video Coding", regexp: "avc(?:[\\-\\._ ]?1)?", re: nil},
|
||||
{tag: "VP9", title: "", regexp: "vp[\\-\\._ ]?9", re: nil},
|
||||
{tag: "VP8", title: "", regexp: "vp[\\-\\._ ]?8", re: nil},
|
||||
{tag: "VP7", title: "", regexp: "vp[\\-\\._ ]?7", re: nil},
|
||||
}
|
||||
types["codecs"] = codecs
|
||||
|
||||
container := []*TagInfo{
|
||||
{tag: "avi", title: "Audio Video Interleave (avi)", regexp: "", re: nil},
|
||||
{tag: "img", title: "IMG", regexp: "", re: nil},
|
||||
{tag: "iso", title: "ISO", regexp: "", re: nil},
|
||||
{tag: "mkv", title: "Matroska (mkv)", regexp: "", re: nil},
|
||||
{tag: "mov", title: "MOV", regexp: "", re: nil},
|
||||
{tag: "mp4", title: "MP4", regexp: "", re: nil},
|
||||
{tag: "mpg", title: "MPEG", regexp: "mpe?g", re: nil},
|
||||
{tag: "m2ts", title: "BluRay Disc (m2ts)", regexp: "", re: nil},
|
||||
{tag: "vob", title: "VOB", regexp: "", re: nil},
|
||||
}
|
||||
types["container"] = container
|
||||
|
||||
hdr := []*TagInfo{
|
||||
{tag: "HDR10+", title: "High Dynamic Range (10-bit+)", regexp: "hdr[\\-\\.]?10\\+|10\\+[\\-\\.]?bit|hdr10plus|hi10p", re: nil},
|
||||
{tag: "HDR10", title: "High Dynamic Range (10-bit)", regexp: "hdr[\\-\\.]?10|10[\\-\\.]?bit|hi10", re: nil},
|
||||
{tag: "HDR+", title: "High Dynamic Range+", regexp: "hdr\\+", re: nil},
|
||||
{tag: "HDR", title: "High Dynamic Range", regexp: "", re: nil},
|
||||
{tag: "SDR", title: "Standard Dynamic Range", regexp: "", re: nil},
|
||||
{tag: "DV", title: "Dolby Vision", regexp: "(?i:dolby[\\-\\._ ]vision|dovi|\\Qdv\\E\\b)", re: nil},
|
||||
}
|
||||
types["hdr"] = hdr
|
||||
|
||||
other := []*TagInfo{
|
||||
{tag: "HYBRID", title: "Hybrid", regexp: "", re: nil},
|
||||
{tag: "REMUX", title: "Remux", regexp: "", re: nil},
|
||||
{tag: "REPACK", title: "Repack", regexp: "repack(?:ed)?", re: nil},
|
||||
{tag: "REREPACK", title: "Rerepack", regexp: "rerepack(?:ed)?", re: nil},
|
||||
}
|
||||
types["other"] = other
|
||||
|
||||
source := []*TagInfo{
|
||||
{tag: "Cassette", title: "Cassette", regexp: "", re: nil},
|
||||
{tag: "CD", title: "Compact Disc", regexp: "cd[\\-\\._ ]?(?:album)?", re: nil},
|
||||
{tag: "BDRiP", title: "BluRay (rip)", regexp: "b[dr]?[\\-\\._ ]?rip", re: nil},
|
||||
{tag: "BDSCR", title: "BluRay (screener)", regexp: "b[dr][\\-\\._ ]?scr(?:eener)?", re: nil},
|
||||
{tag: "BluRay3D", title: "", regexp: "blu[\\-\\._ ]?ray[\\-\\._ ]?3d|bd3d", re: nil},
|
||||
{tag: "BluRayRiP", title: "BluRay (rip)", regexp: "", re: nil},
|
||||
{tag: "BluRay", title: "", regexp: "blu[\\-\\._ ]?ray|bd", re: nil},
|
||||
{tag: "BRDRip", title: "BluRay Disc (rip)", regexp: "", re: nil},
|
||||
{tag: "DAT", title: "Datacable", regexp: "(?-i:DAT)", re: nil},
|
||||
{tag: "DVBRiP", title: "Digital Video Broadcasting (rip)", regexp: "dvb[\\-\\._ ]?rip", re: nil},
|
||||
{tag: "DVDA", title: "Audio DVD", regexp: "", re: nil},
|
||||
{tag: "DVDRiP", title: "Digital Video Disc (rip)", regexp: "dvd[\\-\\._ ]?rip", re: nil},
|
||||
{tag: "DVDSCRRiP", title: "Digital Video Disc (screener rip)", regexp: "(?:dvd[\\-\\._ ]?)?scr(?:eener)?[\\-\\._ ]?rip", re: nil},
|
||||
{tag: "DVDSCR", title: "Digital Video Disc (screener)", regexp: "(?:dvd[\\-\\._ ]?)?scr(?:eener)?", re: nil},
|
||||
{tag: "DVDS", title: "Digital Video Disc (single)", regexp: "dvds(?:ingle)?", re: nil},
|
||||
{tag: "DVD", title: "Digital Video Disc", regexp: "dvd", re: nil},
|
||||
{tag: "SACD", title: "Super Audio Compact Disc", regexp: "", re: nil},
|
||||
{tag: "RADIO", title: "Radio", regexp: "(?-i:R[aA]D[iI][oO])", re: nil},
|
||||
{tag: "SATRiP", title: "Satellite (rip)", regexp: "sat[\\-\\._ ]?rip", re: nil},
|
||||
{tag: "SAT", title: "Satellite Radio", regexp: "(?-i:SAT)", re: nil},
|
||||
{tag: "SBD", title: "Soundboard", regexp: "(?-i:SBD|DAB|Soundboard)", re: nil},
|
||||
{tag: "UHD.BDRiP", title: "Ultra High-Definition BluRay (rip)", regexp: "uhd[\\-\\._ ]?(?:bd)?rip", re: nil},
|
||||
{tag: "UHD.BluRay", title: "Ultra High-Definition BluRay", regexp: "uhd[\\-\\._ ]?(?:blu[\\-\\._ ]?ray|bd)", re: nil},
|
||||
{tag: "UHDTV", title: "Ultra High-Definition TV", regexp: "", re: nil},
|
||||
{tag: "UMDMOVIE", title: "Universal Media Disc Movie", regexp: "", re: nil},
|
||||
{tag: "Vinyl", title: "Vinyl", regexp: "vinyl|vl", re: nil},
|
||||
{tag: "WEB-DL", title: "Web (DL)", regexp: "web[\\-\\._ ]?dl", re: nil},
|
||||
{tag: "WEB-HD", title: "Web (HD)", regexp: "web[\\-\\._ ]?hd", re: nil},
|
||||
{tag: "WEBFLAC", title: "Web (FLAC)", regexp: "", re: nil},
|
||||
{tag: "WebHDRiP", title: "Web (HD rip)", regexp: "", re: nil},
|
||||
{tag: "WEBRiP", title: "Web (rip)", regexp: "web[\\-\\._ ]?rip", re: nil},
|
||||
{tag: "WEBSCR", title: "Web (screener)", regexp: "web[\\-\\._ ]?scr(?:eener)?", re: nil},
|
||||
{tag: "WebUHD", title: "Web (UHD)", regexp: "", re: nil},
|
||||
{tag: "WEB", title: "Web", regexp: "", re: nil},
|
||||
}
|
||||
types["source"] = source
|
||||
|
||||
resolution := []*TagInfo{
|
||||
{tag: "PN", title: "Selector", regexp: "p(?:al)?[\\-\\._ ]?n(?:tsc)?[\\-\\._ ]selector", re: nil},
|
||||
{tag: "DCI4K", title: "DCI 4k", regexp: "dci[\\-\\._ ]?4k|4096x2160", re: nil},
|
||||
{tag: "DCI2K", title: "DCI 2k", regexp: "dci[\\-\\._ ]?2k|2048x1080", re: nil},
|
||||
{tag: "4320p", title: "UltraHD 8K (4320p)", regexp: "4320p|7680x4320", re: nil},
|
||||
{tag: "2880p", title: "5k (2880p)", regexp: "2880p|5k|5120x2880", re: nil},
|
||||
{tag: "2160p", title: "UltraHD 4K (2160p)", regexp: "2160p|3840x2160|uhd|4k", re: nil},
|
||||
{tag: "1800p", title: "QHD+ (1800p)", regexp: "1800p|3200x1800", re: nil},
|
||||
{tag: "1440p", title: "QHD (1440p)", regexp: "1440p|2560x1440", re: nil},
|
||||
{tag: "1080p", title: "FullHD (1080p)", regexp: "1080[ip]|1920x1080", re: nil},
|
||||
{tag: "900p", title: "900[ip]|1600x900", regexp: "900[ip]|1600x900", re: nil},
|
||||
{tag: "720p", title: "HD (720p)", regexp: "720[ip]|1280x720", re: nil},
|
||||
{tag: "576p", title: "PAL (576p)", regexp: "576[ip]|720x576|pal", re: nil},
|
||||
{tag: "540p", title: "qHD (540p)", regexp: "540[ip]|960x540", re: nil},
|
||||
{tag: "480p", title: "NTSC (480p)", regexp: "480[ip]|720x480|848x480|854x480|ntsc", re: nil},
|
||||
{tag: "360p", title: "nHD (360p)", regexp: "360[ip]|640x360", re: nil},
|
||||
{tag: "$1p", title: "Other ($1p)", regexp: "([123]\\d{3})p", re: nil},
|
||||
}
|
||||
types["resolution"] = resolution
|
||||
|
||||
// language `(?i)\b((DK|DKSUBS|DANiSH|DUTCH|NL|NLSUBBED|ENG|FI|FLEMiSH|FiNNiSH|DE|FRENCH|GERMAN|HE|HEBREW|HebSub|HiNDi|iCELANDiC|KOR|MULTi|MULTiSUBS|NORWEGiAN|NO|NORDiC|PL|PO|POLiSH|PLDUB|RO|ROMANiAN|RUS|SPANiSH|SE|SWEDiSH|SWESUB||))\b`)
|
||||
// websites `(?i)\b((AMBC|AS|AMZN|AMC|ANPL|ATVP|iP|CORE|BCORE|CMOR|CN|CBC|CBS|CMAX|CNBC|CC|CRIT|CR|CSPN|CW|DAZN|DCU|DISC|DSCP|DSNY|DSNP|DPLY|ESPN|FOX|FUNI|PLAY|HBO|HMAX|HIST|HS|HOTSTAR|HULU|iT|MNBC|MTV|NATG|NBC|NF|NICK|NRK|PMNT|PMNP|PCOK|PBS|PBSK|PSN|QIBI|SBS|SHO|STAN|STZ|SVT|SYFY|TLC|TRVL|TUBI|TV3|TV4|TVL|VH1|VICE|VMEO|UFC|USAN|VIAP|VIAPLAY|VL|WWEN|XBOX|YHOO|YT|RED))\b`)
|
||||
|
||||
for s, infos := range types {
|
||||
for _, info := range infos {
|
||||
var err error
|
||||
//if info.re, err = regexp.Compile(`(?i)^(?:` + info.RE() + `)$`); err != nil {
|
||||
if info.re, err = regexp.Compile(`(?i)(?:` + info.RE() + `)`); err != nil {
|
||||
fmt.Errorf("tag %q has invalid regexp %q\n", s, info.re)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type TagInfo struct {
|
||||
tag string
|
||||
title string
|
||||
regexp string
|
||||
re *regexp.Regexp
|
||||
}
|
||||
|
||||
// Tag returns the tag info tag.
|
||||
func (info *TagInfo) Tag() string {
|
||||
return info.tag
|
||||
}
|
||||
|
||||
// Title returns the tag info title.
|
||||
func (info *TagInfo) Title() string {
|
||||
return info.title
|
||||
}
|
||||
|
||||
// Regexp returns the tag info regexp.
|
||||
func (info *TagInfo) Regexp() string {
|
||||
return info.regexp
|
||||
}
|
||||
|
||||
//// Other returns the tag info other.
|
||||
//func (info *TagInfo) Other() string {
|
||||
// return info.other
|
||||
//}
|
||||
//
|
||||
//// Type returns the tag info type.
|
||||
//func (info *TagInfo) Type() int {
|
||||
// return info.typ
|
||||
//}
|
||||
|
||||
//// Excl returns the tag info excl.
|
||||
//func (info *TagInfo) Excl() bool {
|
||||
// return info.excl
|
||||
//}
|
||||
|
||||
// RE returns the tag info regexp string.
|
||||
func (info *TagInfo) RE() string {
|
||||
if info.regexp != "" {
|
||||
return info.regexp
|
||||
}
|
||||
return `\Q` + info.tag + `\E`
|
||||
}
|
||||
|
||||
// Match matches the tag info to s.
|
||||
func (info *TagInfo) Match(s string) bool {
|
||||
return info.re.MatchString(s)
|
||||
}
|
||||
|
||||
// FindFunc is the find signature..
|
||||
type FindFunc func(string) *TagInfo
|
||||
|
||||
// Find returns a func to find tag info.
|
||||
func Find(infos ...*TagInfo) FindFunc {
|
||||
n := len(infos)
|
||||
return func(s string) *TagInfo {
|
||||
for i := 0; i < n; i++ {
|
||||
if infos[i].Match(s) {
|
||||
return infos[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
type ReleaseTags struct {
|
||||
Audio []string
|
||||
Channels string
|
||||
Source string
|
||||
Resolution string
|
||||
Container string
|
||||
Codec string
|
||||
HDR []string
|
||||
Other []string
|
||||
Bonus []string
|
||||
}
|
||||
|
||||
func ParseReleaseTags(tags []string) ReleaseTags {
|
||||
releaseTags := ReleaseTags{}
|
||||
|
||||
for _, tag := range tags {
|
||||
|
||||
for tagType, tagInfos := range types {
|
||||
|
||||
for _, info := range tagInfos {
|
||||
// check tag
|
||||
match := info.Match(tag)
|
||||
if match {
|
||||
fmt.Printf("match: %v, info: %v\n", tag, info.Tag())
|
||||
switch tagType {
|
||||
case "audio":
|
||||
releaseTags.Audio = append(releaseTags.Audio, info.Tag())
|
||||
continue
|
||||
case "bonus":
|
||||
releaseTags.Bonus = append(releaseTags.Bonus, info.Tag())
|
||||
continue
|
||||
case "channels":
|
||||
releaseTags.Channels = info.Tag()
|
||||
break
|
||||
case "codecs":
|
||||
releaseTags.Codec = info.Tag()
|
||||
break
|
||||
case "container":
|
||||
releaseTags.Container = info.Tag()
|
||||
break
|
||||
case "hdr":
|
||||
releaseTags.HDR = append(releaseTags.HDR, info.Tag())
|
||||
continue
|
||||
case "other":
|
||||
releaseTags.Other = append(releaseTags.Other, info.Tag())
|
||||
continue
|
||||
case "source":
|
||||
releaseTags.Source = info.Tag()
|
||||
break
|
||||
case "resolution":
|
||||
releaseTags.Resolution = info.Tag()
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return releaseTags
|
||||
}
|
||||
func ParseReleaseTagString(tags string) ReleaseTags {
|
||||
releaseTags := ReleaseTags{}
|
||||
|
||||
for tagType, tagInfos := range types {
|
||||
//fmt.Printf("tagType: %v\n", tagType)
|
||||
|
||||
for _, info := range tagInfos {
|
||||
// check tag
|
||||
match := info.Match(tags)
|
||||
if !match {
|
||||
continue
|
||||
}
|
||||
|
||||
//fmt.Printf("match: info: %v\n", info.Tag())
|
||||
switch tagType {
|
||||
case "audio":
|
||||
releaseTags.Audio = append(releaseTags.Audio, info.Tag())
|
||||
continue
|
||||
case "bonus":
|
||||
releaseTags.Bonus = append(releaseTags.Bonus, info.Tag())
|
||||
continue
|
||||
case "channels":
|
||||
releaseTags.Channels = info.Tag()
|
||||
break
|
||||
case "codecs":
|
||||
releaseTags.Codec = info.Tag()
|
||||
break
|
||||
case "container":
|
||||
releaseTags.Container = info.Tag()
|
||||
break
|
||||
case "hdr":
|
||||
releaseTags.HDR = append(releaseTags.HDR, info.Tag())
|
||||
continue
|
||||
case "other":
|
||||
releaseTags.Other = append(releaseTags.Other, info.Tag())
|
||||
continue
|
||||
case "source":
|
||||
releaseTags.Source = info.Tag()
|
||||
break
|
||||
case "resolution":
|
||||
releaseTags.Resolution = info.Tag()
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return releaseTags
|
||||
}
|
56
internal/domain/releasetags_test.go
Normal file
56
internal/domain/releasetags_test.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestParseReleaseTags(t *testing.T) {
|
||||
type args struct {
|
||||
tags []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want ReleaseTags
|
||||
}{
|
||||
{name: "test_1", args: args{tags: []string{"CD", "FLAC", "Lossless"}}, want: ReleaseTags{Source: "CD", Audio: []string{"FLAC", "Lossless"}}},
|
||||
{name: "test_2", args: args{tags: []string{"MP4", "2160p", "BluRay", "DV"}}, want: ReleaseTags{Source: "BluRay", Resolution: "2160p", Container: "mp4", HDR: []string{"DV"}}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equalf(t, tt.want, ParseReleaseTags(tt.args.tags), "ParseReleaseTags(%v)", tt.args.tags)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseReleaseTagString(t *testing.T) {
|
||||
type args struct {
|
||||
tags string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want ReleaseTags
|
||||
}{
|
||||
{name: "music_1", args: args{tags: "FLAC / Lossless / Log / 80% / Cue / CD"}, want: ReleaseTags{Audio: []string{"Cue", "FLAC", "Lossless", "Log"}, Source: "CD"}},
|
||||
{name: "music_2", args: args{tags: "FLAC Lossless Log 80% Cue CD"}, want: ReleaseTags{Audio: []string{"Cue", "FLAC", "Lossless", "Log"}, Source: "CD"}},
|
||||
{name: "music_3", args: args{tags: "FLAC Lossless Log 100% Cue CD"}, want: ReleaseTags{Audio: []string{"Cue", "FLAC", "Lossless", "Log100", "Log"}, Source: "CD"}},
|
||||
{name: "music_4", args: args{tags: "FLAC 24bit Lossless Log 100% Cue CD"}, want: ReleaseTags{Audio: []string{"24BIT Lossless", "Cue", "FLAC", "Lossless", "Log100", "Log"}, Source: "CD"}},
|
||||
{name: "music_5", args: args{tags: "MP3 320 WEB"}, want: ReleaseTags{Audio: []string{"320", "MP3"}, Source: "WEB"}},
|
||||
{name: "movies_1", args: args{tags: "x264 Blu-ray MKV 1080p"}, want: ReleaseTags{Codec: "x264", Source: "BluRay", Resolution: "1080p", Container: "mkv"}},
|
||||
{name: "movies_2", args: args{tags: "HEVC HDR Blu-ray mp4 2160p"}, want: ReleaseTags{Codec: "HEVC", Source: "BluRay", Resolution: "2160p", Container: "mp4", HDR: []string{"HDR"}}},
|
||||
{name: "movies_3", args: args{tags: "HEVC HDR DV Blu-ray mp4 2160p"}, want: ReleaseTags{Codec: "HEVC", Source: "BluRay", Resolution: "2160p", Container: "mp4", HDR: []string{"HDR", "DV"}}},
|
||||
{name: "movies_4", args: args{tags: "H.264, Blu-ray/HD DVD"}, want: ReleaseTags{Codec: "H.264", Source: "BluRay"}},
|
||||
{name: "movies_5", args: args{tags: "H.264, Remux"}, want: ReleaseTags{Codec: "H.264", Other: []string{"REMUX"}}},
|
||||
{name: "movies_6", args: args{tags: "H.264, DVD"}, want: ReleaseTags{Codec: "H.264", Source: "DVD"}},
|
||||
{name: "movies_7", args: args{tags: "H.264, DVD, Freeleech"}, want: ReleaseTags{Codec: "H.264", Source: "DVD", Bonus: []string{"Freeleech"}}},
|
||||
{name: "movies_8", args: args{tags: "H.264, DVD, Freeleech!"}, want: ReleaseTags{Codec: "H.264", Source: "DVD", Bonus: []string{"Freeleech"}}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equalf(t, tt.want, ParseReleaseTagString(tt.args.tags), "ParseReleaseTagString(%v)", tt.args.tags)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -56,7 +56,7 @@ func (j *TorznabJob) process() error {
|
|||
releases := make([]*domain.Release, 0)
|
||||
|
||||
for _, item := range items {
|
||||
rls, err := domain.NewRelease(item.Title, "")
|
||||
rls, err := domain.NewRelease(j.IndexerIdentifier)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func (j *TorznabJob) process() error {
|
|||
// parse size bytes string
|
||||
rls.ParseSizeBytesString(item.Size)
|
||||
|
||||
if err := rls.Parse(); err != nil {
|
||||
if err := rls.ParseString(item.Title); err != nil {
|
||||
j.Log.Error().Err(err).Msgf("torznab.process: error parsing release")
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ func (s *service) CheckFilter(f domain.Filter, release *domain.Release) (bool, e
|
|||
log.Trace().Msgf("filter.Service.CheckFilter: checking filter: %v %+v", f.Name, f)
|
||||
log.Trace().Msgf("filter.Service.CheckFilter: checking filter: %v for release: %+v", f.Name, release)
|
||||
|
||||
rejections, matchedFilter := release.CheckFilter(f)
|
||||
rejections, matchedFilter := f.CheckFilter(release)
|
||||
if len(rejections) > 0 {
|
||||
log.Trace().Msgf("filter.Service.CheckFilter: (%v) for release: %v rejections: (%v)", f.Name, release.TorrentName, release.RejectionsString())
|
||||
return false, nil
|
||||
|
|
|
@ -1,644 +1,38 @@
|
|||
package filter
|
||||
|
||||
//func Test_checkFilterStrings(t *testing.T) {
|
||||
// type args struct {
|
||||
// name string
|
||||
// filterList string
|
||||
// }
|
||||
// tests := []struct {
|
||||
// name string
|
||||
// args args
|
||||
// want bool
|
||||
// }{
|
||||
// {
|
||||
// name: "test_01",
|
||||
// args: args{
|
||||
// name: "The End",
|
||||
// filterList: "The End, Other movie",
|
||||
// },
|
||||
// want: true,
|
||||
// },
|
||||
// {
|
||||
// name: "test_02",
|
||||
// args: args{
|
||||
// name: "The Simpsons S12",
|
||||
// filterList: "The End, Other movie",
|
||||
// },
|
||||
// want: false,
|
||||
// },
|
||||
// {
|
||||
// name: "test_03",
|
||||
// args: args{
|
||||
// name: "The.Simpsons.S12",
|
||||
// filterList: "The?Simpsons*, Other movie",
|
||||
// },
|
||||
// want: true,
|
||||
// },
|
||||
// }
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.name, func(t *testing.T) {
|
||||
// got := checkFilterStrings(tt.args.name, tt.args.filterList)
|
||||
// assert.Equal(t, tt.want, got)
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
import "testing"
|
||||
|
||||
//func Test_service_checkFilter(t *testing.T) {
|
||||
// type args struct {
|
||||
// filter domain.Filter
|
||||
// announce domain.Announce
|
||||
// }
|
||||
//
|
||||
// svcMock := &service{
|
||||
// repo: nil,
|
||||
// actionRepo: nil,
|
||||
// indexerSvc: nil,
|
||||
// }
|
||||
//
|
||||
// tests := []struct {
|
||||
// name string
|
||||
// args args
|
||||
// expected bool
|
||||
// }{
|
||||
// {
|
||||
// name: "freeleech",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Freeleech: true,
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// Freeleech: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "scene",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Scene: true,
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// Scene: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "not_scene",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Scene: false,
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// Scene: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "shows_1",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Shows: "That show",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "shows_2",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Shows: "That show, The Other show",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "shows_3",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Shows: "That?show*, The?Other?show",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "shows_4",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Shows: "The Other show",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "shows_5",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Shows: "*show*",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "shows_6",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That.Show.S06.1080p.BluRay.DD5.1.x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Shows: "*show*",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "shows_7",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That.Show.S06.1080p.BluRay.DD5.1.x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Shows: "That?show*",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "match_releases_single",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// MatchReleases: "That show",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "match_releases_single_wildcard",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// MatchReleases: "That show*",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "match_releases_multiple",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// MatchReleases: "That show*, Other one",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "match_release_groups",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// ReleaseGroup: "GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// MatchReleaseGroups: "GROUP1",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "match_release_groups_multiple",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// ReleaseGroup: "GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// MatchReleaseGroups: "GROUP1,GROUP2",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "match_release_groups_dont_match",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// ReleaseGroup: "GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// MatchReleaseGroups: "GROUP2",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "except_release_groups",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// ReleaseGroup: "GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// ExceptReleaseGroups: "GROUP1",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "match_uploaders",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Uploader: "Uploader1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterAdvanced: domain.FilterAdvanced{
|
||||
// MatchUploaders: "Uploader1",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "non_match_uploaders",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Uploader: "Uploader2",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterAdvanced: domain.FilterAdvanced{
|
||||
// MatchUploaders: "Uploader1",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "except_uploaders",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Uploader: "Uploader1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterAdvanced: domain.FilterAdvanced{
|
||||
// ExceptUploaders: "Uploader1",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "resolutions_1080p",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 1080p BluRay DD5.1 x264-GROUP1",
|
||||
// Resolution: "1080p",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Resolutions: []string{"1080p"},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "resolutions_2160p",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// Resolution: "2160p",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Resolutions: []string{"2160p"},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "resolutions_no_match",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// Resolution: "2160p",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Resolutions: []string{"1080p"},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "codecs_1_match",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Codecs: []string{"x264"},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "codecs_2_no_match",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Codecs: []string{"h264"},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "sources_1_match",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Sources: []string{"BluRay"},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "sources_2_no_match",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Sources: []string{"WEB"},
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "years_1",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Years: "2020",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "years_2",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Years: "2020,1990",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "years_3_no_match",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Years: "1990",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "years_4_no_match",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Show S06 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Years: "2020",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "match_categories_1",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Category: "TV",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterAdvanced: domain.FilterAdvanced{
|
||||
// MatchCategories: "TV",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "match_categories_2",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Category: "TV :: HD",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterAdvanced: domain.FilterAdvanced{
|
||||
// MatchCategories: "*TV*",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "match_categories_3",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Category: "TV :: HD",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterAdvanced: domain.FilterAdvanced{
|
||||
// MatchCategories: "*TV*, *HD*",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// {
|
||||
// name: "match_categories_4_no_match",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Category: "TV :: HD",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterAdvanced: domain.FilterAdvanced{
|
||||
// MatchCategories: "Movies",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "except_categories_1",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// Category: "Movies",
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterAdvanced: domain.FilterAdvanced{
|
||||
// ExceptCategories: "Movies",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: false,
|
||||
// },
|
||||
// {
|
||||
// name: "match_multiple_fields_1",
|
||||
// args: args{
|
||||
// announce: domain.Announce{
|
||||
// TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
|
||||
// Category: "Movies",
|
||||
// Freeleech: true,
|
||||
// },
|
||||
// filter: domain.Filter{
|
||||
// Enabled: true,
|
||||
// FilterAdvanced: domain.FilterAdvanced{
|
||||
// MatchCategories: "Movies",
|
||||
// },
|
||||
// FilterTVMovies: domain.FilterTVMovies{
|
||||
// Resolutions: []string{"2160p"},
|
||||
// Sources: []string{"BluRay"},
|
||||
// Years: "2020",
|
||||
// },
|
||||
// FilterP2P: domain.FilterP2P{
|
||||
// MatchReleaseGroups: "GROUP1",
|
||||
// MatchReleases: "That movie",
|
||||
// Freeleech: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// expected: true,
|
||||
// },
|
||||
// }
|
||||
// for _, tt := range tests {
|
||||
// t.Run(tt.name, func(t *testing.T) {
|
||||
// got := svcMock.checkFilter(tt.args.filter, tt.args.announce)
|
||||
// assert.Equal(t, tt.expected, got)
|
||||
// })
|
||||
// }
|
||||
//}
|
||||
func Test_checkSizeFilter(t *testing.T) {
|
||||
type args struct {
|
||||
minSize string
|
||||
maxSize string
|
||||
releaseSize uint64
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "test_1", args: args{minSize: "1GB", maxSize: "", releaseSize: 100}, want: false, wantErr: false},
|
||||
{name: "test_2", args: args{minSize: "1GB", maxSize: "", releaseSize: 2000000000}, want: true, wantErr: false},
|
||||
{name: "test_3", args: args{minSize: "1GB", maxSize: "2.2GB", releaseSize: 2000000000}, want: true, wantErr: false},
|
||||
{name: "test_4", args: args{minSize: "1GB", maxSize: "2GIB", releaseSize: 2000000000}, want: true, wantErr: false},
|
||||
{name: "test_5", args: args{minSize: "1GB", maxSize: "2GB", releaseSize: 2000000010}, want: false, wantErr: false},
|
||||
{name: "test_6", args: args{minSize: "1GB", maxSize: "2GB", releaseSize: 2000000000}, want: false, wantErr: false},
|
||||
{name: "test_7", args: args{minSize: "", maxSize: "2GB", releaseSize: 2500000000}, want: false, wantErr: false},
|
||||
{name: "test_8", args: args{minSize: "", maxSize: "20GB", releaseSize: 2500000000}, want: true, wantErr: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, err := checkSizeFilter(tt.args.minSize, tt.args.maxSize, tt.args.releaseSize)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("checkSizeFilter() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("checkSizeFilter() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ parse:
|
|||
vars:
|
||||
- torrentName
|
||||
- freeleech
|
||||
- internal
|
||||
- origin
|
||||
- category
|
||||
- torrentSize
|
||||
- baseUrl
|
||||
|
|
|
@ -53,12 +53,12 @@ parse:
|
|||
- "New Torrent: PilotsEYE tv: QUITO 2014 1080p Blu-ray AVC DD 2.0 - Type: Documentary (H.264, Blu-ray/HD DVD) - Uploaded by: Anonymous - Size: 23.14 GiB - https://hdbits.org/details.php?id=12345&hit=1"
|
||||
- "New Torrent: Xiao Q 2019 720p BluRay DD-EX 5.1 x264-Anonymous - Type: Movie (H.264, Encode) Internal! - Uploaded by: Anonymous - Size: 4.54 GiB - https://hdbits.org/details.php?id=12345&hit=1"
|
||||
- "New Torrent: The Gentlemen 2019 UHD Blu-ray English TrueHD 7.1 - Type: Audio Track - Uploaded by: Anonymous - Size: 3.19 GiB - https://hdbits.org/details.php?id=519896&hit=1"
|
||||
pattern: '^New Torrent: (.+) - Type: (.+?) (?:\((.+)\))?\s?(Internal!)?\s?- Uploaded by: (.+) - Size: (.+) - (https://.+?/).+id=(\d+)'
|
||||
pattern: '^New Torrent: (.+) - Type: (.+?) (?:\((.+)\))?\s?(?:(Internal)!?)?\s?- Uploaded by: (.+) - Size: (.+) - (https://.+?/).+id=(\d+)'
|
||||
vars:
|
||||
- torrentName
|
||||
- category
|
||||
- releaseTags
|
||||
- internal
|
||||
- origin
|
||||
- uploader
|
||||
- torrentSize
|
||||
- baseUrl
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue