navidrome/utils/files.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
653 B
Go
Raw Normal View History

package utils
import (
"mime"
"path/filepath"
"strings"
)
2020-07-04 03:06:33 +02:00
var excludeAudioType = []string{
"audio/x-mpegurl",
2020-07-04 03:15:01 +02:00
"audio/x-scpls",
2020-07-04 03:06:33 +02:00
}
func IsAudioFile(filePath string) bool {
extension := filepath.Ext(filePath)
2020-07-04 03:06:33 +02:00
mimeType := mime.TypeByExtension(extension)
return !StringInSlice(mimeType, excludeAudioType) && strings.HasPrefix(mimeType, "audio/")
}
func IsImageFile(filePath string) bool {
extension := filepath.Ext(filePath)
return strings.HasPrefix(mime.TypeByExtension(extension), "image/")
}
func IsPlaylist(filePath string) bool {
2020-07-23 09:24:33 +02:00
extension := strings.ToLower(filepath.Ext(filePath))
return extension == ".m3u" || extension == ".m3u8"
}