diff --git a/go.mod b/go.mod index 4299637..6c54ea4 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/autobrr/autobrr go 1.18 require ( + github.com/Masterminds/sprig/v3 v3.2.2 github.com/Masterminds/squirrel v1.5.3 github.com/anacrolix/torrent v1.46.0 github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef @@ -41,6 +42,8 @@ require ( ) require ( + github.com/Masterminds/goutils v1.1.1 // indirect + github.com/Masterminds/semver/v3 v3.1.1 // indirect github.com/PuerkitoBio/goquery v1.5.1 // indirect github.com/ajg/form v1.5.1 // indirect github.com/anacrolix/dht/v2 v2.18.0 // indirect @@ -57,6 +60,7 @@ require ( github.com/hashicorp/hcl v1.0.0 // indirect github.com/hekmon/cunits/v2 v2.1.0 // indirect github.com/huandu/xstrings v1.3.2 // indirect + github.com/imdario/mergo v0.3.11 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect @@ -64,7 +68,9 @@ require ( github.com/magiconair/properties v1.8.6 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/mitchellh/reflectwalk v1.0.0 // indirect github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect @@ -73,6 +79,7 @@ require ( github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect + github.com/shopspring/decimal v1.2.0 // indirect github.com/spf13/afero v1.9.2 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect diff --git a/go.sum b/go.sum index 8dd764f..4cb4615 100644 --- a/go.sum +++ b/go.sum @@ -41,6 +41,12 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= +github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= +github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8= +github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= github.com/Masterminds/squirrel v1.5.3 h1:YPpoceAcxuzIljlr5iWpNKaql7hLeG1KLSrhvdHpkZc= github.com/Masterminds/squirrel v1.5.3/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10= github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE= @@ -213,6 +219,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -253,6 +260,8 @@ github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= +github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= @@ -291,8 +300,12 @@ github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebG github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= +github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= +github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mmcdole/gofeed v1.1.3 h1:pdrvMb18jMSLidGp8j0pLvc9IGziX4vbmvVqmLH6z8o= github.com/mmcdole/gofeed v1.1.3/go.mod h1:QQO3maftbOu+hiVOGOZDRLymqGQCos4zxbA4j89gMrE= github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf h1:sWGE2v+hO0Nd4yFU/S/mDBM5plIU8v/Qhfz41hkDIAI= @@ -366,6 +379,8 @@ github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Q github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46/go.mod h1:uAQ5PCi+MFsC7HjREoAz1BU+Mq60+05gifQSsHSDG/8= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= github.com/sasha-s/go-deadlock v0.3.1/go.mod h1:F73l+cr82YSh10GxyRI6qZiCgK64VaZjwesgfQ1/iLM= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= @@ -377,6 +392,7 @@ github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:X github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff/go.mod h1:KSQcGKpxUMHk3nbYzs/tIBAM2iDooCn0BmttHOJEbLs= github.com/spf13/afero v1.9.2 h1:j49Hj62F0n+DaZ1dDCvhABaPNSGNkt32oRFxI33IEMw= github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= @@ -421,6 +437,7 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= @@ -749,6 +766,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/announce/announce.go b/internal/announce/announce.go index 2fbb042..9720619 100644 --- a/internal/announce/announce.go +++ b/internal/announce/announce.go @@ -176,9 +176,9 @@ func (a *announceProcessor) onLinesMatched(def *domain.IndexerDefinition, vars m rls.ParseString(rls.TorrentName) // parse torrentUrl - err = def.Parse.ParseTorrentUrl(vars, def.SettingsMap, rls) + err = def.Parse.ParseMatch(vars, def.SettingsMap, rls) if err != nil { - a.log.Error().Stack().Err(err).Msg("announce: could not parse torrent url") + a.log.Error().Stack().Err(err).Msgf("announce: %v", err) return err } diff --git a/internal/domain/indexer.go b/internal/domain/indexer.go index 9c48485..4d572cf 100644 --- a/internal/domain/indexer.go +++ b/internal/domain/indexer.go @@ -7,6 +7,7 @@ import ( "net/url" "text/template" + "github.com/Masterminds/sprig/v3" "github.com/dustin/go-humanize" ) @@ -122,11 +123,12 @@ type IndexerParseExtract struct { } type IndexerParseMatch struct { - TorrentURL string `json:"torrenturl"` - Encode []string `json:"encode"` + TorrentURL string `json:"torrenturl"` + TorrentName string `json:"torrentname"` + Encode []string `json:"encode"` } -func (p *IndexerParse) ParseTorrentUrl(vars map[string]string, extraVars map[string]string, release *Release) error { +func (p *IndexerParse) ParseMatch(vars map[string]string, extraVars map[string]string, release *Release) error { tmpVars := map[string]string{} // copy vars to new tmp map @@ -152,19 +154,37 @@ func (p *IndexerParse) ParseTorrentUrl(vars map[string]string, extraVars map[str } } - // setup text template to inject variables into - tmpl, err := template.New("torrenturl").Parse(p.Match.TorrentURL) - if err != nil { - return errors.New("could not create torrent url template") + if p.Match.TorrentURL != "" { + // setup text template to inject variables into + tmpl, err := template.New("torrenturl").Funcs(sprig.TxtFuncMap()).Parse(p.Match.TorrentURL) + if err != nil { + return errors.New("could not create torrent url template") + } + + var urlBytes bytes.Buffer + err = tmpl.Execute(&urlBytes, &tmpVars) + if err != nil { + return errors.New("could not write torrent url template output") + } + + release.TorrentURL = urlBytes.String() } - var urlBytes bytes.Buffer - err = tmpl.Execute(&urlBytes, &tmpVars) - if err != nil { - return errors.New("could not write torrent url template output") - } + if p.Match.TorrentName != "" { + // setup text template to inject variables into + tmplName, err := template.New("torrentname").Funcs(sprig.TxtFuncMap()).Parse(p.Match.TorrentName) + if err != nil { + return err + } - release.TorrentURL = urlBytes.String() + var nameBytes bytes.Buffer + err = tmplName.Execute(&nameBytes, &tmpVars) + if err != nil { + return errors.New("could not write torrent name template output") + } + + release.TorrentName = nameBytes.String() + } // handle cookies if v, ok := extraVars["cookie"]; ok { diff --git a/internal/domain/indexer_test.go b/internal/domain/indexer_test.go new file mode 100644 index 0000000..cac4584 --- /dev/null +++ b/internal/domain/indexer_test.go @@ -0,0 +1,163 @@ +package domain + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIndexerParse_ParseMatch(t *testing.T) { + type fields struct { + Type string + ForceSizeUnit string + Lines []IndexerParseExtract + Match IndexerParseMatch + } + type args struct { + vars map[string]string + extraVars map[string]string + release *Release + } + tests := []struct { + name string + fields fields + args args + expect *Release + wantErr bool + }{ + { + name: "test_01", + fields: fields{ + Type: "", + ForceSizeUnit: "", + Lines: []IndexerParseExtract{ + { + Test: nil, + Pattern: "New Torrent Announcement:\\s*<([^>]*)>\\s*Name:'(.*)' uploaded by '([^']*)'\\s*(freeleech)*\\s*-\\s*(https?\\:\\/\\/[^\\/]+\\/)torrent\\/(\\d+)", + Vars: []string{ + "category", + "torrentName", + "uploader", + "freeleech", + "baseUrl", + "torrentId", + }, + }, + }, + Match: IndexerParseMatch{ + TorrentURL: "{{ .baseUrl }}rss/download/{{ .torrentId }}/{{ .rsskey }}/{{ .torrentName }}.torrent", + TorrentName: "", + Encode: []string{"torrentName"}, + }, + }, + args: args{ + vars: map[string]string{ + "category": "TV :: Episodes HD", + "torrentName": "The Show 2019 S03E08 2160p DV WEBRip 6CH x265 HEVC-GROUP", + "uploader": "Anonymous", + "freeleech": "", + "baseUrl": "https://mock.org/", + "torrentId": "240860011", + }, + extraVars: map[string]string{ + "rsskey": "00000000000000000000", + }, + release: &Release{ + Indexer: "mock", + FilterStatus: ReleaseStatusFilterPending, + Rejections: []string{}, + Protocol: ReleaseProtocolTorrent, + Implementation: ReleaseImplementationIRC, + }, + }, + expect: &Release{ + Indexer: "mock", + FilterStatus: ReleaseStatusFilterPending, + Rejections: []string{}, + Protocol: ReleaseProtocolTorrent, + Implementation: ReleaseImplementationIRC, + TorrentURL: "https://mock.org/rss/download/240860011/00000000000000000000/The+Show+2019+S03E08+2160p+DV+WEBRip+6CH+x265+HEVC-GROUP.torrent", + }, + wantErr: false, + }, + { + name: "test_02", + fields: fields{ + Type: "", + ForceSizeUnit: "", + Lines: []IndexerParseExtract{ + { + Test: nil, + Pattern: `(.*?)(?: - )?(Visual Novel|Light Novel|TV.*|Movie|Manga|OVA|ONA|DVD Special|BD Special|Oneshot|Anthology|Manhwa|Manhua|Artbook|Game|Live Action.*|)[\s\p{Zs}]{2,}\[(\d+)\] :: (.*?)(?: \/ (?:RAW|Softsubs|Hardsubs|Translated)\s\((.+)\)(?:.*Episode\s(\d+))?(?:.*(Freeleech))?.*)? \|\| (https.*)\/torrents.*\?id=\d+&torrentid=(\d+) \|\| (.+?(?:(?:\|\| Uploaded by|$))?) (?:\|\| Uploaded by: (.*))?$`, + Vars: []string{ + "torrentName", + "category", + "year", + "releaseTags", + "releaseGroup", + "releaseEpisode", + "freeleech", + "baseUrl", + "torrentId", + "tags", + "uploader", + }, + }, + }, + Match: IndexerParseMatch{ + TorrentURL: "{{ .baseUrl }}/torrent/{{ .torrentId }}/download/{{ .passkey }}", + TorrentName: `{{ if .releaseGroup }}[{{ .releaseGroup }}] {{ end }}{{ .torrentName }} [{{ .year }}] {{ if .releaseEpisode }}{{ printf "- %02s " .releaseEpisode }}{{ end }}{{ print "[" .releaseTags "]" | replace " / " "][" }}`, + Encode: nil, + }, + }, + args: args{ + vars: map[string]string{ + "torrentName": "Great BluRay SoftSubbed Anime", + "category": "TV Series", + "year": "2020", + "releaseTags": "Blu-ray / MKV / h264 10-bit / 1080p / FLAC 2.0 / Dual Audio / Softsubs (Sub Group) / Freeleech", + "releaseGroup": "Softsubs", + "releaseEpisode": "", + "freeleech": "freeleech", + "baseUrl": "https://mock.org", + "torrentId": "240860011", + "tags": "comedy, drama, school.life, sports", + "uploader": "Uploader", + }, + extraVars: map[string]string{ + "passkey": "00000000000000000000", + }, + release: &Release{ + Indexer: "mock", + FilterStatus: ReleaseStatusFilterPending, + Rejections: []string{}, + Protocol: ReleaseProtocolTorrent, + Implementation: ReleaseImplementationIRC, + }, + }, + expect: &Release{ + Indexer: "mock", + FilterStatus: ReleaseStatusFilterPending, + Rejections: []string{}, + Protocol: ReleaseProtocolTorrent, + Implementation: ReleaseImplementationIRC, + TorrentURL: "https://mock.org/torrent/240860011/download/00000000000000000000", + TorrentName: "[Softsubs] Great BluRay SoftSubbed Anime [2020] [Blu-ray][MKV][h264 10-bit][1080p][FLAC 2.0][Dual Audio][Softsubs (Sub Group)][Freeleech]", + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + p := &IndexerParse{ + Type: tt.fields.Type, + ForceSizeUnit: tt.fields.ForceSizeUnit, + Lines: tt.fields.Lines, + Match: tt.fields.Match, + } + + p.ParseMatch(tt.args.vars, tt.args.extraVars, tt.args.release) + assert.Equal(t, tt.expect, tt.args.release) + }) + } +} diff --git a/internal/domain/release.go b/internal/domain/release.go index caf3c46..28cfe85 100644 --- a/internal/domain/release.go +++ b/internal/domain/release.go @@ -484,6 +484,11 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro r.Group = releaseGroup } + if episodeVal, err := getStringMapValue(varMap, "releaseEpisode"); err == nil { + episode, _ := strconv.Atoi(episodeVal); + r.Episode = episode + } + return nil } diff --git a/internal/indexer/definitions/animebytes.yaml b/internal/indexer/definitions/animebytes.yaml index 907d899..b7e2349 100644 --- a/internal/indexer/definitions/animebytes.yaml +++ b/internal/indexer/definitions/animebytes.yaml @@ -57,13 +57,15 @@ parse: - "Awesome Live Action Special - Live Action TV Special [2021] :: Web / MKV / h264 / 848x480 / AAC 2.0 / Softsubs (Sub Group) || https://animebytes.tv/torrents.php?id=00000&torrentid=00000 || manga|| Uploaded by: Some-Uploader" - "Best Visual Novel - Visual Novel [2006] :: Game / PC / Unarchived / Hentai (Censored) || https://animebytes.tv/torrents.php?id=00000&torrentid=00000 || nukige || Uploaded by: Uploader" - "Artist Name - Album of awesome Music [1991] :: MP3 / V0 (VBR) / CD || https://animebytes.tv/torrents2.php?id=00000&torrentid=000000 || ambient, folk || Uploaded by: Uploader" - pattern: '(.*?(Visual Novel|Light Novel|TV.*|Movie|Manga|OVA|ONA|DVD Special|BD Special|Oneshot|Anthology|Manhwa|Manhua|Artbook|Game|Live Action.*|))[\s\p{Zs}]{2,}\[(\d+)\] :: (.*(?:RAW|Softsubs|Hardsubs|Translated)\s\((.+)\).*|.*)\|\| (https.*)\/torrents.*\?id=\d+&torrentid=(\d+) \|\| (.+?(?:(?:\|\| Uploaded by|$))?)(?:\|\| Uploaded by: (.*))?$' + pattern: '(.*?)(?: - )?(Visual Novel|Light Novel|TV.*|Movie|Manga|OVA|ONA|DVD Special|BD Special|Oneshot|Anthology|Manhwa|Manhua|Artbook|Game|Live Action.*|)[\s\p{Zs}]{2,}\[(\d+)\] :: (.*?)(?: \/ (?:RAW|Softsubs|Hardsubs|Translated)\s\((.+)\)(?:.*Episode\s(\d+))?(?:.*(Freeleech))?.*)? \|\| (https.*)\/torrents.*\?id=\d+&torrentid=(\d+) \|\| (.+?(?:(?:\|\| Uploaded by|$))?) (?:\|\| Uploaded by: (.*))?$' vars: - torrentName - category - year - releaseTags - releaseGroup + - releaseEpisode + - freeleech - baseUrl - torrentId - tags @@ -71,3 +73,4 @@ parse: match: torrenturl: "{{ .baseUrl }}/torrent/{{ .torrentId }}/download/{{ .passkey }}" + torrentname: "{{ if .releaseGroup }}[{{ .releaseGroup }}] {{ end }}{{ .torrentName }} ({{ .year }}) {{ if .releaseEpisode }}{{ printf \"- %02s \" .releaseEpisode }}{{ end }}{{ print \"[\" .releaseTags \"]\" | replace \" / \" \"][\" }}"