helpers

package
v2.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2025 License: GPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalLauncherCache = &LauncherCache{}

GlobalLauncherCache is the singleton instance used throughout the application.

View Source
var GlobalRegexCache = NewRegexCache()

GlobalRegexCache is the singleton instance used throughout the application

View Source
var ReURI = regexp.MustCompile(`^([a-zA-Z][a-zA-Z0-9+.-]*)://(.+)$`)

Functions

func AlphaMapKeys

func AlphaMapKeys[V any](m map[string]V) []string

func CachedCompile

func CachedCompile(pattern string) (*regexp.Regexp, error)

func CachedMustCompile

func CachedMustCompile(pattern string) *regexp.Regexp

Convenience functions that use the global cache

func ConfigDir

func ConfigDir(pl platforms.Platform) string

func Contains

func Contains[T comparable](xs []T, x T) bool

Contains returns true if slice contains value.

func CopyFile

func CopyFile(sourcePath, destPath string) error

func CreateVirtualPath

func CreateVirtualPath(scheme, id, name string) string

CreateVirtualPath creates a properly encoded virtual path for media Example: "kodi-show", "123", "Some Hot/Cold" -> "kodi-show://123/Some%20Hot%2FCold"

func DataDir

func DataDir(pl platforms.Platform) string

func DoLaunch

func DoLaunch(
	cfg *config.Instance,
	pl platforms.Platform,
	setActiveMedia func(*models.ActiveMedia),
	launcher *platforms.Launcher,
	path string,
) error

DoLaunch launches the given path and updates the active media with it if it was successful.

func ExeDir

func ExeDir() string

func FilenameFromPath

func FilenameFromPath(p string) string

func FindLauncher

func FindLauncher(
	cfg *config.Instance,
	pl platforms.Platform,
	path string,
) (platforms.Launcher, error)

FindLauncher takes a path and tries to find the best possible match for a launcher, taking into account any allowlist restrictions. Returns the launcher to be used.

func GetAllLocalIPs

func GetAllLocalIPs() []string

GetAllLocalIPs returns all non-loopback private IPv4 addresses

func GetFileSize

func GetFileSize(filePath string) (int64, error)

func GetLocalIP

func GetLocalIP() string

func GetMd5Hash

func GetMd5Hash(filePath string) (string, error)

func GetSerialDeviceList

func GetSerialDeviceList() ([]string, error)

func HasSpace

func HasSpace(s string) bool

func HasUserDir

func HasUserDir() (string, bool)

HasUserDir checks if a "user" directory exists next to the Zaparoo binary and returns true and the absolute path to it. This directory is used as a parent for all platform directories if it exists, for a portable install.

func InitLogging

func InitLogging(pl platforms.Platform, writers []io.Writer) error

func IsFalsey

func IsFalsey(s string) bool

func IsServiceRunning

func IsServiceRunning(cfg *config.Instance) bool

func IsTruthy

func IsTruthy(s string) bool

func IsZip

func IsZip(filePath string) bool

func ListZip

func ListZip(filePath string) ([]string, error)

ListZip returns a slice of all filenames in a zip file.

func MapKeys

func MapKeys[K comparable, V any](m map[K]V) []K

MapKeys returns a list of all keys in a map.

func MatchSystemFile

func MatchSystemFile(
	cfg *config.Instance,
	pl platforms.Platform,
	systemID string,
	path string,
) bool

MatchSystemFile returns true if a given path is for a given system. This function now uses the launcher cache for O(1) system lookup instead of O(n*m).

func MaybeJSON

func MaybeJSON(data []byte) bool

func ParseCustomLaunchers

func ParseCustomLaunchers(
	pl platforms.Platform,
	customLaunchers []config.LaunchersCustom,
) []platforms.Launcher

func PathIsLauncher

func PathIsLauncher(
	cfg *config.Instance,
	pl platforms.Platform,
	l *platforms.Launcher,
	path string,
) bool

PathIsLauncher returns true if a given path matches against any of the criteria defined in a launcher.

func PathToLaunchers

func PathToLaunchers(
	cfg *config.Instance,
	pl platforms.Platform,
	path string,
) []platforms.Launcher

PathToLaunchers is a reverse lookup to match a given path against all possible launchers in a platform. Returns all matched launchers.

func RandSeq

func RandSeq(n int) (string, error)

func RandomElem

func RandomElem[T any](xs []T) (T, error)

RandomElem picks and returns a random element from a slice.

func ScanSteamApps

func ScanSteamApps(steamDir string) ([]platforms.ScanResult, error)

func ScanSteamShortcuts

func ScanSteamShortcuts(steamDir string) ([]platforms.ScanResult, error)

func SlugifyPath

func SlugifyPath(filePath string) string

func SlugifyString

func SlugifyString(input string) string

func TokensEqual

func TokensEqual(a, b *tokens.Token) bool

func WaitForInternet

func WaitForInternet(maxTries int) bool

func YesNoPrompt

func YesNoPrompt(label string, def bool) bool

Types

type LauncherCache

type LauncherCache struct {
	// contains filtered or unexported fields
}

LauncherCache provides fast O(1) launcher lookups by system ID. This replaces the expensive O(n*m) pl.Launchers() calls in hot paths.

func (*LauncherCache) GetAllLaunchers

func (lc *LauncherCache) GetAllLaunchers() []platforms.Launcher

GetAllLaunchers returns all cached launchers.

func (*LauncherCache) GetLaunchersBySystem

func (lc *LauncherCache) GetLaunchersBySystem(systemID string) []platforms.Launcher

GetLaunchersBySystem returns all launchers for a specific system ID. Returns nil if no launchers found for the system.

func (*LauncherCache) Initialize

func (lc *LauncherCache) Initialize(pl platforms.Platform, cfg *config.Instance)

Initialize builds the launcher cache from platform launchers. This should be called once at startup after custom launchers are loaded.

func (*LauncherCache) Refresh

func (lc *LauncherCache) Refresh(pl platforms.Platform, cfg *config.Instance)

Refresh rebuilds the cache with updated launcher data. This can be called via API to refresh the cache without restarting.

type PathInfo

type PathInfo struct {
	Path      string
	Base      string
	Filename  string
	Extension string
	Name      string
}

func GetPathInfo

func GetPathInfo(path string) PathInfo

type RegexCache

type RegexCache struct {
	// contains filtered or unexported fields
}

RegexCache provides thread-safe caching of compiled regular expressions to avoid repeated compilation overhead during media scanning operations.

func NewRegexCache

func NewRegexCache() *RegexCache

NewRegexCache creates a new RegexCache instance

func (*RegexCache) Clear

func (rc *RegexCache) Clear()

Clear removes all cached patterns (useful for testing or memory management)

func (*RegexCache) Compile

func (rc *RegexCache) Compile(pattern string) (*regexp.Regexp, error)

Compile compiles a regex pattern and caches it for future use. If the pattern is already cached, returns the cached version. Returns an error if the pattern cannot be compiled.

func (*RegexCache) MustCompile

func (rc *RegexCache) MustCompile(pattern string) *regexp.Regexp

MustCompile compiles a regex pattern and caches it for future use. If the pattern is already cached, returns the cached version. Panics if the pattern cannot be compiled (same behavior as regexp.MustCompile).

func (*RegexCache) Size

func (rc *RegexCache) Size() int

Size returns the number of cached patterns

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(args ServiceArgs) (*Service, error)

func (*Service) Pid

func (s *Service) Pid() (int, error)

Pid returns the process ID of the current running service daemon.

func (*Service) Restart

func (s *Service) Restart() error

func (*Service) Running

func (s *Service) Running() bool

Running returns true if the service is running.

func (*Service) ServiceHandler

func (s *Service) ServiceHandler(cmd *string) error

func (*Service) Start

func (s *Service) Start() error

Start a new service daemon in the background.

func (*Service) Stop

func (s *Service) Stop() error

Stop the service daemon.

type ServiceArgs

type ServiceArgs struct {
	Platform platforms.Platform
	Entry    ServiceEntry
	NoDaemon bool
}

type ServiceEntry

type ServiceEntry func() (func() error, error)

type VirtualPathResult

type VirtualPathResult struct {
	Scheme string
	ID     string
	Name   string
}

VirtualPathResult holds parsed virtual path components

func ParseVirtualPathStr

func ParseVirtualPathStr(virtualPath string) (result VirtualPathResult, err error)

ParseVirtualPathStr parses a virtual path and returns its components with string ID

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL