Skip to content

Commit

Permalink
fix(tvmaze): search for normalized show title
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxencs committed Aug 25, 2024
1 parent 7a3aa64 commit 06fa08d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
10 changes: 10 additions & 0 deletions internal/utils/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 7 additions & 3 deletions internal/utils/tvmaze.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions internal/utils/tvmaze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 06fa08d

Please sign in to comment.