Skip to content

Commit

Permalink
trakt: add support for networks and status filters on show searches
Browse files Browse the repository at this point in the history
  • Loading branch information
l3uddz committed Feb 10, 2020
1 parent d2c86d1 commit f17ab2a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var (
flagGenre string
flagYear string
flagRating string
flagNetwork string
flagStatus string

// Global vars
log *logrus.Entry
Expand Down
14 changes: 12 additions & 2 deletions cmd/shows.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ var showsCmd = &cobra.Command{
params := map[string]string{
"country": flagCountry,
"language": flagLanguage,
"genre": flagGenre,
"year": flagYear,
"rating": flagRating,
"network": flagNetwork,
"status": flagStatus,
}

// retrieve media
Expand Down Expand Up @@ -88,6 +93,11 @@ func init() {

showsCmd.Flags().IntVar(&flagLimit, "limit", 0, "Max accepted items to add.")

showsCmd.Flags().StringVar(&flagCountry, "country", "", "Country to filter results.")
showsCmd.Flags().StringVar(&flagLanguage, "language", "", "Language to filter results.")
showsCmd.Flags().StringVar(&flagCountry, "country", "", "Countries to filter results.")
showsCmd.Flags().StringVar(&flagLanguage, "language", "", "Languages to filter results.")
showsCmd.Flags().StringVar(&flagGenre, "genre", "", "Genres to filter results.")
showsCmd.Flags().StringVar(&flagYear, "year", "", "Years to filter results.")
showsCmd.Flags().StringVar(&flagRating, "rating", "", "Ratings to filter results.")
showsCmd.Flags().StringVar(&flagNetwork, "network", "", "Networks to filter results.")
showsCmd.Flags().StringVar(&flagStatus, "status", "", "Statuses to filter results.")
}
15 changes: 15 additions & 0 deletions provider/trakt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/l3uddz/mediarr/config"
"github.com/l3uddz/mediarr/logger"
"github.com/l3uddz/mediarr/utils/lists"
"github.com/l3uddz/mediarr/utils/media"
"github.com/l3uddz/mediarr/utils/web"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -116,6 +117,8 @@ func NewTrakt() *Trakt {

supportedShowsSearchTypes: []string{
SearchTypePopular,
SearchTypeTrending,
SearchTypeUpcoming,
},
supportedMoviesSearchTypes: []string{
SearchTypeTrending,
Expand Down Expand Up @@ -183,6 +186,10 @@ func (p *Trakt) GetShows(searchType string, logic map[string]interface{}, params
switch searchType {
case SearchTypePopular:
return p.getShows("/shows/popular", logic, params)
case SearchTypeTrending:
return p.getShows("/shows/trending", logic, params)
case SearchTypeUpcoming:
return p.getShows("/shows/anticipated", logic, params)
default:
break
}
Expand Down Expand Up @@ -234,6 +241,10 @@ func (p *Trakt) getRequestParams(params map[string]string) req.Param {
reqParams["years"] = v
case "rating":
reqParams["ratings"] = v
case "network":
reqParams["networks"] = v
case "status":
reqParams["status"] = v
default:
break
}
Expand Down Expand Up @@ -552,6 +563,10 @@ func (p *Trakt) getShows(endpoint string, logic map[string]interface{}, params m
p.log.Tracef("Ignoring: %+v", mediaItem)
ignoredItemsSize += 1
continue
} else if !media.ValidateTvdbId(itemId) {
p.log.Tracef("Ignoring, bad TvdbId: %+v", mediaItem)
ignoredItemsSize += 1
continue
} else {
p.log.Debugf("Accepted: %+v", mediaItem)
}
Expand Down

0 comments on commit f17ab2a

Please sign in to comment.