Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add endpoint to search tracks #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions tracks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package myradio

import (
"fmt"
"github.com/UniversityRadioYork/myradio-go/api"
"strings"
)

Expand Down Expand Up @@ -131,3 +132,53 @@ func (s *Session) GetTrackAlbum(trackid uint64) (album *Album, err error) {
err = s.getf("/track/%d/album", trackid).Into(&album)
return
}

// The parameters for searching for tracks.
// All of these are optional.
type TrackSearchParams struct {
Title string
Artist string
RecordID uint64
// The cleanliness of the track - either "y", "n", or "u"
Digitised bool
Clean string
Precise bool
Limit uint64
// Either "id" (default), "title", or "random"
Sort string
ITonesPlaylistID string
}

func (s *Session) SearchTracks(p TrackSearchParams) (tracks []Track, err error) {
args := make(map[string][]string)
if p.Title != "" {
args["title"] = []string{p.Title}
}
if p.Artist != "" {
args["artist"] = []string{p.Artist}
}
if p.RecordID != 0 {
args["recordid"] = []string{fmt.Sprint(p.RecordID)}
}
if p.Digitised != true {
args["digitised"] = []string{fmt.Sprint(p.Digitised)}
}
if p.Clean != "" {
args["clean"] = []string{p.Clean}
}
if p.Limit != 0 {
args["limit"] = []string{fmt.Sprint(p.Limit)}
}
if p.Sort != "" {
args["sort"] = []string{p.Sort}
}
if p.ITonesPlaylistID != "" {
args["itonesplaylistid"] = []string{p.ITonesPlaylistID}
}

req := api.NewRequest("/track/search")
req.Params = args
err = s.do(req).Into(&tracks)

return
}