func (h PlaylistHandler) add(playlist player.Playlist, controls player.Controls, data PlaylistCommand) (err error) { if data.Album == "" { log.Printf("Don't play artists (or nulls)\n") return errors.New("Playing artists is not implemented") } log.Printf("Trying to add %s/%s/%s/%s to playlist (%v)\n", data.Category, data.Artist, data.Album, data.Track, data.Immediate) var album *model.Album = nil var track *model.Track = nil if data.Track == "" { album, err = model.GetAlbum(h.Music, data.Category, data.Artist, data.Album) } else { track, err = model.GetTrack(h.Music, data.Category, data.Artist, data.Album, data.Track) } if err != nil { log.Printf("Album not found.") return err } if data.Immediate { err = playlist.Clear() if err != nil { log.Printf("Error clearing playlist") return err } } if track != nil { err = playlist.AddTrack(track) } if album != nil { err = playlist.AddAlbum(album) } if err != nil { log.Printf("Error adding album or track %s/%s", data.Album, data.Track) return err } if data.Immediate { err = controls.Play() } return err }
func (player *MpdPlayer) doAddCommand(cmd *PlaylistCommand, music model.Collection) (err error) { if cmd.Album == "" { log.Printf("Don't play artists (or nulls)\n") return errors.New("Playing artists is not implemented") } log.Printf("Trying to add %s/%s/%s/%s to playlist (%v)\n", cmd.Category, cmd.Artist, cmd.Album, cmd.Track, cmd.Immediate) var album *model.Album = nil var track *model.Track = nil if cmd.Track == "" { album, err = model.GetAlbum(&music, cmd.Category, cmd.Artist, cmd.Album) } else { track, err = model.GetTrack(&music, cmd.Category, cmd.Artist, cmd.Album, cmd.Track) } if err != nil { log.Printf("Album not found.") return err } if cmd.Immediate { err = player.Clear() if err != nil { log.Printf("Error clearing playlist") return err } } if track != nil { err = player.AddTrack(track) } if album != nil { err = player.AddAlbum(album) } if err != nil { log.Printf("Error adding album or track %s/%s", cmd.Album, cmd.Track) return err } if cmd.Immediate { err = player.Play() } return err }
func (h AlbumHandler) getAlbum(w http.ResponseWriter, categoryName string, artistName string, albumName string) { log.Printf("Looking up album '%s/%s/%s\n", categoryName, artistName, albumName) album, err := model.GetAlbum(h.Music, categoryName, artistName, albumName) if err == nil { log.Printf("Found album: %s/%s; %d tracks", album.Artist, album.Name, len(album.Tracks)) summary := model.NewAlbumSummary(album) j, _ := json.Marshal(summary) w.Write(j) return } log.Printf("Did not find album: %s/%s/%s (%v)", categoryName, artistName, albumName, err) //fmt.Fprintf(w, "\n<h1>Hello</h1><div>world</div>\n") writeError(w, http.StatusNotFound, fmt.Sprintf("Album not found '%s'", albumName)) }
func (h AlbumHandler) getAlbum(w http.ResponseWriter, categoryName string, artistName string, albumName string) { log.Printf("Looking up album '%s/%s/%s\n", categoryName, artistName, albumName) music, err := h.GetCollection() if err != nil { log.Printf("Failed to connect to mpd") writeError(w, http.StatusNotFound, "Problem with mpd") } album, err := model.GetAlbum(music, categoryName, artistName, albumName) if err == nil { log.Printf("Found album: %s/%s; %d tracks", album.Artist, album.Name, len(album.Tracks)) summary := model.NewAlbumSummary(album) j, _ := json.Marshal(summary) w.Write(j) return } log.Printf("Did not find album: %s/%s/%s (%v)", categoryName, artistName, albumName, err) writeError(w, http.StatusNotFound, fmt.Sprintf("Album not found '%s'", albumName)) }