Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit c9cac34

Browse files
authored
feat: add new browse options to commandline client (#6)
* feat: add new browse options to commandline client * feat: update documentation with browse options
1 parent 3d9104f commit c9cac34

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/menzerath/monstercat-api/go)
44
![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/menzerath/monstercat-api)
5-
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/menzerath/monstercat-api/monstercat?tab=doc)
5+
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/menzerath/monstercat-api/v2/monstercat)
66

77
Go-based wrapper and CLI to access Monstercat's API for releases and tracks.
88

@@ -32,19 +32,21 @@ $ ./monstercat catalog --search="mix contest"
3232
| CATALOG ID | TITLE | ARTIST | TYPE | RELEASE DATE |
3333
+------------+-------------------------------------------------+------------+---------+--------------+
3434
| MMC604 | S6E4 - The Mix Contest - "You & Me" | Monstercat | Podcast | 2021-08-11 |
35-
| MMC603 | S6E3 - The Mix Contest - Orbit | Monstercat | Podcast | 2021-08-04 |
36-
| MMC602 | S6E2 - The Mix Contest - There and Back | Monstercat | Podcast | 2021-07-28 |
37-
| MMC601 | S6E1 - The Mix Contest - Opening Ceremonies | Monstercat | Podcast | 2021-07-21 |
35+
| MMC603 | S6E3 - The Mix Contest - "Orbit" | Monstercat | Podcast | 2021-08-04 |
36+
| MMC602 | S6E2 - The Mix Contest - "There and Back" | Monstercat | Podcast | 2021-07-28 |
37+
| MMC601 | S6E1 - The Mix Contest - "Opening Ceremonies" | Monstercat | Podcast | 2021-07-21 |
3838
| MMCS600 | The Mix Contest 2021 - Submissions Open Now! | Monstercat | Podcast | 2021-05-19 |
3939
| MMC508 | The Mix Contest 2020 - Winner’s Showcase | Monstercat | Podcast | 2020-09-23 |
40-
| MMC507 | S5E7 - The Mix Contest - Showdown | Monstercat | Podcast | 2020-09-02 |
41-
| MMC506 | S5E6 - The Mix Contest - Unity | Monstercat | Podcast | 2020-08-26 |
42-
| MMC505 | S5E5 - The Mix Contest - Bittersweet Horizons | Monstercat | Podcast | 2020-08-19 |
43-
| MMC504 | S5E4 - The Mix Contest - How We Win, Together | Monstercat | Podcast | 2020-08-12 |
40+
| MMC507 | S5E7 - The Mix Contest - "Showdown" | Monstercat | Podcast | 2020-09-02 |
41+
| MMC506 | S5E6 - The Mix Contest - "Unity" | Monstercat | Podcast | 2020-08-26 |
42+
| MMC505 | S5E5 - The Mix Contest - "Bittersweet Horizons" | Monstercat | Podcast | 2020-08-19 |
43+
| MMC504 | S5E4 - The Mix Contest - "How We Win, Together" | Monstercat | Podcast | 2020-08-12 |
4444
+------------+-------------------------------------------------+------------+---------+--------------+
4545
10 of 25 results
4646
```
4747

48+
A list of all configurable options can be obtained by adding the `--help` flag to any command.
49+
4850
### API
4951

5052
To use this project in your own work, follow these steps:
@@ -65,11 +67,13 @@ import (
6567

6668
func main() {
6769
client := monstercat.NewClient()
68-
catalog, err := client.Catalog("mix contest", "podcast", 5, 0)
70+
catalog, err := client.BrowseCatalog(WithSearch("mix contest"))
6971
if err != nil {
7072
fmt.Printf("error: %s", err)
7173
os.Exit(1)
7274
}
7375
fmt.Printf("catalog: %+v", catalog)
7476
}
7577
```
78+
79+
A list of all `BrowseOption`s is available in our [API documentation](https://pkg.go.dev/github.com/menzerath/monstercat-api/v2/monstercat#BrowseOption).

cmd/catalog.go

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,35 @@ package cmd
33
import (
44
"fmt"
55
"os"
6+
"strconv"
67

78
"github.com/menzerath/monstercat-api/v2/monstercat"
89
"github.com/olekukonko/tablewriter"
910
"github.com/spf13/cobra"
1011
)
1112

1213
var (
13-
catalogSearch string
14-
catalogType string
15-
catalogLimit int
16-
catalogOffset int
14+
catalogSearch string
15+
catalogBrands []string
16+
catalogGenres []string
17+
catalogTypes []string
18+
catalogTags []string
19+
catalogIncludeGold bool
20+
catalogIncludeUnreleased bool
21+
catalogSort string
22+
catalogLimit int
23+
catalogOffset int
1724
)
1825

1926
func init() {
20-
catalogCmd.Flags().StringVarP(&catalogSearch, "search", "s", "", "search query")
21-
catalogCmd.Flags().StringVarP(&catalogType, "type", "t", "", "type of release")
27+
catalogCmd.Flags().StringVarP(&catalogSearch, "search", "s", "", "search query (title, album, artist, ...)")
28+
catalogCmd.Flags().StringArrayVarP(&catalogBrands, "brand", "b", []string{}, "brand identifier (1 = Uncaged, 2 = Instinct, 3 = CotW, 4 = Silk, 5 = Silk Showcase)")
29+
catalogCmd.Flags().StringArrayVarP(&catalogGenres, "genre", "g", []string{}, "genre (dubstep, acoustic, ...)")
30+
catalogCmd.Flags().StringArrayVarP(&catalogTypes, "type", "t", []string{}, "release type (Single, EP, Album)")
31+
catalogCmd.Flags().StringArrayVar(&catalogTags, "tag", []string{}, "tags (chill, badass, ...)")
32+
catalogCmd.Flags().BoolVar(&catalogIncludeGold, "gold", true, "include gold releases")
33+
catalogCmd.Flags().BoolVar(&catalogIncludeUnreleased, "unreleased", true, "include unreleased releases")
34+
catalogCmd.Flags().StringVar(&catalogSort, "sort", "-date", "sort by")
2235
catalogCmd.Flags().IntVar(&catalogLimit, "limit", 10, "limit number of catalog")
2336
catalogCmd.Flags().IntVar(&catalogOffset, "offset", 0, "offset number of catalog")
2437

@@ -29,7 +42,37 @@ var catalogCmd = &cobra.Command{
2942
Use: "catalog",
3043
Short: "catalog returns a set of the most recent Monstercat catalog items",
3144
Run: func(cmd *cobra.Command, args []string) {
32-
catalog, err := monstercat.NewClient().Catalog(catalogSearch, catalogType, catalogLimit, catalogOffset)
45+
options := make([]monstercat.BrowseOption, 0)
46+
if catalogSearch != "" {
47+
options = append(options, monstercat.WithSearch(catalogSearch))
48+
}
49+
for _, brand := range catalogBrands {
50+
brandID, err := strconv.Atoi(brand)
51+
if err != nil {
52+
fmt.Printf("%s is not a valid brand id\n", brand)
53+
os.Exit(1)
54+
}
55+
options = append(options, monstercat.WithBrand(brandID))
56+
}
57+
for _, genre := range catalogGenres {
58+
options = append(options, monstercat.WithGenre(genre))
59+
}
60+
for _, releaseType := range catalogTypes {
61+
options = append(options, monstercat.WithReleaseType(releaseType))
62+
}
63+
for _, tag := range catalogTags {
64+
options = append(options, monstercat.WithTag(tag))
65+
}
66+
options = append(
67+
options,
68+
monstercat.IncludeGold(catalogIncludeGold),
69+
monstercat.IncludeUnreleased(catalogIncludeUnreleased),
70+
monstercat.WithSort(catalogSort),
71+
monstercat.WithLimit(catalogLimit),
72+
monstercat.WithOffset(catalogOffset),
73+
)
74+
75+
catalog, err := monstercat.NewClient().BrowseCatalog(options...)
3376
if err != nil {
3477
fmt.Printf("error fetching catalog: %s", err)
3578
os.Exit(1)

0 commit comments

Comments
 (0)