config

package
v0.3.22 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides configuration management for goplexcli. It handles loading, saving, and validating user configuration including Plex server credentials, multi-server support, and paths to external tools. Configuration is stored in a platform-specific config directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCacheDir

func GetCacheDir() (string, error)

GetCacheDir returns the cache directory path

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the platform-specific config directory

func GetConfigPath

func GetConfigPath() (string, error)

GetConfigPath returns the full path to the config file

Types

type Config

type Config struct {
	// Legacy single-server fields (maintained for backward compatibility)
	PlexURL      string `json:"plex_url,omitempty"`
	PlexToken    string `json:"plex_token"`
	PlexUsername string `json:"plex_username,omitempty"`

	// Servers holds multi-server configuration. Each server can be independently
	// enabled or disabled for indexing.
	Servers []PlexServer `json:"servers,omitempty"`

	// Tool paths allow overriding the default paths to external binaries.
	// If empty, the system PATH is searched.
	MPVPath    string `json:"mpv_path,omitempty"`
	RclonePath string `json:"rclone_path,omitempty"`
	FzfPath    string `json:"fzf_path,omitempty"`

	// DownloadDir is the destination directory for downloads. A leading "~"
	// is expanded to the user's home directory. If empty, downloads go to the
	// current working directory. Can be overridden per-run with --dest.
	DownloadDir string `json:"download_dir,omitempty"`

	// SyncPeer is the hostname or IP (optionally host:port) of another computer
	// on the LAN to pull the media cache from ("Sync from LAN"). When set, sync
	// goes straight to this host; when empty, mDNS auto-discovery is used.
	SyncPeer string `json:"sync_peer,omitempty"`

	// PathMappings translate Plex on-disk file paths into rclone remote paths
	// during cache indexing. If empty, a legacy heuristic is used.
	PathMappings []PathMapping `json:"path_mappings,omitempty"`

	// WebDAVUser and WebDAVPass are the shared Basic Auth credentials used for
	// every gowebdav server discovered on the LAN (the "transfer to webdav"
	// action). gowebdav servers advertise themselves via mDNS but do not
	// advertise credentials, so the same user/pass is assumed across all of
	// them. Empty values mean connect anonymously.
	WebDAVUser string `json:"webdav_user,omitempty"`
	WebDAVPass string `json:"webdav_pass,omitempty"`
	// WebDAVDir is an optional sub-path under the server root to upload into
	// (e.g. "incoming"). Empty uploads to the server root.
	WebDAVDir string `json:"webdav_dir,omitempty"`

	// OutplayerTargets are user-defined Outplayer "Wi-Fi transfer" destinations.
	// Unlike gowebdav servers they are not discovered on the LAN; each is
	// configured explicitly with a base URL. Individually enabled or disabled;
	// disabled targets are hidden from the transfer menu but kept in config.
	OutplayerTargets []OutplayerTarget `json:"outplayer_targets,omitempty"`
}

Config holds all user configuration for goplexcli. It supports both legacy single-server configurations and newer multi-server setups.

func Load

func Load() (*Config, error)

Load reads the config file and returns a Config struct

func (*Config) GetEnabledOutplayerTargets added in v0.3.0

func (c *Config) GetEnabledOutplayerTargets() []OutplayerTarget

GetEnabledOutplayerTargets returns all Outplayer targets that are enabled and should be offered as transfer destinations.

func (*Config) GetEnabledServers

func (c *Config) GetEnabledServers() []PlexServer

GetEnabledServers returns all servers that should be indexed

func (*Config) MigrateLegacy

func (c *Config) MigrateLegacy() error

MigrateLegacy converts old single-server config to multi-server format

func (*Config) ResolveDownloadDir added in v0.2.2

func (c *Config) ResolveDownloadDir(override string) (string, error)

ResolveDownloadDir returns the directory downloads should be written to. Precedence: the override argument (e.g. from a --dest flag), then the configured DownloadDir, then the current working directory. A leading "~" in either configured path is expanded to the user's home directory.

func (*Config) Save

func (c *Config) Save() error

Save writes the config to disk

func (*Config) TokenForServer added in v0.3.1

func (c *Config) TokenForServer(s PlexServer) string

TokenForServer returns the token to use when talking to a specific server: the server's own access token when present, otherwise the account-wide PlexToken. Owners can use their account token directly, but shared users get a 401 from the server unless the per-server token is used.

func (*Config) TokenForURL added in v0.3.1

func (c *Config) TokenForURL(serverURL string) string

TokenForURL returns the token to use for the server at the given URL, matching configured servers while ignoring trailing slashes. It falls back to the account-wide PlexToken when no configured server matches or the matching server has no token of its own.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the config has all required fields and valid values. It returns an error describing what's wrong if validation fails. Call this after Load() to ensure the configuration is usable.

type OutplayerTarget added in v0.3.0

type OutplayerTarget struct {
	// Name is a human-readable identifier for the target (e.g. "iPhone").
	Name string `json:"name"`
	// URL is the base URL of the Outplayer Wi-Fi transfer server, as shown in
	// the app (e.g. "http://192.168.0.34").
	URL string `json:"url"`
	// Dir is the destination folder on the target to upload into. Empty means
	// the server root. Note that some built-in folders (e.g. "Inbox") are not
	// writable, so the root is the safe default.
	Dir string `json:"dir,omitempty"`
	// Enabled determines whether this target appears in the transfer menu.
	Enabled bool `json:"enabled"`
}

OutplayerTarget represents an Outplayer "Wi-Fi transfer" destination. Outplayer is an iOS media player whose Wi-Fi transfer feature runs a small HTTP server (GCDWebUploader) that accepts multipart file uploads. Multiple targets can be configured and each individually enabled or disabled.

func (OutplayerTarget) Validate added in v0.3.0

func (t OutplayerTarget) Validate() error

Validate checks that an Outplayer target has the required fields and a usable URL. It is called when adding a target so misconfiguration is caught early.

type PathMapping added in v0.2.2

type PathMapping struct {
	Prefix string `json:"prefix"`
	Remote string `json:"remote"`
}

PathMapping translates a Plex on-disk file path prefix into an rclone remote. A file path beginning with Prefix has that prefix replaced by Remote. For example {Prefix: "/home/joshkerr/plexcloudservers2/", Remote: "plexcloudservers2:"} turns "/home/joshkerr/plexcloudservers2/Media/TV/x.mkv" into "plexcloudservers2:Media/TV/x.mkv".

type PlexServer

type PlexServer struct {
	// Name is a human-readable identifier for the server
	Name string `json:"name"`
	// URL is the base URL of the Plex server (e.g., "http://192.168.1.100:32400")
	URL string `json:"url"`
	// Token is this server's access token from plex.tv. Shared (non-owner)
	// accounts cannot use their account token against a server — the server
	// returns 401 — so the per-server token must be used when present. Empty
	// for configs saved before this field existed; callers fall back to the
	// account-wide PlexToken (see Config.TokenForServer).
	Token string `json:"token,omitempty"`
	// Enabled determines whether this server is included when indexing media
	Enabled bool `json:"enabled"`
}

PlexServer represents a configured Plex server. Multiple servers can be configured, with each individually enabled or disabled.

Jump to

Keyboard shortcuts

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