Example #1
0
func MakePlist(c *spotify.Client, id spotify.ID) error {
	u, err := c.CurrentUser()
	if err != nil {
		return errors.New("curuser err: " + err.Error())
	}

	uid := u.ID

	pl, err := c.CreatePlaylistForUser(uid, NewPlistName(), false)
	if err != nil {
		return errors.New("create error: " + err.Error())
	}

	ids, err := GetTrax(c, id)
	if err != nil {
		return errors.New("gettrax err: " + err.Error())
	}

	snap, err := c.AddTracksToPlaylist(u.ID, pl.ID, ids...)
	if err != nil {
		return errors.New("addtrax err: " + err.Error())
	}
	fmt.Println(snap)

	return nil
}
Example #2
0
File: main.go Project: brandur/wgt2
func getPlaylist(client *spotify.Client, user *spotify.PrivateUser, playlistName string) (*spotify.SimplePlaylist, error) {
	page, err := client.CurrentUsersPlaylists()
	if err != nil {
		return nil, err
	}

	for _, playlist := range page.Playlists {
		if playlist.Name == playlistName {
			log.Printf("Found playlist: %v", playlistName)
			return &playlist, nil
		}
	}

	// otherwise create a new playlist for the user
	log.Printf("Creating playlist: %v", playlistName)

	playlist, err := client.CreatePlaylistForUser(user.ID, playlistName, true)
	return &playlist.SimplePlaylist, err
}