From 38421c3962cae249ac43377d815be7087bef1300 Mon Sep 17 00:00:00 2001 From: nuxen Date: Fri, 11 Oct 2024 23:19:48 +0200 Subject: [PATCH] refactor: clean up client-to-torrent episode matching (#151) * refactor: clean up client-to-torrent eps matching * chore(tests): properly use assert package * chore(tests): sort imports * chore: fix import order and rename CompareInfo fields * chore(processor): var rename to follow current naming --- internal/domain/http.go | 13 +- internal/domain/release.go | 6 +- internal/http/processor.go | 16 +-- internal/release/release.go | 92 ++++++++++---- internal/release/release_test.go | 193 ++++++++++++++++++++++++++++++ internal/utils/formatting.go | 37 ------ internal/utils/formatting_test.go | 147 ----------------------- 7 files changed, 282 insertions(+), 222 deletions(-) create mode 100644 internal/release/release_test.go diff --git a/internal/domain/http.go b/internal/domain/http.go index 256f37d..9fd3e54 100644 --- a/internal/domain/http.go +++ b/internal/domain/http.go @@ -3,9 +3,7 @@ package domain -import ( - "fmt" -) +import "fmt" type StatusCode int @@ -21,6 +19,9 @@ const ( StatusStreamingServiceMismatch StatusCode = 208 StatusAlreadyInClient StatusCode = 210 StatusNotASeasonPack StatusCode = 211 + StatusSizeMismatch StatusCode = 212 + StatusSeasonMismatch StatusCode = 213 + StatusEpisodeMismatch StatusCode = 214 StatusBelowThreshold StatusCode = 230 StatusSuccessfulMatch StatusCode = 250 StatusSuccessfulHardlink StatusCode = 250 @@ -62,6 +63,12 @@ func (s StatusCode) String() string { return "release already in client" case StatusNotASeasonPack: return "release is not a season pack" + case StatusSizeMismatch: + return "size did not match" + case StatusSeasonMismatch: + return "season did not match" + case StatusEpisodeMismatch: + return "episode did not match" case StatusBelowThreshold: return "number of matches below threshold" case StatusSuccessfulMatch: diff --git a/internal/domain/release.go b/internal/domain/release.go index 1ce2e61..8c32983 100644 --- a/internal/domain/release.go +++ b/internal/domain/release.go @@ -4,7 +4,7 @@ package domain type CompareInfo struct { - StatusCode StatusCode - RequestRejectField any - ClientRejectField any + StatusCode StatusCode + RejectValueA any + RejectValueB any } diff --git a/internal/http/processor.go b/internal/http/processor.go index a2cee22..8f5bea2 100644 --- a/internal/http/processor.go +++ b/internal/http/processor.go @@ -260,8 +260,8 @@ func (p *processor) processSeasonPack() (domain.StatusCode, error) { domain.StatusCutMismatch, domain.StatusEditionMismatch, domain.StatusRepackStatusMismatch, domain.StatusHdrMismatch, domain.StatusStreamingServiceMismatch: p.log.Info().Msgf("%s: request(%s => %v), client(%s => %v)", - compareInfo.StatusCode, requestRls.String(), compareInfo.RequestRejectField, - clientEntry.r.String(), compareInfo.ClientRejectField) + compareInfo.StatusCode, requestRls.String(), compareInfo.RejectValueA, + clientEntry.r.String(), compareInfo.RejectValueB) codeSet[compareInfo.StatusCode] = true continue @@ -453,7 +453,7 @@ func (p *processor) parseTorrent() (domain.StatusCode, error) { successfulHardlink := false var matchedEpPath string - var matchErr error + var compareInfo domain.CompareInfo var targetEpPath string targetPackDir := filepath.Join(clientCfg.PreImportPath, parsedPackName) @@ -463,11 +463,11 @@ func (p *processor) parseTorrent() (domain.StatusCode, error) { // reset targetEpPath for each checked torrentEp targetEpPath = "" - matchedEpPath, matchErr = utils.MatchEpToSeasonPackEp(match.clientEpPath, match.clientEpSize, + matchedEpPath, compareInfo = release.MatchEpToSeasonPackEp(match.clientEpPath, match.clientEpSize, torrentEp.Path, torrentEp.Size) - if matchErr != nil { - p.log.Debug().Err(matchErr).Msgf("episode did not match: client(%s), torrent(%s)", - filepath.Base(match.clientEpPath), torrentEp.Path) + if len(matchedEpPath) == 0 { + p.log.Debug().Msgf("%s: client(%s => %v), torrent(%s => %v)", compareInfo.StatusCode, + filepath.Base(match.clientEpPath), compareInfo.RejectValueA, torrentEp.Path, compareInfo.RejectValueB) continue } targetEpPath = filepath.Join(targetPackDir, matchedEpPath) @@ -482,7 +482,7 @@ func (p *processor) parseTorrent() (domain.StatusCode, error) { break } - if matchErr != nil { + if len(matchedEpPath) == 0 { p.log.Error().Msgf("error matching episode to file in pack, skipping hardlink: %s", filepath.Base(match.clientEpPath)) continue diff --git a/internal/release/release.go b/internal/release/release.go index 2ba228a..dd66500 100644 --- a/internal/release/release.go +++ b/internal/release/release.go @@ -4,6 +4,8 @@ package release import ( + "path/filepath" + "github.com/nuxencs/seasonpackarr/internal/domain" "github.com/nuxencs/seasonpackarr/internal/utils" @@ -23,41 +25,41 @@ func CheckCandidates(requestRls, clientRls rls.Release, fuzzyMatching domain.Fuz func compareReleases(requestRls, clientRls rls.Release, fuzzyMatching domain.FuzzyMatching) domain.CompareInfo { if rls.MustNormalize(requestRls.Resolution) != rls.MustNormalize(clientRls.Resolution) { return domain.CompareInfo{ - StatusCode: domain.StatusResolutionMismatch, - RequestRejectField: requestRls.Resolution, - ClientRejectField: clientRls.Resolution, + StatusCode: domain.StatusResolutionMismatch, + RejectValueA: requestRls.Resolution, + RejectValueB: clientRls.Resolution, } } if rls.MustNormalize(requestRls.Source) != rls.MustNormalize(clientRls.Source) { return domain.CompareInfo{ - StatusCode: domain.StatusSourceMismatch, - RequestRejectField: requestRls.Source, - ClientRejectField: clientRls.Source, + StatusCode: domain.StatusSourceMismatch, + RejectValueA: requestRls.Source, + RejectValueB: clientRls.Source, } } if rls.MustNormalize(requestRls.Group) != rls.MustNormalize(clientRls.Group) { return domain.CompareInfo{ - StatusCode: domain.StatusRlsGrpMismatch, - RequestRejectField: requestRls.Group, - ClientRejectField: clientRls.Group, + StatusCode: domain.StatusRlsGrpMismatch, + RejectValueA: requestRls.Group, + RejectValueB: clientRls.Group, } } if !utils.EqualElements(requestRls.Cut, clientRls.Cut) { return domain.CompareInfo{ - StatusCode: domain.StatusCutMismatch, - RequestRejectField: requestRls.Cut, - ClientRejectField: clientRls.Cut, + StatusCode: domain.StatusCutMismatch, + RejectValueA: requestRls.Cut, + RejectValueB: clientRls.Cut, } } if !utils.EqualElements(requestRls.Edition, clientRls.Edition) { return domain.CompareInfo{ - StatusCode: domain.StatusEditionMismatch, - RequestRejectField: requestRls.Edition, - ClientRejectField: clientRls.Edition, + StatusCode: domain.StatusEditionMismatch, + RejectValueA: requestRls.Edition, + RejectValueB: clientRls.Edition, } } @@ -65,9 +67,9 @@ func compareReleases(requestRls, clientRls rls.Release, fuzzyMatching domain.Fuz if !fuzzyMatching.SkipRepackCompare { if !utils.EqualElements(requestRls.Other, clientRls.Other) { return domain.CompareInfo{ - StatusCode: domain.StatusRepackStatusMismatch, - RequestRejectField: requestRls.Other, - ClientRejectField: clientRls.Other, + StatusCode: domain.StatusRepackStatusMismatch, + RejectValueA: requestRls.Other, + RejectValueB: clientRls.Other, } } } @@ -80,17 +82,17 @@ func compareReleases(requestRls, clientRls rls.Release, fuzzyMatching domain.Fuz if !utils.EqualElements(requestRls.HDR, clientRls.HDR) { return domain.CompareInfo{ - StatusCode: domain.StatusHdrMismatch, - RequestRejectField: requestRls.HDR, - ClientRejectField: clientRls.HDR, + StatusCode: domain.StatusHdrMismatch, + RejectValueA: requestRls.HDR, + RejectValueB: clientRls.HDR, } } if requestRls.Collection != clientRls.Collection { return domain.CompareInfo{ - StatusCode: domain.StatusStreamingServiceMismatch, - RequestRejectField: requestRls.Collection, - ClientRejectField: clientRls.Collection, + StatusCode: domain.StatusStreamingServiceMismatch, + RejectValueA: requestRls.Collection, + RejectValueB: clientRls.Collection, } } @@ -101,6 +103,48 @@ func compareReleases(requestRls, clientRls rls.Release, fuzzyMatching domain.Fuz return domain.CompareInfo{StatusCode: domain.StatusSuccessfulMatch} } +func MatchEpToSeasonPackEp(clientEpPath string, clientEpSize int64, torrentEpPath string, torrentEpSize int64) (string, domain.CompareInfo) { + if clientEpSize != torrentEpSize { + return "", domain.CompareInfo{ + StatusCode: domain.StatusSizeMismatch, + RejectValueA: clientEpSize, + RejectValueB: torrentEpSize, + } + } + + clientEpRls := rls.ParseString(filepath.Base(clientEpPath)) + torrentEpRls := rls.ParseString(filepath.Base(torrentEpPath)) + + switch { + case clientEpRls.Series != torrentEpRls.Series: + return "", domain.CompareInfo{ + StatusCode: domain.StatusSeasonMismatch, + RejectValueA: clientEpRls.Series, + RejectValueB: torrentEpRls.Series, + } + case clientEpRls.Episode != torrentEpRls.Episode: + return "", domain.CompareInfo{ + StatusCode: domain.StatusEpisodeMismatch, + RejectValueA: clientEpRls.Episode, + RejectValueB: torrentEpRls.Episode, + } + case clientEpRls.Resolution != torrentEpRls.Resolution: + return "", domain.CompareInfo{ + StatusCode: domain.StatusResolutionMismatch, + RejectValueA: clientEpRls.Resolution, + RejectValueB: torrentEpRls.Resolution, + } + case rls.MustNormalize(clientEpRls.Group) != rls.MustNormalize(torrentEpRls.Group): + return "", domain.CompareInfo{ + StatusCode: domain.StatusRlsGrpMismatch, + RejectValueA: clientEpRls.Group, + RejectValueB: torrentEpRls.Group, + } + } + + return torrentEpPath, domain.CompareInfo{} +} + func PercentOfTotalEpisodes(totalEps int, foundEps int) float32 { if totalEps == 0 { return 0 diff --git a/internal/release/release_test.go b/internal/release/release_test.go new file mode 100644 index 0000000..f99bc3f --- /dev/null +++ b/internal/release/release_test.go @@ -0,0 +1,193 @@ +package release + +import ( + "testing" + + "github.com/nuxencs/seasonpackarr/internal/domain" + + "github.com/stretchr/testify/assert" +) + +func Test_MatchEpToSeasonPackEp(t *testing.T) { + type args struct { + clientEpPath string + clientEpSize int64 + torrentEpPath string + torrentEpSize int64 + } + + type compare struct { + path string + info domain.CompareInfo + } + + tests := []struct { + name string + args args + want compare + }{ + { + name: "found_match", + args: args{ + clientEpPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Series Title 2022 S02E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + torrentEpSize: 2316560346, + }, + want: compare{ + path: "Series Title 2022 S02E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + info: domain.CompareInfo{}, + }, + }, + { + name: "wrong_episode", + args: args{ + clientEpPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Series Title 2022 S02E02 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + torrentEpSize: 2316560346, + }, + want: compare{ + path: "", + info: domain.CompareInfo{ + StatusCode: domain.StatusEpisodeMismatch, + RejectValueA: 1, + RejectValueB: 2, + }, + }, + }, + { + name: "wrong_season", + args: args{ + clientEpPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Series Title 2022 S03E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + torrentEpSize: 2316560346, + }, + want: compare{ + path: "", + info: domain.CompareInfo{ + StatusCode: domain.StatusSeasonMismatch, + RejectValueA: 2, + RejectValueB: 3, + }, + }, + }, + { + name: "wrong_resolution", + args: args{ + clientEpPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Series Title 2022 S02E01 2160p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + torrentEpSize: 2316560346, + }, + want: compare{ + path: "", + info: domain.CompareInfo{ + StatusCode: domain.StatusResolutionMismatch, + RejectValueA: "1080p", + RejectValueB: "2160p", + }, + }, + }, + { + name: "wrong_rlsgrp", + args: args{ + clientEpPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Series Title 2022 S02E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-OtherRlsGrp.mkv", + torrentEpSize: 2316560346, + }, + want: compare{ + path: "", + info: domain.CompareInfo{ + StatusCode: domain.StatusRlsGrpMismatch, + RejectValueA: "RlsGrp", + RejectValueB: "OtherRlsGrp", + }, + }, + }, + { + name: "wrong_size", + args: args{ + clientEpPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Series Title 2022 S02E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + torrentEpSize: 2278773077, + }, + want: compare{ + path: "", + info: domain.CompareInfo{ + StatusCode: domain.StatusSizeMismatch, + RejectValueA: int64(2316560346), + RejectValueB: int64(2278773077), + }, + }, + }, + { + name: "subfolder_in_client", + args: args{ + clientEpPath: "Test/Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + torrentEpSize: 2316560346, + }, + want: compare{ + path: "Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + info: domain.CompareInfo{}, + }, + }, + { + name: "subfolder_in_torrent", + args: args{ + clientEpPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + torrentEpSize: 2316560346, + }, + want: compare{ + path: "Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + info: domain.CompareInfo{}, + }, + }, + { + name: "subfolder_in_both", + args: args{ + clientEpPath: "Test/Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + torrentEpSize: 2316560346, + }, + want: compare{ + path: "Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + info: domain.CompareInfo{}, + }, + }, + { + name: "multi_subfolder", + args: args{ + clientEpPath: "/data/torrents/tv/Test/Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + clientEpSize: 2316560346, + torrentEpPath: "Series Title 2022 S02/Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + torrentEpSize: 2316560346, + }, + want: compare{ + path: "Series Title 2022 S02/Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", + info: domain.CompareInfo{}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + gotPath, gotInfo := MatchEpToSeasonPackEp(tt.args.clientEpPath, tt.args.clientEpSize, tt.args.torrentEpPath, tt.args.torrentEpSize) + + got := compare{ + path: gotPath, + info: gotInfo, + } + + assert.Equalf(t, tt.want, got, "MatchEpToSeasonPackEp(%v, %v, %v, %v)", + tt.args.clientEpPath, tt.args.clientEpSize, tt.args.torrentEpPath, tt.args.torrentEpSize) + }) + } +} diff --git a/internal/utils/formatting.go b/internal/utils/formatting.go index f0e03e4..952e31b 100644 --- a/internal/utils/formatting.go +++ b/internal/utils/formatting.go @@ -5,7 +5,6 @@ package utils import ( "fmt" - "path/filepath" "regexp" "strings" @@ -42,42 +41,6 @@ func FormatSeasonPackTitle(packName string) string { return packName } -func MatchEpToSeasonPackEp(clientEpPath string, clientEpSize int64, torrentEpPath string, torrentEpSize int64) (string, error) { - epInClientRls := rls.ParseString(filepath.Base(clientEpPath)) - epInTorrentRls := rls.ParseString(filepath.Base(torrentEpPath)) - - err := compareEpisodes(epInClientRls, epInTorrentRls) - if err != nil { - return "", err - } - - if clientEpSize != torrentEpSize { - return "", fmt.Errorf("size mismatch") - } - - return torrentEpPath, nil -} - -func compareEpisodes(episodeRls, torrentEpRls rls.Release) error { - if episodeRls.Series != torrentEpRls.Series { - return fmt.Errorf("season mismatch") - } - - if episodeRls.Episode != torrentEpRls.Episode { - return fmt.Errorf("episode mismatch") - } - - if episodeRls.Resolution != torrentEpRls.Resolution { - return fmt.Errorf("resolution mismatch") - } - - if rls.MustNormalize(episodeRls.Group) != rls.MustNormalize(torrentEpRls.Group) { - return fmt.Errorf("group mismatch") - } - - return nil -} - func normalizeTitle(title string) string { return rls.MustNormalize(title) } diff --git a/internal/utils/formatting_test.go b/internal/utils/formatting_test.go index 565ce40..6251338 100644 --- a/internal/utils/formatting_test.go +++ b/internal/utils/formatting_test.go @@ -4,7 +4,6 @@ package utils import ( - "fmt" "testing" "github.com/moistari/rls" @@ -174,149 +173,3 @@ func Test_FormatSeasonPackTitle(t *testing.T) { }) } } - -func Test_MatchEpToSeasonPackEp(t *testing.T) { - type args struct { - epInClientPath string - epInClientSize int64 - torrentEpPath string - torrentEpSize int64 - } - tests := []struct { - name string - args args - want string - wantErr assert.ErrorAssertionFunc - }{ - { - name: "found_match", - args: args{ - epInClientPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Series Title 2022 S02E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - torrentEpSize: 2316560346, - }, - want: "Series Title 2022 S02E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - wantErr: assert.NoError, - }, - { - name: "wrong_episode", - args: args{ - epInClientPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Series Title 2022 S02E02 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - torrentEpSize: 2316560346, - }, - want: "", - wantErr: assert.Error, - }, - { - name: "wrong_season", - args: args{ - epInClientPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Series Title 2022 S03E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - torrentEpSize: 2316560346, - }, - want: "", - wantErr: assert.Error, - }, - { - name: "wrong_resolution", - args: args{ - epInClientPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Series Title 2022 S02E01 2160p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - torrentEpSize: 2316560346, - }, - want: "", - wantErr: assert.Error, - }, - { - name: "wrong_rlsgrp", - args: args{ - epInClientPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Series Title 2022 S02E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-OtherRlsGrp.mkv", - torrentEpSize: 2316560346, - }, - want: "", - wantErr: assert.Error, - }, - { - name: "wrong_size", - args: args{ - epInClientPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Series Title 2022 S02E01 1080p Test ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - torrentEpSize: 2278773077, - }, - want: "", - wantErr: assert.Error, - }, - { - name: "found_no_match", - args: args{ - epInClientPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "", - torrentEpSize: 0, - }, - want: "", - wantErr: assert.Error, - }, - { - name: "subfolder_in_client", - args: args{ - epInClientPath: "Test/Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - torrentEpSize: 2316560346, - }, - want: "Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - wantErr: assert.NoError, - }, - { - name: "subfolder_in_torrent", - args: args{ - epInClientPath: "Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - torrentEpSize: 2316560346, - }, - want: "Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - wantErr: assert.NoError, - }, - { - name: "subfolder_in_both", - args: args{ - epInClientPath: "Test/Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - torrentEpSize: 2316560346, - }, - want: "Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - wantErr: assert.NoError, - }, - { - name: "multi_subfolder", - args: args{ - epInClientPath: "/data/torrents/tv/Test/Series Title 2022 S02E01 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - epInClientSize: 2316560346, - torrentEpPath: "Series Title 2022 S02/Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - torrentEpSize: 2316560346, - }, - want: "Series Title 2022 S02/Test/Series Title 2022 S02E01 Test 1080p ATVP WEB-DL DDP 5.1 Atmos H.264-RlsGrp.mkv", - wantErr: assert.NoError, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := MatchEpToSeasonPackEp(tt.args.epInClientPath, tt.args.epInClientSize, tt.args.torrentEpPath, tt.args.torrentEpSize) - if !tt.wantErr(t, err, fmt.Sprintf("MatchEpToSeasonPackEp(%v, %v, %v, %v)", tt.args.epInClientPath, tt.args.epInClientSize, tt.args.torrentEpPath, tt.args.torrentEpSize)) { - return - } - assert.Equalf(t, tt.want, got, "MatchEpToSeasonPackEp(%v, %v, %v, %v)", tt.args.epInClientPath, tt.args.epInClientSize, tt.args.torrentEpPath, tt.args.torrentEpSize) - }) - } -}