diff --git a/internal/utils/formatting.go b/internal/utils/formatting.go index 758f63a..97e1813 100644 --- a/internal/utils/formatting.go +++ b/internal/utils/formatting.go @@ -77,3 +77,13 @@ func compareEpisodes(episodeRls, torrentEpRls rls.Release) error { return nil } + +func normalizeTitle(title string) string { + punctuationRegex := regexp.MustCompile(`[^\w\s]`) + duplicateSpacesRegex := regexp.MustCompile(`\s{2,}`) + + title = punctuationRegex.ReplaceAllString(title, "") + title = duplicateSpacesRegex.ReplaceAllString(title, " ") + + return title +} diff --git a/internal/utils/tvmaze.go b/internal/utils/tvmaze.go index eb20ce1..0c9e6e3 100644 --- a/internal/utils/tvmaze.go +++ b/internal/utils/tvmaze.go @@ -6,20 +6,24 @@ package utils import ( "fmt" + "seasonpackarr/pkg/errors" + "github.com/mrobinsn/go-tvmaze/tvmaze" ) func GetEpisodesPerSeason(title string, season int) (int, error) { totalEpisodes := 0 - show, err := tvmaze.DefaultClient.GetShow(title) + normalizedTitle := normalizeTitle(title) + + show, err := tvmaze.DefaultClient.GetShow(normalizedTitle) if err != nil { - return 0, err + return 0, errors.Wrap(err, "could not find show on tvmaze") } episodes, err := show.GetEpisodes() if err != nil { - return 0, err + return 0, errors.Wrap(err, "could not get episodes from tvmaze") } for _, episode := range episodes { diff --git a/internal/utils/tvmaze_test.go b/internal/utils/tvmaze_test.go index 21334b9..7b3bdd1 100644 --- a/internal/utils/tvmaze_test.go +++ b/internal/utils/tvmaze_test.go @@ -52,6 +52,13 @@ func Test_GetEpisodesPerSeason(t *testing.T) { want: 5, wantErr: false, }, + { + name: "show_with_punctuation", + title: "Orphan Black - Echoes", + season: 1, + want: 10, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {