mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
Feature: Improve filtering and release parsing (#56)
* feat: match against orig and cleaned rel * feat: add more release parse tests * feat: filter check tags * feat: improve filter tag parsing * refactor: simplify tag split and trim * fix(indexers): use releasetags for milkie * fix: properly replace spaces in string * feat: better source check * feat: extract releasetags
This commit is contained in:
parent
8f53becbb3
commit
ae1f14d0a4
6 changed files with 1036 additions and 130 deletions
|
@ -1,68 +1,224 @@
|
|||
package domain
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRelease_Parse(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
fields Release
|
||||
want Release
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "parse_1", fields: Release{
|
||||
ID: 0,
|
||||
Rejections: nil,
|
||||
Indexer: "",
|
||||
FilterName: "",
|
||||
Protocol: "",
|
||||
Implementation: "",
|
||||
Timestamp: time.Time{},
|
||||
TorrentID: "",
|
||||
GroupID: "",
|
||||
TorrentName: "Servant S01 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-FLUX",
|
||||
Raw: "",
|
||||
Title: "",
|
||||
Category: "",
|
||||
Season: 0,
|
||||
Episode: 0,
|
||||
Year: 0,
|
||||
Resolution: "",
|
||||
Source: "",
|
||||
Codec: "",
|
||||
Container: "",
|
||||
HDR: "",
|
||||
Audio: "",
|
||||
Group: "",
|
||||
Region: "",
|
||||
Edition: "",
|
||||
Proper: false,
|
||||
Repack: false,
|
||||
Website: "",
|
||||
Language: "",
|
||||
Unrated: false,
|
||||
Hybrid: false,
|
||||
Size: 0,
|
||||
ThreeD: false,
|
||||
Artists: nil,
|
||||
Type: "",
|
||||
Format: "",
|
||||
Bitrate: "",
|
||||
LogScore: 0,
|
||||
HasLog: false,
|
||||
HasCue: false,
|
||||
IsScene: false,
|
||||
Origin: "",
|
||||
Tags: nil,
|
||||
Freeleech: false,
|
||||
FreeleechPercent: 0,
|
||||
Uploader: "",
|
||||
PreTime: "",
|
||||
TorrentURL: "",
|
||||
Filter: nil,
|
||||
}, wantErr: false},
|
||||
{
|
||||
name: "parse_1",
|
||||
fields: Release{
|
||||
TorrentName: "Servant S01 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-FLUX",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "Servant S01 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-FLUX",
|
||||
Clean: "Servant S01 2160p ATVP WEB DL DDP 5 1 Atmos DV HEVC FLUX",
|
||||
Season: 1,
|
||||
Episode: 0,
|
||||
Resolution: "2160p",
|
||||
Source: "WEB-DL",
|
||||
Codec: "HEVC",
|
||||
HDR: "DV",
|
||||
Audio: "DDP 5.1 Atmos",
|
||||
Group: "FLUX",
|
||||
Website: "ATVP",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_2",
|
||||
fields: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
Clean: "Servant S01 2160p ATVP WEB DL DDP 5 1 Atmos DV HEVC FLUX",
|
||||
Season: 1,
|
||||
Episode: 0,
|
||||
Resolution: "2160p",
|
||||
Source: "WEB-DL",
|
||||
Codec: "HEVC",
|
||||
HDR: "DV",
|
||||
Audio: "DDP.5.1", // need to fix audio parsing
|
||||
Group: "FLUX",
|
||||
Website: "ATVP",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_3",
|
||||
fields: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
ReleaseTags: "MKV / 2160p / WEB-DL",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
Clean: "Servant S01 2160p ATVP WEB DL DDP 5 1 Atmos DV HEVC FLUX",
|
||||
ReleaseTags: "MKV / 2160p / WEB-DL",
|
||||
Container: "MKV",
|
||||
Season: 1,
|
||||
Episode: 0,
|
||||
Resolution: "2160p",
|
||||
Source: "WEB-DL",
|
||||
Codec: "HEVC",
|
||||
HDR: "DV",
|
||||
Audio: "DDP.5.1", // need to fix audio parsing
|
||||
Group: "FLUX",
|
||||
Website: "ATVP",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_4",
|
||||
fields: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
ReleaseTags: "MKV | 2160p | WEB-DL",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
Clean: "Servant S01 2160p ATVP WEB DL DDP 5 1 Atmos DV HEVC FLUX",
|
||||
ReleaseTags: "MKV | 2160p | WEB-DL",
|
||||
Container: "MKV",
|
||||
Season: 1,
|
||||
Episode: 0,
|
||||
Resolution: "2160p",
|
||||
Source: "WEB-DL",
|
||||
Codec: "HEVC",
|
||||
HDR: "DV",
|
||||
Audio: "DDP.5.1", // need to fix audio parsing
|
||||
Group: "FLUX",
|
||||
Website: "ATVP",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_5",
|
||||
fields: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
ReleaseTags: "MP4 | 2160p | WEB-DL",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
Clean: "Servant S01 2160p ATVP WEB DL DDP 5 1 Atmos DV HEVC FLUX",
|
||||
ReleaseTags: "MP4 | 2160p | WEB-DL",
|
||||
Container: "MP4",
|
||||
Season: 1,
|
||||
Episode: 0,
|
||||
Resolution: "2160p",
|
||||
Source: "WEB-DL",
|
||||
Codec: "HEVC",
|
||||
HDR: "DV",
|
||||
Audio: "DDP.5.1", // need to fix audio parsing
|
||||
Group: "FLUX",
|
||||
Website: "ATVP",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_6",
|
||||
fields: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
ReleaseTags: "MP4 | 2160p | WEB-DL | Freeleech!",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "Servant.S01.2160p.ATVP.WEB-DL.DDP.5.1.Atmos.DV.HEVC-FLUX",
|
||||
Clean: "Servant S01 2160p ATVP WEB DL DDP 5 1 Atmos DV HEVC FLUX",
|
||||
ReleaseTags: "MP4 | 2160p | WEB-DL | Freeleech!",
|
||||
Container: "MP4",
|
||||
Season: 1,
|
||||
Episode: 0,
|
||||
Resolution: "2160p",
|
||||
Source: "WEB-DL",
|
||||
Codec: "HEVC",
|
||||
HDR: "DV",
|
||||
Audio: "DDP.5.1", // need to fix audio parsing
|
||||
Group: "FLUX",
|
||||
Website: "ATVP",
|
||||
Freeleech: true,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_music_1",
|
||||
fields: Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / Cue / CD",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
Clean: "Artist Albumname",
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / Cue / CD",
|
||||
Group: "",
|
||||
Audio: "FLAC",
|
||||
Source: "CD",
|
||||
HasCue: true,
|
||||
HasLog: true,
|
||||
LogScore: 100,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_music_2",
|
||||
fields: Release{
|
||||
TorrentName: "Various Artists - Music '21",
|
||||
Tags: []string{"house, techno, tech.house, electro.house, future.house, bass.house, melodic.house"},
|
||||
ReleaseTags: "MP3 / 320 / Cassette",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "Various Artists - Music '21",
|
||||
Clean: "Various Artists Music '21",
|
||||
Tags: []string{"house, techno, tech.house, electro.house, future.house, bass.house, melodic.house"},
|
||||
ReleaseTags: "MP3 / 320 / Cassette",
|
||||
Group: "",
|
||||
Audio: "MP3",
|
||||
Source: "Cassette",
|
||||
Bitrate: "320",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_music_3",
|
||||
fields: Release{
|
||||
TorrentName: "The artist (ザ・フリーダムユニティ) - Long album name",
|
||||
ReleaseTags: "MP3 / V0 (VBR) / CD",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "The artist (ザ・フリーダムユニティ) - Long album name",
|
||||
Clean: "The artist (ザ・フリーダムユニティ) Long album name",
|
||||
ReleaseTags: "MP3 / V0 (VBR) / CD",
|
||||
Group: "",
|
||||
Audio: "MP3",
|
||||
Source: "CD",
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "parse_music_4",
|
||||
fields: Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / Cue / CD",
|
||||
},
|
||||
want: Release{
|
||||
TorrentName: "Artist - Albumname",
|
||||
Clean: "Artist Albumname",
|
||||
ReleaseTags: "FLAC / Lossless / Log / 100% / Cue / CD",
|
||||
Group: "",
|
||||
Audio: "FLAC",
|
||||
Source: "CD",
|
||||
HasCue: true,
|
||||
HasLog: true,
|
||||
LogScore: 100,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
@ -70,6 +226,8 @@ func TestRelease_Parse(t *testing.T) {
|
|||
if err := r.Parse(); (err != nil) != tt.wantErr {
|
||||
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.want, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +301,55 @@ func TestRelease_CheckFilter(t *testing.T) {
|
|||
},
|
||||
want: true,
|
||||
},
|
||||
|
||||
{
|
||||
name: "movie_parse_2",
|
||||
fields: &Release{
|
||||
TorrentName: "That Movie 2020 2160p Blu-Ray DD5.1 x264-GROUP1",
|
||||
Category: "Movies",
|
||||
Freeleech: true,
|
||||
Size: uint64(30000000001),
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "Movies",
|
||||
Freeleech: true,
|
||||
MinSize: "10 GB",
|
||||
MaxSize: "40GB",
|
||||
Resolutions: []string{"2160p"},
|
||||
Sources: []string{"BluRay"},
|
||||
Codecs: []string{"x264"},
|
||||
Years: "2020",
|
||||
MatchReleaseGroups: "GROUP1",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "movie_parse_3",
|
||||
fields: &Release{
|
||||
TorrentName: "That Movie 2020 2160p WEBDL DD5.1 x264-GROUP1",
|
||||
Category: "Movies",
|
||||
Freeleech: true,
|
||||
Size: uint64(30000000001),
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "Movies",
|
||||
Freeleech: true,
|
||||
MinSize: "10 GB",
|
||||
MaxSize: "40GB",
|
||||
Resolutions: []string{"2160p"},
|
||||
Sources: []string{"WEB-DL"},
|
||||
Codecs: []string{"x264"},
|
||||
Years: "2020",
|
||||
MatchReleaseGroups: "GROUP1",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "movie_parse_shows",
|
||||
fields: &Release{
|
||||
|
@ -168,6 +375,31 @@ func TestRelease_CheckFilter(t *testing.T) {
|
|||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "movie_parse_shows_1",
|
||||
fields: &Release{
|
||||
TorrentName: "That.Movie.2020.2160p.BluRay.DD5.1.x264-GROUP1",
|
||||
Category: "Movies",
|
||||
Freeleech: true,
|
||||
Size: uint64(30000000001),
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "Movies",
|
||||
Freeleech: true,
|
||||
MinSize: "10 GB",
|
||||
MaxSize: "40GB",
|
||||
Resolutions: []string{"2160p"},
|
||||
Sources: []string{"BluRay"},
|
||||
Codecs: []string{"x264"},
|
||||
Years: "2020",
|
||||
MatchReleaseGroups: "GROUP1",
|
||||
Shows: "That Movie",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "movie_parse_multiple_shows",
|
||||
fields: &Release{
|
||||
|
@ -193,6 +425,31 @@ func TestRelease_CheckFilter(t *testing.T) {
|
|||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "movie_parse_multiple_shows_1",
|
||||
fields: &Release{
|
||||
TorrentName: "That.Movie.2020.2160p.BluRay.DD5.1.x264-GROUP1",
|
||||
Category: "Movies",
|
||||
Freeleech: true,
|
||||
Size: uint64(30000000001),
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "Movies",
|
||||
Freeleech: true,
|
||||
MinSize: "10 GB",
|
||||
MaxSize: "40GB",
|
||||
Resolutions: []string{"2160p"},
|
||||
Sources: []string{"BluRay"},
|
||||
Codecs: []string{"x264"},
|
||||
Years: "2020",
|
||||
MatchReleaseGroups: "GROUP1",
|
||||
Shows: "That Movie, good story, bad movie",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "movie_parse_wildcard_shows",
|
||||
fields: &Release{
|
||||
|
@ -346,6 +603,182 @@ func TestRelease_CheckFilter(t *testing.T) {
|
|||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "match_tags",
|
||||
fields: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "TV",
|
||||
Uploader: "Uploader1",
|
||||
Tags: []string{"tv"},
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show",
|
||||
Tags: "tv",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "match_tags_bad",
|
||||
fields: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "TV",
|
||||
Uploader: "Uploader1",
|
||||
Tags: []string{"foreign"},
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show",
|
||||
Tags: "tv",
|
||||
},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "match_except_tags",
|
||||
fields: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "TV",
|
||||
Uploader: "Uploader1",
|
||||
Tags: []string{"foreign"},
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show",
|
||||
ExceptTags: "tv",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "match_except_tags_2",
|
||||
fields: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "TV",
|
||||
Uploader: "Uploader1",
|
||||
Tags: []string{"foreign"},
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show",
|
||||
ExceptTags: "foreign",
|
||||
},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "match_group_1",
|
||||
fields: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP",
|
||||
Category: "TV",
|
||||
Uploader: "Uploader1",
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show",
|
||||
MatchReleaseGroups: "GROUP",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "match_group_potential_partial_1",
|
||||
fields: &Release{
|
||||
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-ift",
|
||||
Category: "TV",
|
||||
Uploader: "Uploader1",
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show shift",
|
||||
MatchReleaseGroups: "ift",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "match_group_potential_partial_2",
|
||||
fields: &Release{
|
||||
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP",
|
||||
Category: "TV",
|
||||
Uploader: "Uploader1",
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show shift",
|
||||
MatchReleaseGroups: "ift",
|
||||
},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "match_group_potential_partial_3",
|
||||
fields: &Release{
|
||||
TorrentName: "Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-de[42]",
|
||||
Category: "TV",
|
||||
Uploader: "Uploader1",
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show shift",
|
||||
MatchReleaseGroups: "de[42]",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "match_group_potential_partial_3",
|
||||
fields: &Release{
|
||||
TorrentName: "[AnimeGroup] Good show shift S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC",
|
||||
Category: "TV",
|
||||
Uploader: "Uploader1",
|
||||
},
|
||||
args: args{
|
||||
filter: Filter{
|
||||
Enabled: true,
|
||||
MatchCategories: "*tv*",
|
||||
MatchUploaders: "Uploader1,Uploader2",
|
||||
ExceptUploaders: "Anonymous",
|
||||
Shows: "Good show shift",
|
||||
MatchReleaseGroups: "[AnimeGroup]",
|
||||
},
|
||||
},
|
||||
want: true,
|
||||
|
@ -362,3 +795,194 @@ func TestRelease_CheckFilter(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRelease_MapVars(t *testing.T) {
|
||||
type args struct {
|
||||
varMap map[string]string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields *Release
|
||||
want *Release
|
||||
args args
|
||||
}{
|
||||
{
|
||||
name: "1",
|
||||
fields: &Release{},
|
||||
want: &Release{TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2"},
|
||||
args: args{varMap: map[string]string{
|
||||
"torrentName": "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "2",
|
||||
fields: &Release{},
|
||||
want: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
Freeleech: true,
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
},
|
||||
args: args{varMap: map[string]string{
|
||||
"torrentName": "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
"category": "tv",
|
||||
"freeleech": "freeleech",
|
||||
"uploader": "Anon",
|
||||
"torrentSize": "10GB",
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "3",
|
||||
fields: &Release{},
|
||||
want: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
FreeleechPercent: 100,
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
},
|
||||
args: args{varMap: map[string]string{
|
||||
"torrentName": "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
"category": "tv",
|
||||
"freeleechPercent": "100%",
|
||||
"uploader": "Anon",
|
||||
"torrentSize": "10GB",
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "4",
|
||||
fields: &Release{},
|
||||
want: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
FreeleechPercent: 100,
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
Tags: []string{"foreign", "tv"},
|
||||
},
|
||||
args: args{varMap: map[string]string{
|
||||
"torrentName": "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
"category": "tv",
|
||||
"freeleechPercent": "100%",
|
||||
"uploader": "Anon",
|
||||
"torrentSize": "10GB",
|
||||
"tags": "foreign,tv",
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "5",
|
||||
fields: &Release{},
|
||||
want: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
FreeleechPercent: 100,
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
Tags: []string{"foreign", "tv"},
|
||||
},
|
||||
args: args{varMap: map[string]string{
|
||||
"torrentName": "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
"category": "tv",
|
||||
"freeleechPercent": "100%",
|
||||
"uploader": "Anon",
|
||||
"torrentSize": "10GB",
|
||||
"tags": "foreign,tv",
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "6",
|
||||
fields: &Release{},
|
||||
want: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
Year: 2020,
|
||||
FreeleechPercent: 100,
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
Tags: []string{"foreign", "tv"},
|
||||
},
|
||||
args: args{varMap: map[string]string{
|
||||
"torrentName": "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
"category": "tv",
|
||||
"year": "2020",
|
||||
"freeleechPercent": "100%",
|
||||
"uploader": "Anon",
|
||||
"torrentSize": "10GB",
|
||||
"tags": "foreign, tv",
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "7",
|
||||
fields: &Release{},
|
||||
want: &Release{
|
||||
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
Category: "tv",
|
||||
Year: 2020,
|
||||
FreeleechPercent: 100,
|
||||
Uploader: "Anon",
|
||||
Size: uint64(10000000000),
|
||||
Tags: []string{"hip.hop", "rhythm.and.blues", "2000s"},
|
||||
},
|
||||
args: args{varMap: map[string]string{
|
||||
"torrentName": "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
||||
"category": "tv",
|
||||
"year": "2020",
|
||||
"freeleechPercent": "100%",
|
||||
"uploader": "Anon",
|
||||
"torrentSize": "10GB",
|
||||
"tags": "hip.hop,rhythm.and.blues, 2000s",
|
||||
}},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := tt.fields
|
||||
_ = r.MapVars(tt.args.varMap)
|
||||
|
||||
assert.Equal(t, tt.want, r)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitAny(t *testing.T) {
|
||||
type args struct {
|
||||
s string
|
||||
seps string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "test_1",
|
||||
args: args{
|
||||
s: "Tag1 / Tag2 / Tag3",
|
||||
seps: "/ ",
|
||||
},
|
||||
want: []string{"Tag1", "Tag2", "Tag3"},
|
||||
},
|
||||
{
|
||||
name: "test_2",
|
||||
args: args{
|
||||
s: "Tag1 | Tag2 | Tag3",
|
||||
seps: "| ",
|
||||
},
|
||||
want: []string{"Tag1", "Tag2", "Tag3"},
|
||||
},
|
||||
{
|
||||
name: "test_3",
|
||||
args: args{
|
||||
s: "Tag1 | Tag2 / Tag3",
|
||||
seps: "| /",
|
||||
},
|
||||
want: []string{"Tag1", "Tag2", "Tag3"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equalf(t, tt.want, SplitAny(tt.args.s, tt.args.seps), "SplitAny(%v, %v)", tt.args.s, tt.args.seps)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue