Move songs in wav format to songs dir

This commit is contained in:
Chigozirim Igweamaka 2024-08-03 21:25:36 +01:00
parent a439b87af8
commit aeb72e8ace

View file

@ -238,7 +238,6 @@ func erase(songsDir string) {
fmt.Println("Erase complete") fmt.Println("Erase complete")
} }
// index processes the path, whether it's a directory or a single file.
func save(path string, force bool) { func save(path string, force bool) {
fileInfo, err := os.Stat(path) fileInfo, err := os.Stat(path)
if err != nil { if err != nil {
@ -256,7 +255,7 @@ func save(path string, force bool) {
if !info.IsDir() { if !info.IsDir() {
err := saveSong(filePath, force) err := saveSong(filePath, force)
if err != nil { 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 return nil
@ -265,10 +264,9 @@ func save(path string, force bool) {
fmt.Printf("Error walking the directory %v: %v\n", path, err) fmt.Printf("Error walking the directory %v: %v\n", path, err)
} }
} else { } else {
// If it's a file, process it directly
err := saveSong(path, force) err := saveSong(path, force)
if err != nil { 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) 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 return nil
} }