Skip to content

Commit 60daae8

Browse files
committed
skip params that are not provided
1 parent 585f17e commit 60daae8

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

cmd/movies.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ var moviesCmd = &cobra.Command{
5151

5252
// build param map
5353
params := map[string]string{
54-
"country": flagCountry,
54+
"country": flagCountry,
55+
"language": flagLanguage,
5556
}
5657

5758
// retrieve media
@@ -98,6 +99,7 @@ func init() {
9899
// optional flags
99100
moviesCmd.Flags().BoolVarP(&flagRefreshCache, "refresh-cache", "r", false, "Refresh the locally stored cache.")
100101

101-
moviesCmd.Flags().StringVar(&flagCountry, "country", "us", "Country to filter results.")
102+
moviesCmd.Flags().StringVar(&flagCountry, "country", "", "Country to filter results.")
103+
moviesCmd.Flags().StringVar(&flagLanguage, "language", "", "Language to filter results.")
102104

103105
}

cmd/root.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ var (
2929

3030
flagSearchType string
3131

32-
flagCountry string
32+
flagCountry string
33+
flagLanguage string
3334

3435
// Global vars
3536
log *logrus.Entry

cmd/shows.go

+3
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,7 @@ func init() {
9292

9393
// optional flags
9494
showsCmd.Flags().BoolVarP(&flagRefreshCache, "refresh-cache", "r", false, "Refresh the locally stored cache.")
95+
96+
showsCmd.Flags().StringVar(&flagCountry, "country", "", "Country to filter results.")
97+
showsCmd.Flags().StringVar(&flagLanguage, "language", "", "Language to filter results.")
9598
}

provider/tmdb.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,16 @@ func (p *Tmdb) getMoviesNowPlaying(params map[string]string) (map[string]config.
191191
}
192192

193193
for k, v := range params {
194+
// skip empty params
195+
if v == "" {
196+
continue
197+
}
198+
194199
switch k {
195200
case "country":
196201
reqParams["region"] = v
202+
case "language":
203+
reqParams["language"] = v
197204
}
198205
}
199206

@@ -233,7 +240,7 @@ func (p *Tmdb) getMoviesNowPlaying(params map[string]string) (map[string]config.
233240
// process response
234241
for _, item := range s.Results {
235242
// skip this item?
236-
if item.Adult {
243+
if item.Adult || item.Video {
237244
continue
238245
}
239246

0 commit comments

Comments
 (0)