Remove duplicated helper functions, move them to utils package

This commit is contained in:
Deluan
2020-06-24 18:12:23 -04:00
committed by Deluan Quintão
parent bb9a7fadc0
commit eb109ebeb4
5 changed files with 61 additions and 21 deletions
+2 -8
View File
@@ -4,7 +4,6 @@ import (
"bufio"
"errors"
"fmt"
"mime"
"os"
"os/exec"
"path"
@@ -16,6 +15,7 @@ import (
"github.com/deluan/navidrome/conf"
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/utils"
)
type Metadata struct {
@@ -66,8 +66,7 @@ func LoadAllAudioFiles(dirPath string) (map[string]os.FileInfo, error) {
continue
}
filePath := filepath.Join(dirPath, f.Name())
extension := path.Ext(filePath)
if !isAudioFile(extension) {
if !utils.IsAudioFile(filePath) {
continue
}
fi, err := os.Stat(filePath)
@@ -159,11 +158,6 @@ func extractMetadata(filePath, info string) (*Metadata, error) {
return m, nil
}
func isAudioFile(extension string) bool {
typ := mime.TypeByExtension(extension)
return strings.HasPrefix(typ, "audio/")
}
func (m *Metadata) parseInfo(info string) {
reader := strings.NewReader(info)
scanner := bufio.NewScanner(reader)