mediascanner

package
v2.22.1 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PhaseDiscovering     = "discovering"
	PhaseInitializing    = "initializing"
	PhaseCreatingIndexes = "creating_indexes"
	PhaseBuildingCaches  = "building_caches"
)

Variables

View Source
var ErrFsTimeout = errors.New("filesystem operation timed out")

ErrFsTimeout is returned when a filesystem operation exceeds the timeout.

Functions

func FallbackMediaIdentity added in v2.21.0

func FallbackMediaIdentity(cfg *config.Instance, systemID, path string) (database.MediaIdentity, bool)

FallbackMediaIdentity builds the identity the indexer would give a played file that is not in the index, such as a cartridge dumped by the Operator bridge, so its play history can still be matched to a title. The title, slug and filename tags come from the same derivation StageMediaPath uses, so a later plain folder walk of that file yields the same fingerprint. A later index that supplies scanner inputs this path cannot know (a directory prefix policy, a scanner-provided name, NoExt) can differ, and the server reconciles the two observations. Only absolute filesystem paths qualify: virtual paths and bare names such as arcade set names are not files the indexer would have parsed.

func FindPath

func FindPath(ctx context.Context, path string) (string, error)

FindPath case-insensitively finds a file/folder at a path and returns the actual filesystem case. On case-insensitive filesystems (Windows, macOS), this ensures we get the real case from the filesystem rather than preserving the input case, which prevents case-mismatch issues during string comparisons.

This function recursively normalizes the entire path from root to leaf to ensure all components match the actual filesystem case.

Special handling:

  • Linux: Prefers exact match before case-insensitive match (handles File.txt vs file.txt)
  • Windows: Handles 8.3 short names (PROGRA~1) via fallback to os.Stat
  • All platforms: Works with symlinks, UNC paths, network drives

func GetFiles

func GetFiles(
	ctx context.Context,
	cfg *config.Instance,
	platform platforms.Platform,
	systemID string,
	path string,
	pauser *syncutil.Pauser,
) ([]string, error)

GetFiles searches for all valid games in a given path and returns a list of files. Uses fastwalk for parallel directory traversal with built-in symlink cycle detection. Deep searches .zip files when ZipsAsDirs is enabled.

func MediaDBSettled added in v2.22.0

func MediaDBSettled(mediaDB database.MediaDBI) bool

MediaDBSettled reports whether the media database is idle: not corrupt or awaiting rebuild, no indexing under way or owed, and no optimization (which includes the disambiguation backfill) under way or owed. Until then a library file may simply not be indexed yet, so a fallback identity must not stand in for its row. Status read failures count as unsettled.

func NewNamesIndex

func NewNamesIndex(
	ctx context.Context,
	platform platforms.Platform,
	cfg *config.Instance,
	systems []systemdefs.System,
	fdb *database.Database,
	update func(IndexStatus),
	pauser *syncutil.Pauser,
) (indexedFiles int, err error)

func NewNamesIndexWithSources added in v2.18.0

func NewNamesIndexWithSources(
	ctx context.Context, platform platforms.Platform, cfg *config.Instance,
	systems []systemdefs.System, fdb *database.Database, update func(IndexStatus),
	pauser *syncutil.Pauser, sourceOptions *IndexSourceOptions,
) (indexedFiles int, err error)

NewNamesIndexWithSources reports selected successful launcher contributions without changing the existing filesystem or custom scanner contracts.

func SeedCanonicalTags added in v2.7.0

func SeedCanonicalTags(ctx context.Context, db database.MediaDBI) error

SeedCanonicalTags seeds the database with canonical GameDataBase-style hierarchical tag types and values (e.g. "genre:sports:wrestling", "players:2:vs"). Definitions live in the tags package. Runs set-based inside its own transaction; already-present rows are left untouched.

func StageMediaPath added in v2.16.0

func StageMediaPath(params *StageMediaPathParams) error

StageMediaPath parses one scanned file into its media fragments and appends them to the scanner staging tables. Tags, missing state, and most existence checks run set-based in ReconcileStagedSystem once the system's files are staged, so scanner memory does not grow with library or database size.

Types

type IndexSourceOptions added in v2.18.0

type IndexSourceOptions struct {
	Completed    func([]IndexedSource)
	LauncherIDs  []string
	AllLaunchers bool
}

IndexSourceOptions requests a bounded summary for selected launchers, or for every launcher when AllLaunchers is set. Completed runs only after successful finalization; existing index callers need no hook.

type IndexStatus

type IndexStatus struct {
	SystemID string
	Phase    string // PhaseDiscovering, PhaseInitializing, or empty during indexing
	// WalkPath is the folder a running folder scan is reading, empty outside
	// a scan.
	WalkPath string
	Total    int
	Step     int
	Files    int
	// WalkEntries counts the filesystem entries this system's folder scan has
	// read so far, zero outside a scan.
	WalkEntries int
	// WalkStalled is set on the one update that finds the scan stalled.
	WalkStalled bool
}

type IndexedSource added in v2.18.0

type IndexedSource struct {
	LauncherID string
	SystemID   string
	Files      int
	// Unavailable marks files indexed for a launcher that cannot run here,
	// such as one whose emulator is not installed. A scraper keyed on the
	// files themselves still applies to them; one that reads the launcher's
	// own data does not.
	Unavailable bool
}

IndexedSource identifies an applicable contribution, not a durable media row.

type MediaPathFragments

type MediaPathFragments struct {
	Path         string
	FileName     string
	Title        string
	DisplayTitle string
	Slug         string
	SlugTokens   []string
	Ext          string
	Tags         []string
}

func GetPathFragments

func GetPathFragments(params *PathFragmentParams) MediaPathFragments

type PathFragmentParams added in v2.7.0

type PathFragmentParams struct {
	Config              *config.Instance
	Path                string
	SystemID            string
	MediaType           slugs.MediaType
	ProvidedName        string
	PrefixPolicy        browseprefix.Policy
	NoExt               bool
	StripLeadingNumbers bool
}

PathFragmentParams contains parameters for GetPathFragments.

type PathResult

type PathResult struct {
	Path   string
	System systemdefs.System
}

func GetSystemPaths

func GetSystemPaths(
	ctx context.Context,
	cfg *config.Instance,
	platform platforms.Platform,
	rootFolders []string,
	systems []systemdefs.System,
) []PathResult

type StageMediaPathParams added in v2.16.0

type StageMediaPathParams struct {
	Config       *config.Instance
	Source       *platforms.MediaSource
	DB           database.MediaDBI
	Path         string
	SystemID     string
	MediaType    slugs.MediaType
	ProvidedName string
	// LinkTarget is the path of the media this file is a symlink alias of.
	LinkTarget   string
	PrefixPolicy browseprefix.Policy
	NoExt        bool
}

StageMediaPathParams contains parameters for StageMediaPath.

Jump to

Keyboard shortcuts

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