navidrome/model/file_types.go

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

31 lines
711 B
Go
Raw Normal View History

2022-12-23 17:32:39 +01:00
package model
import (
"mime"
"path/filepath"
"slices"
"strings"
)
2020-07-04 03:06:33 +02:00
var excludeAudioType = []string{
2024-05-10 04:09:39 +02:00
"audio/mpegurl",
2020-07-04 03:06:33 +02:00
"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)
2022-12-23 17:32:39 +01:00
return !slices.Contains(excludeAudioType, mimeType) && strings.HasPrefix(mimeType, "audio/")
}
func IsImageFile(filePath string) bool {
extension := filepath.Ext(filePath)
return strings.HasPrefix(mime.TypeByExtension(extension), "image/")
}
2022-12-23 17:32:39 +01:00
func IsValidPlaylist(filePath string) bool {
extension := strings.ToLower(filepath.Ext(filePath))
return extension == ".m3u" || extension == ".m3u8" || extension == ".nsp"
}