Skip to content

Commit

Permalink
fix(tvmaze): search for normalized show title (#133)
Browse files Browse the repository at this point in the history
* fix(tvmaze): search for normalized show title

* refactor(utils): use rls normalize function

* chore(tvmaze): don't save normalized title to var
  • Loading branch information
nuxencs authored Aug 29, 2024
1 parent 7a3aa64 commit 78624fd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions internal/utils/formatting.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func compareEpisodes(episodeRls, torrentEpRls rls.Release) error {

return nil
}

func normalizeTitle(title string) string {
return rls.MustNormalize(title)
}
10 changes: 6 additions & 4 deletions internal/utils/tvmaze.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ 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)
show, err := tvmaze.DefaultClient.GetShow(normalizeTitle(title))
if err != nil {
return 0, err
return 0, errors.Wrap(err, "failed to find show on tvmaze")
}

episodes, err := show.GetEpisodes()
if err != nil {
return 0, err
return 0, errors.Wrap(err, "failed to get episodes from tvmaze")
}

for _, episode := range episodes {
Expand All @@ -29,7 +31,7 @@ func GetEpisodesPerSeason(title string, season int) (int, error) {
}

if totalEpisodes == 0 {
return 0, fmt.Errorf("couldn't find episodes in season %d of %q", season, title)
return 0, fmt.Errorf("failed to find episodes in season %d of %q", season, title)
}

return totalEpisodes, nil
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 78624fd

Please sign in to comment.