func DeletePlaylist(name, mPoint string) error {
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return err
	}
	defer db.Close()
	err = db.Update(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Playlists"))
		if root == nil {
			glog.Errorf("Error opening Playlists bucket.\n")
			return errors.New("Error opening Playlists bucket.")
		}
		playlistBucket := root.Bucket([]byte(name))
		if playlistBucket == nil {
			return nil
		}
		c := playlistBucket.Cursor()
		for k, songJson := c.First(); k != nil; k, songJson = c.Next() {
			if songJson == nil {
				glog.Infof("Error opening song Json: %s in playlist: %s\n", k, name)
				continue
			}
			var file playlistmgr.PlaylistFile
			err = json.Unmarshal(songJson, &file)
			if err != nil {
				continue
			}
			artistsBucket := tx.Bucket([]byte("Artists"))
			if artistsBucket == nil {
				glog.Error("Cannot open Artists bucket.")
				return errors.New("Cannot open Artists bucket.")
			}
			artistBucket := artistsBucket.Bucket([]byte(file.Artist))
			if artistBucket == nil {
				glog.Infof("Cannot open Artist bucket: %s.\n", file.Artist)
				continue
			}
			albumBucket := artistBucket.Bucket([]byte(file.Album))
			if albumBucket == nil {
				glog.Infof("Cannot open Album bucket: %s in Artist: %s.\n", file.Album, file.Artist)
				continue
			}
			jsonFile := albumBucket.Get([]byte(file.Title))
			if jsonFile == nil {
				glog.Infof("Cannot open song: %s Album bucket: %s in Artist: %s.\n", file.Title, file.Album, file.Artist)
				continue
			}
			var song SongStore
			err = json.Unmarshal(jsonFile, &song)
			if err != nil {
				return err
			}
			if song.Playlists != nil {
				for i, list := range song.Playlists {
					if list == name {
						song.Playlists = append(song.Playlists[:i], song.Playlists[i+1:]...)
						break
					}
				}
			}
			encoded, err := json.Marshal(song)
			if err != nil {
				return err
			}
			return albumBucket.Put([]byte(k), encoded)
		}
		return root.DeleteBucket([]byte(name))
	})
	return playlistmgr.DeletePlaylist(name, mPoint)
}
DeletePlaylist function deletes a playlist from the database
and also deletes all the entries in the specific files and
deletes it from the filesystem.
package store
import (
	"bazil.org/fuse"
	"encoding/json"
	"errors"
	"github.com/boltdb/bolt"
	"github.com/dankomiocevic/mulifs/playlistmgr"
	"github.com/golang/glog"
	"io/ioutil"
	"os"
)
func GetPlaylistPath(playlist string) (string, error) {
	glog.Infof("Entered Playlist path with playlist: %s\n", playlist)
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return "", err
	}
	defer db.Close()
	err = db.View(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Playlists"))
		if root == nil {
			return errors.New("No playlists.")
		}
		playlistBucket := root.Bucket([]byte(playlist))
		if playlistBucket == nil {
			return errors.New("Playlist not exists.")
		}
		return nil
	})
	return playlist, err
}
func GetPlaylistFilePath(playlist, song, mPoint string) (string, error) {
	glog.Infof("Entered Playlist file path with song: %s, and playlist: %s\n", song, playlist)
	returnValue, err := getPlaylistFile(playlist, song)
	if err == nil {
		return returnValue.Path, nil
	}
	if mPoint[len(mPoint)-1] != '/' {
		mPoint = mPoint + "/"
	}
	fullPath := mPoint + "playlists/" + playlist + "/" + song
	src, err := os.Stat(fullPath)
	if err != nil || src.IsDir() {
		return "", errors.New("File not exists.")
	}
	return fullPath, nil
}
func ListPlaylists() ([]fuse.Dirent, error) {
	glog.Info("Entered list playlists.")
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return nil, err
	}
	defer db.Close()
	var a []fuse.Dirent
	err = db.View(func(tx *bolt.Tx) error {
		b := tx.Bucket([]byte("Playlists"))
		if b == nil {
			glog.Infof("There is no Playlists bucket.")
			return nil
		}
		c := b.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			if v == nil {
				var node fuse.Dirent
				node.Name = string(k)
				node.Type = fuse.DT_Dir
				a = append(a, node)
			}
		}
		return nil
	})
	return a, nil
}
func ListPlaylistSongs(playlist, mPoint string) ([]fuse.Dirent, error) {
	glog.Infof("Listing contents of playlist %s.\n", playlist)
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return nil, err
	}
	defer db.Close()
	var a []fuse.Dirent
	err = db.View(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Playlists"))
		if root == nil {
			return nil
		}
		b := root.Bucket([]byte(playlist))
		if b == nil {
			return nil
		}
		c := b.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			if v != nil {
				var node fuse.Dirent
				node.Name = string(k)
				node.Type = fuse.DT_File
				a = append(a, node)
			}
		}
		return nil
	})
	if err != nil {
		return nil, err
	}
	if mPoint[len(mPoint)-1] != '/' {
		mPoint = mPoint + "/"
	}
	fullPath := mPoint + "playlists/" + playlist + "/"
	files, _ := ioutil.ReadDir(fullPath)
	for _, f := range files {
		if !f.IsDir() {
			var node fuse.Dirent
			node.Name = string(f.Name())
			node.Type = fuse.DT_File
			a = append(a, node)
		}
	}
	return a, nil
}
func CreatePlaylist(name, mPoint string) (string, error) {
	glog.Infof("Creating Playlist with name: %s\n", name)
	name = GetCompatibleString(name)
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return "", err
	}
	defer db.Close()
	err = db.Update(func(tx *bolt.Tx) error {
		root, err := tx.CreateBucketIfNotExists([]byte("Playlists"))
		if err != nil {
			glog.Errorf("Error creating Playlists bucket: %s\n", err)
			return err
		}
		_, err = root.CreateBucketIfNotExists([]byte(name))
		if err != nil {
			glog.Errorf("Error creating %s bucket: %s\n", name, err)
			return err
		}
		return nil
	})
	if err != nil {
		return "", err
	}
	return name, err
}
func RegeneratePlaylistFile(name, mPoint string) error {
	glog.Infof("Regenerating playlist for name: %s\n", name)
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return err
	}
	defer db.Close()
	var a []playlistmgr.PlaylistFile
	err = db.View(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Playlists"))
		if root == nil {
			glog.Info("Cannot open Playlists bucket.")
			return errors.New("Cannot open Playlists bucket.")
		}
		b := root.Bucket([]byte(name))
		if b == nil {
			glog.Infof("Playlist %s not exists", name)
			return errors.New("Playlist not exists.")
		}
		c := b.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			if v != nil {
				var file playlistmgr.PlaylistFile
				err := json.Unmarshal(v, &file)
				if err == nil {
					a = append(a, file)
				} else {
					glog.Errorf("Cannot unmarshal Playlist File %s: %s\n", k, err)
				}
			}
		}
		return nil
	})
	if err != nil {
		return err
	}
	return playlistmgr.RegeneratePlaylistFile(a, name, mPoint)
}
func AddFileToPlaylist(file playlistmgr.PlaylistFile, playlistName string) error {
	path, err := GetFilePath(file.Artist, file.Album, file.Title)
	if err != nil {
		return errors.New("Playlist item not found in MuLi.")
	}
	file.Path = path
	db, err := bolt.Open(config.DbPath, 0600, nil)
	if err != nil {
		return err
	}
	defer db.Close()
	err = db.Update(func(tx *bolt.Tx) error {
		root := tx.Bucket([]byte("Playlists"))
		if root == nil {
			glog.Errorf("Error opening Playlists bucket: %s\n", err)
			return errors.New("Error opening Playlists bucket.")
		}
		playlistBucket := root.Bucket([]byte(playlistName))
		if playlistBucket == nil {
			glog.Errorf("Error opening %s playlist bucket: %s\n", playlistName, err)
			return errors.New("Error opening playlist bucket.")
		}
		encoded, err := json.Marshal(file)
		if err != nil {
			glog.Errorf("Cannot encode PlaylistFile.")
			return err
		}
		playlistBucket.Put([]byte(file.Title), encoded)
		root = tx.Bucket([]byte("Artists"))
		if root == nil {
			glog.Errorf("Error opening Artists bucket: %s\n", err)
			return errors.New("Error opening Artists bucket.")
		}
		artistBucket := root.Bucket([]byte(file.Artist))
		if artistBucket == nil {
			glog.Errorf("Error opening %s artist bucket: %s\n", file.Artist, err)
			return errors.New("Error opening artist bucket.")
		}
		albumBucket := artistBucket.Bucket([]byte(file.Album))
		if albumBucket == nil {
			glog.Errorf("Error opening %s album on %s artist: %s\n", file.Album, file.Artist, err)
			return errors.New("Error opening album bucket.")
		}
		songJson := albumBucket.Get([]byte(file.Title))
		if songJson == nil {
			glog.Errorf("Error opening %s on %s album on %s artist: %s\n", file.Title, file.Album, file.Artist, err)
			return errors.New("Error opening song json.")
		}
		var song SongStore
		err = json.Unmarshal(songJson, &song)
		if err != nil {
			return err
		}
		if song.Playlists != nil {
			for _, list := range song.Playlists {
				if list == playlistName {
					return nil
				}
			}
		}
		song.Playlists = append(song.Playlists, playlistName)
		encoded, err = json.Marshal(song)
		if err != nil {
			return err
		}
		return albumBucket.Put([]byte(file.Title), encoded)
	})
	return err
}