Merge pull request #11 from cgzirim/development

Move songs in wav format to songs dir
This commit is contained in:
Chigozirim Igweamaka 2024-08-03 21:26:36 +01:00 committed by GitHub
commit 2c627c1cde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -238,7 +238,6 @@ func erase(songsDir string) {
fmt.Println("Erase complete")
}
// index processes the path, whether it's a directory or a single file.
func save(path string, force bool) {
fileInfo, err := os.Stat(path)
if err != nil {
@ -256,7 +255,7 @@ func save(path string, force bool) {
if !info.IsDir() {
err := saveSong(filePath, force)
if err != nil {
fmt.Printf("Error indexing song (%v): %v\n", filePath, err)
fmt.Printf("Error saving song (%v): %v\n", filePath, err)
}
}
return nil
@ -265,10 +264,9 @@ func save(path string, force bool) {
fmt.Printf("Error walking the directory %v: %v\n", path, err)
}
} else {
// If it's a file, process it directly
err := saveSong(path, force)
if err != nil {
fmt.Printf("Error indexing song (%v): %v\n", path, err)
fmt.Printf("Error saving song (%v): %v\n", path, err)
}
}
}
@ -309,5 +307,15 @@ func saveSong(filePath string, force bool) error {
return fmt.Errorf("failed to process or save song: %v", err)
}
// Move song in wav format to songs directory
fileName := strings.TrimSuffix(filepath.Base(filePath), filepath.Ext(filePath))
wavFile := fileName + ".wav"
sourcePath := filepath.Join(filepath.Dir(filePath), wavFile)
newFilePath := filepath.Join(SONGS_DIR, wavFile)
err = os.Rename(sourcePath, newFilePath)
if err != nil {
return fmt.Errorf("failed to rename temporary file to output file: %v", err)
}
return nil
}