示例#1
0
文件: playlist.go 项目: hoffoo/pickup
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
}
示例#2
0
文件: playlist.go 项目: hoffoo/pickup
func (h PlaylistHandler) clear(playlist player.Playlist) (err error) {
	return playlist.Clear()
}