Documentation
¶
Overview ¶
Package plex provides media organization for Plex libraries. It handles media type detection, file renaming, and library placement.
Index ¶
- Variables
- func CleanupSourceDir(sourceDir, downloadsPath, incompletePath string) error
- func FindAllVideos(path string) ([]string, error)
- func FindMainVideo(path string) (string, error)
- func FindSubtitles(path string) []string
- func FindSubtitlesForVideo(baseDir, videoPath string) []string
- func FormatMoviePath(m MovieNaming) (string, error)
- func FormatTVFilename(t TVNaming) string
- func FormatTVPath(t TVNaming) (string, error)
- func SanitizeFilename(name string) string
- func ValidatePath(path, allowedBase string) error
- type DetectionResult
- type MediaType
- type MoveConfig
- type MoveProgress
- type MoveResult
- type Mover
- func (m *Mover) MoveAsMovie(ctx context.Context, sourcePath string, naming MovieNaming) (*MoveResult, error)
- func (m *Mover) MoveAsTV(ctx context.Context, sourcePath string, naming TVNaming) (*MoveResult, error)
- func (m *Mover) MoveToLibrary(ctx context.Context, sourcePath string) (*MoveResult, error)
- func (m *Mover) MoveToLibraryWithProgress(ctx context.Context, sourcePath string, detection DetectionResult, ...) (*MoveResult, error)
- type MovieNaming
- type TVNaming
Constants ¶
This section is empty.
Variables ¶
var ( ErrSourceNotFound = errors.New("source file or directory not found") ErrDestinationExists = errors.New("destination already exists") ErrPermissionDenied = errors.New("permission denied") ErrPathEscape = errors.New("path escapes allowed directory") )
Move operation errors.
var ErrDetectionFailed = errors.New("unable to detect media type")
ErrDetectionFailed indicates media type could not be determined.
var ErrInvalidInput = errors.New("invalid input for naming")
ErrInvalidInput indicates the input cannot be processed for naming.
Functions ¶
func CleanupSourceDir ¶ added in v0.1.8
CleanupSourceDir removes all files and the directory itself. Call this after user confirms cleanup of remaining files. Includes safeguards to prevent accidentally deleting important directories. downloadsPath is the configured downloads directory (e.g., ~/Downloads/torrents) incompletePath is qBittorrent's temp/incomplete path (may be empty if not configured) Both paths will be protected along with common subdirectories.
func FindAllVideos ¶ added in v0.1.9
FindAllVideos finds all video files in a directory (up to 2 levels deep), ignoring samples. Returns files sorted alphabetically. Used for TV season packs with multiple episodes.
func FindMainVideo ¶ added in v0.1.6
FindMainVideo finds the largest video file in a directory (top level only), ignoring samples.
func FindSubtitles ¶ added in v0.1.6
FindSubtitles finds all .srt subtitle files in a directory (up to 2 levels deep).
func FindSubtitlesForVideo ¶ added in v0.1.9
FindSubtitlesForVideo finds .srt subtitle files matching a specific video file. Looks for subtitles that start with the same base name (without extension). Like script: find "$BASE_DIR" -maxdepth 2 -type f -iname "${NO_EXT}*.srt"
func FormatMoviePath ¶
func FormatMoviePath(m MovieNaming) (string, error)
FormatMoviePath generates a Plex-compatible filename for a movie. Returns: "Title (Year).ext" (directly in Movies folder, like the bash script)
func FormatTVFilename ¶ added in v0.1.6
FormatTVFilename generates a Plex-compatible filename for a TV episode. Returns: "Show Title - S##E## - Episode Title.ext" or "Show Title - S##E##.ext"
func FormatTVPath ¶
FormatTVPath generates a Plex-compatible directory path for a TV episode. Returns: "Show Title/Season ##" - caller appends original filename.
func SanitizeFilename ¶
SanitizeFilename removes or replaces characters that are invalid for filesystem paths.
func ValidatePath ¶
ValidatePath checks that a path is safe and within allowed boundaries.
Types ¶
type DetectionResult ¶
type DetectionResult struct {
Type MediaType
Title string // Parsed title
Year int // Release year (movies) or 0 if unknown
Season int // Season number (TV) or 0
Episode int // Episode number (TV) or 0
Confidence float64 // 0.0-1.0 confidence score
}
DetectionResult holds the outcome of media type detection.
func Detect ¶
func Detect(filename string) (DetectionResult, error)
Detect analyzes a filename to determine media type. Checks TV patterns first (more specific), then falls back to movie year detection.
func DetectFromPath ¶
func DetectFromPath(path string) (DetectionResult, error)
DetectFromPath analyzes a full path including parent directories. Uses the innermost directory or filename for detection.
type MoveConfig ¶
type MoveConfig struct {
MovieLibraryPath string // Base path for movie library
TVLibraryPath string // Base path for TV library
UseSudo bool // Use sudo for rsync operations
}
MoveConfig holds configuration for media file operations.
type MoveProgress ¶ added in v0.1.6
type MoveProgress struct {
BytesCopied int64
TotalBytes int64
Percentage float64 // Overall progress (0.0-1.0)
CurrentFile string
Rate string // Transfer rate (e.g., "10.5MB/s")
ETA string // Estimated time remaining (e.g., "0:01:23")
// TV multi-episode fields
EpisodeIndex int // Current episode index (1-based), 0 for movies
EpisodeTotal int // Total episodes, 0 for movies
EpisodeProgress float64 // Current episode progress (0.0-1.0)
}
MoveProgress reports progress during a move operation.
type MoveResult ¶
type MoveResult struct {
SourcePath string // First/main source file
DestinationPath string // Destination directory (TV) or file (movie)
MediaType MediaType
BytesMoved int64
FilesMoved int // Number of video files moved (1 for movies, N for TV)
Success bool
Error error
RemainingFiles []string // Files left in source directory (for cleanup prompt)
SourceDir string // Source directory path (for cleanup)
}
MoveResult contains the outcome of a move operation.
type Mover ¶
type Mover struct {
// contains filtered or unexported fields
}
Mover handles moving completed downloads to Plex libraries.
func NewMover ¶
func NewMover(config MoveConfig) *Mover
NewMover creates a new Mover with the given configuration.
func (*Mover) MoveAsMovie ¶
func (m *Mover) MoveAsMovie(ctx context.Context, sourcePath string, naming MovieNaming) (*MoveResult, error)
MoveAsMovie moves a file to the movie library with specified naming.
func (*Mover) MoveAsTV ¶
func (m *Mover) MoveAsTV(ctx context.Context, sourcePath string, naming TVNaming) (*MoveResult, error)
MoveAsTV moves a file to the TV library with specified naming.
func (*Mover) MoveToLibrary ¶
MoveToLibrary moves a completed download without progress reporting.
func (*Mover) MoveToLibraryWithProgress ¶ added in v0.1.6
func (m *Mover) MoveToLibraryWithProgress( ctx context.Context, sourcePath string, detection DetectionResult, cleanup bool, progress chan<- MoveProgress, ) (*MoveResult, error)
MoveToLibraryWithProgress moves a completed download to the appropriate Plex library. For movies: moves the largest video file to Movies library. For TV: moves ALL video files, each to their proper season folder based on S##E## in filename. It reports progress via the provided channel.