本文整理匯總了Golang中github.com/fhs/gompd/mpd.Client.GetFiles方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.GetFiles方法的具體用法?Golang Client.GetFiles怎麽用?Golang Client.GetFiles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fhs/gompd/mpd.Client
的用法示例。
在下文中一共展示了Client.GetFiles方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getFiles
func getFiles(_ *Cmd, conn *mpd.Client) (r *Result, err error) {
files, err := conn.GetFiles()
if err == nil {
r = NewResult("Files", files)
}
return
}
示例2: updateMoodDatabase
// Walk over all music files and create a .mood file for each in mood-dir.
func updateMoodDatabase(client *mpd.Client, cfg *Config) error {
if cfg.MoodDir == "" {
return fmt.Errorf("No mood bar directory given (-mood-dir)")
}
if err := os.MkdirAll(cfg.MoodDir, 0777); err != nil {
return err
}
paths, err := client.GetFiles()
if err != nil {
return fmt.Errorf("Cannot get all files from mpd: %v", err)
}
// Use up to N threads:
N := 8
wg := &sync.WaitGroup{}
wg.Add(N)
moodChan := make(chan *MoodInfo, N)
for i := 0; i < N; i++ {
go func() {
for pair := range moodChan {
log.Printf("Processing: %s", pair.MusicFile)
cmd := exec.Command("moodbar", pair.MusicFile, "-o", pair.MoodPath)
if err := cmd.Run(); err != nil {
log.Printf("Failed to execute moodbar on `%s`: %v", pair.MusicFile, err)
}
}
wg.Done()
}()
}
for _, path := range paths {
moodName := strings.Replace(path, string(filepath.Separator), "|", -1)
moodPath := filepath.Join(cfg.MoodDir, moodName)
if _, err := os.Stat(moodPath); err == nil {
// Already exists, Skipping.
continue
}
dataPath := filepath.Join(cfg.MusicDir, path)
moodChan <- &MoodInfo{
MusicFile: dataPath,
MoodPath: moodPath,
}
}
close(moodChan)
wg.Wait()
return nil
}