Skip to content

Commit

Permalink
fix(processor): don't match sample in torrents (#160)
Browse files Browse the repository at this point in the history
* fix(processor): don't match sample in torrents

* chore(processor): add tests for IsValidEpisodeFile
  • Loading branch information
nuxencs authored Nov 8, 2024
1 parent 65be43b commit daf337e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/http/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (p *processor) processSeasonPack() (domain.StatusCode, error) {
var fileName string
var size int64
for _, f := range *torrentFiles {
if filepath.Ext(f.Name) != ".mkv" {
if !release.IsValidEpisodeFile(f.Name) {
continue
}

Expand Down
16 changes: 16 additions & 0 deletions internal/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,19 @@ func PercentOfTotalEpisodes(totalEps int, foundEps int) float32 {

return float32(foundEps) / float32(totalEps)
}

func IsValidEpisodeFile(torrentFileName string) bool {
torrentFileRls := rls.ParseString(filepath.Base(torrentFileName))

// ignore non video files
if torrentFileRls.Ext != "mkv" {
return false
}

// ignore sample files
if rls.MustNormalize(torrentFileRls.Group) == "sample" {
return false
}

return true
}
52 changes: 52 additions & 0 deletions internal/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,55 @@ func Test_MatchEpToSeasonPackEp(t *testing.T) {
})
}
}

func Test_IsValidEpisodeFile(t *testing.T) {
type args struct {
torrentFileName string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "sample_with_dash",
args: args{
torrentFileName: "test.release.s06e03.dutch.1080p.web.h264-rlsgrp-sample.mkv",
},
want: false,
},
{
name: "sample_with_dot",
args: args{
torrentFileName: "test.release.s06e03.dutch.1080p.web.h264-rlsgrp.sample.mkv",
},
want: false,
},
{
name: "wrong_ext",
args: args{
torrentFileName: "test.release.s06e03.dutch.1080p.web.h264-rlsgrp.nfo",
},
want: false,
},
{
name: "wrong_ext_and_sample",
args: args{
torrentFileName: "test.release.s06e03.dutch.1080p.web.h264-rlsgrp.sample.nfo",
},
want: false,
},
{
name: "valid_release",
args: args{
torrentFileName: "test.release.s06e03.dutch.1080p.web.h264-rlsgrp.mkv",
},
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, IsValidEpisodeFile(tt.args.torrentFileName), "IsValidEpisodeFile(%v)", tt.args.torrentFileName)
})
}
}

0 comments on commit daf337e

Please sign in to comment.