music-library/bool_func_utils.go

71 lines
1.2 KiB
Go
Raw Normal View History

2025-01-15 12:48:20 +01:00
package main
import (
"errors"
2025-01-16 13:24:29 +01:00
"fmt"
2025-01-15 12:48:20 +01:00
"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)
2025-01-16 13:24:29 +01:00
fmt.Println("VIDEOS_ONLY", "DEBUG", streams, err)
2025-01-15 12:48:20 +01:00
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
}
}