Beispiel #1
0
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
}
Beispiel #2
0
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
}