Example #1
0
func (h ArtistHandler) searchArtists(w http.ResponseWriter, query string) {
	matches := model.SearchArtists(h.Music, query)
	fmt.Printf("Found %d artist results:\n", len(matches))
	for _, item := range matches {
		fmt.Printf("\t%s\n", item.Name)
	}
	j, _ := json.Marshal(matches)
	w.Write(j)
	return
}
Example #2
0
func (h ArtistHandler) showArtist(w http.ResponseWriter, query string) {
	matches := model.SearchArtists(h.Music, query)
	fmt.Printf("Found %d artist results:\n", len(matches))
	for _, item := range matches {
		if item.Name == query {
			fmt.Printf("Found artist: '%s'\n", item.Name)
			j, _ := json.Marshal(item)
			w.Write(j)
			return
		}
	}
	fmt.Printf("Artist not found: %s %s\n", query)
	writeError(w, http.StatusNotFound, fmt.Sprintf("No artist found '%s'",
		query))
}
Example #3
0
func (h ArtistHandler) searchArtists(w http.ResponseWriter, query string) {
	music, err := h.GetCollection()
	if err != nil {
		log.Printf("Failed to connect to mpd")
		writeError(w, http.StatusNotFound, "Problem with mpd")
	}
	matches := model.SearchArtists(music, query)
	log.Printf("Found %d artist results:\n", len(matches))
	for _, item := range matches {
		fmt.Printf("\t%s\n", item.Name)
	}
	j, _ := json.Marshal(matches)
	w.Write(j)
	return
}
Example #4
0
func (h ArtistHandler) showArtist(w http.ResponseWriter, query string) {
	music, err := h.GetCollection()
	if err != nil {
		log.Printf("Failed to connect to mpd")
		writeError(w, http.StatusNotFound, "Problem with mpd")
	}
	matches := model.SearchArtists(music, query)
	fmt.Printf("Found %d artist results:\n", len(matches))
	for _, item := range matches {
		if item.Name == query {
			log.Printf("Found artist: '%s'\n", item.Name)
			j, _ := json.Marshal(item)
			w.Write(j)
			return
		}
	}
	log.Printf("Artist not found: %s %s\n", query)
	writeError(w, http.StatusNotFound, fmt.Sprintf("No artist found '%s'",
		query))
}