Example #1
0
// visitPlaylist checks that the specified file is
// a music file and is on the correct path.
// If it is ok, it stores it on the database.
func visitPlaylist(name, path, mPoint string) error {
	if path[len(path)-1] != '/' {
		path = path + "/"
	}

	fullPath := path + name
	if strings.HasSuffix(fullPath, ".m3u") {
		glog.Infof("Reading %s\n", fullPath)
		err := playlistmgr.CheckPlaylistFile(fullPath)
		if err != nil {
			glog.Infof("Error in %s playlist\n", name)
			return err
		}

		files, err := playlistmgr.ProcessPlaylist(fullPath)
		if err != nil {
			glog.Infof("Problem reading playlist %s: %s\n", name, err)
			return err
		}

		playlistName := name[:len(name)-len(".m3u")]
		playlistName, _ = store.CreatePlaylist(playlistName, mPoint)

		for _, f := range files {
			store.AddFileToPlaylist(f, playlistName)
		}

		os.Remove(fullPath)
		store.RegeneratePlaylistFile(playlistName, mPoint)
	}
	return nil
}
Example #2
0
func (d *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) {
	name := req.Name
	glog.Infof("Entering mkdir with name: %s.\n", name)
	// Do not allow creating directories starting with dot
	if name[0] == '.' {
		glog.Info("Names starting with dot are not allowed.")
		return nil, fuse.EPERM
	}

	if d.mPoint[len(d.mPoint)-1] != '/' {
		d.mPoint = d.mPoint + "/"
	}
	if len(d.artist) < 1 {
		glog.Info("Creating an Artist.")
		ret, err := store.CreateArtist(name)
		if err != nil {
			glog.Infof("Error creating artist: %s\n", err)
			return nil, err
		}

		path := d.mPoint + ret
		err = os.MkdirAll(path, 0777)
		if err != nil {
			glog.Infof("Error creating artist folder: %s\n", err)
			return nil, fuse.EIO
		}
		return &Dir{fs: d.fs, artist: ret, album: "", mPoint: d.mPoint}, nil
	}

	if d.artist == "drop" {
		return nil, fuse.EIO
	}

	if d.artist == "playlists" {
		if len(d.album) < 1 {
			ret, err := store.CreatePlaylist(name, d.mPoint)
			if err != nil {
				glog.Infof("Error creating playlist: %s\n", err)
				return nil, err
			}

			err = store.RegeneratePlaylistFile(ret, d.mPoint)
			if err != nil {
				glog.Infof("Error regenerating playlist: %s\n", err)
				return nil, err
			}
			return &Dir{fs: d.fs, artist: "playlists", album: ret, mPoint: d.mPoint}, nil
		}
		return nil, fuse.EPERM
	}

	if len(d.album) < 1 {
		glog.Infof("Creating album: %s in artist: %s.\n", d.artist, name)
		ret, err := store.CreateAlbum(d.artist, name)
		if err != nil {
			return nil, err
		}
		path := d.mPoint + d.artist + "/" + ret
		err = os.MkdirAll(path, 0777)
		if err != nil {
			glog.Infof("Error creating artist folder: %s\n", err)
			return nil, fuse.EIO
		}
		return &Dir{fs: d.fs, artist: d.artist, album: ret, mPoint: d.mPoint}, nil
	}

	return nil, fuse.EIO
}