Files

51 lines
1.2 KiB
Go

package fileutil
import (
"os"
"path/filepath"
"strings"
)
var (
standardMediaExts = map[string]struct{}{
".mp3": {}, ".flac": {}, ".wav": {}, ".m4a": {},
".ogg": {}, ".opus": {}, ".aac": {}, ".wma": {},
".ape": {}, ".alac": {}, ".dsf": {}, ".dff": {},
}
encryptedMediaExts = map[string]struct{}{
".kgma": {}, ".kgm": {},
".ncm": {},
".qmc": {}, ".qmc0": {}, ".qmc3": {}, ".qmcflac": {}, ".qmcogg": {},
".mgg": {}, ".mflac": {},
".tm": {}, ".tkm": {},
".xiami": {}, ".xm": {},
".ximalaya": {}, ".xmly": {},
".x2m": {}, ".x3m": {},
".kwm": {},
}
videoMediaExts = map[string]struct{}{
".mp4": {}, ".mkv": {}, ".avi": {}, ".mov": {}, ".flv": {},
}
)
// IsMediaFile reports whether the file name looks like a media file this tool handles.
func IsMediaFile(fileName string) bool {
ext := strings.ToLower(filepath.Ext(fileName))
if _, ok := standardMediaExts[ext]; ok {
return true
}
if _, ok := encryptedMediaExts[ext]; ok {
return true
}
if _, ok := videoMediaExts[ext]; ok {
return true
}
return false
}
// FileExist reports whether path exists.
func FileExist(path string) bool {
_, err := os.Stat(path)
return err == nil
}