copy lrc file with song file
This commit is contained in:
@@ -3,6 +3,7 @@ package ripsort
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
@@ -27,11 +28,24 @@ func sortSong(src, dst string) error {
|
|||||||
dstPath := pathForFile(src, *m)
|
dstPath := pathForFile(src, *m)
|
||||||
finalPath := filepath.Join(dst, dstPath)
|
finalPath := filepath.Join(dst, dstPath)
|
||||||
|
|
||||||
|
slog.Info("Copying song", "file", src, "dst", dstPath)
|
||||||
err = copyFile(src, finalPath)
|
err = copyFile(src, finalPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extraFiles := checkForExtraFiles(src)
|
||||||
|
|
||||||
|
for _, extraFile := range extraFiles {
|
||||||
|
extraFilePath := pathForFile(extraFile, *m)
|
||||||
|
finalExtraFilePath := filepath.Join(dst, extraFilePath)
|
||||||
|
slog.Info("Copy extra file", "file", extraFile, "dst", extraFilePath)
|
||||||
|
err = copyFile(extraFile, finalExtraFilePath)
|
||||||
|
if err != nil {
|
||||||
|
slog.Warn("Failed to copy extra file", "file", extraFile, "err", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,3 +146,19 @@ func copyFile(src, dst string) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkForExtraFiles(originalPath string) []string {
|
||||||
|
dir := filepath.Dir(originalPath)
|
||||||
|
fileName := filepath.Base(originalPath)
|
||||||
|
fileNameNoExt := strings.TrimSuffix(fileName, filepath.Ext(fileName))
|
||||||
|
|
||||||
|
extraFiles := []string{}
|
||||||
|
|
||||||
|
lrcPath := filepath.Join(dir, fileNameNoExt+".lrc")
|
||||||
|
stat, err := os.Stat(lrcPath)
|
||||||
|
if err == nil && !stat.IsDir() {
|
||||||
|
extraFiles = append(extraFiles, lrcPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return extraFiles
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user