music-library/bool_func_utils.go
2025-01-16 13:24:29 +01:00

71 lines
1.2 KiB
Go

package main
import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
)
func AbsPath(path string) string {
if filepath.IsAbs(path) {
return path
}
absSource, err := filepath.Abs(path)
if err != nil {
panic(err)
}
return absSource
}
func Exists(path string) bool {
_, err := os.Lstat(path)
return !errors.Is(err, fs.ErrNotExist)
}
func SymlinkFilesOnly(path string) bool {
stat, err := os.Lstat(path)
if err != nil {
return false
}
isSymlink := stat.Mode().Type()&os.ModeSymlink == os.ModeSymlink
return isSymlink && !stat.IsDir()
}
func VideosOnly(path string) bool {
streams, err := GetStreamsFromFile(path)
fmt.Println("VIDEOS_ONLY", "DEBUG", streams, err)
return err == nil && strings.Contains(streams, "video")
}
func Not[T any](f func(T) bool) func(T) bool {
return func(t T) bool { return !f(t) }
}
func And[T any](functions ...func(T) bool) func(T) bool {
return func(t T) bool {
for _, f := range functions {
if !f(t) {
return false
}
}
return true
}
}
func Or[T any](functions ...func(T) bool) func(T) bool {
return func(t T) bool {
for _, f := range functions {
if f(t) {
return true
}
}
return false
}
}