Documentation
¶
Overview ¶
Package scan walks library folders and keeps the items table in sync with disk.
Index ¶
- Constants
- Variables
- func Edition(path string) string
- func ExtraDirKind(name string) (string, bool)
- func ExtraFileKind(name string) (string, bool)
- func ExtraName(path string, titles ...string) string
- func FolderTrailers(dir string) []string
- func IsExtraDir(name string, nested bool) bool
- func IsExtraFile(name string) bool
- func IsTrailerFile(name string) bool
- func KindNames() []string
- func MovieTrailers(root, path string) []string
- func Register(k Kind)
- func ShowFolders(root, episodePath string) (show, season string)
- func SortExtras(extras []Extra)
- func TrailerName(path string) string
- func Trailers(extras []Extra) []string
- func Unregister(name string)
- type BookFile
- type EpisodeInfo
- type Extra
- type File
- type Finisher
- type FolderWatch
- type Kind
- type MovieInfo
- type Remote
- type ScanReport
- type Scanner
- func (s *Scanner) Report(libraryID int64) (since time.Time, last *ScanReport)
- func (s *Scanner) Running(libraryID int64) bool
- func (s *Scanner) Scan(ctx context.Context, lib store.Library) (Stats, error)
- func (s *Scanner) ScanAll(ctx context.Context)
- func (s *Scanner) ScanPaths(ctx context.Context, lib store.Library, paths []string) (Stats, error)
- func (s *Scanner) Start(ctx context.Context, lib store.Library) bool
- type Session
- type Stats
- type TrackInfo
- type Unprobed
- type WatchMode
- type Watcher
Constants ¶
const ( ExtraTrailer = "trailer" ExtraBehindTheScenes = "behindTheScenes" ExtraDeleted = "deleted" ExtraFeaturette = "featurette" ExtraInterview = "interview" ExtraScene = "scene" ExtraShort = "short" ExtraOther = "other" )
The kinds of extra, as the API names them.
const ( MethodEvents = "events" MethodPolling = "polling" MethodOff = "off" )
How a folder is being watched, for FolderWatch.Method.
const SettingWatch = "library_watch"
SettingWatch holds the WatchMode.
Variables ¶
var ErrAlreadyRunning = errors.New("scan already running")
var ErrSkip = errUnplayable
ErrSkip from Index leaves a file out, like one with nothing playable.
var ExtraKinds = []string{ExtraTrailer, ExtraBehindTheScenes, ExtraDeleted, ExtraFeaturette, ExtraInterview, ExtraScene, ExtraShort, ExtraOther}
ExtraKinds is the order extras are listed in.
Functions ¶
func Edition ¶ added in v0.2.1
Edition is the edition a video file's name says it is, such as "Director's Cut", or "" when it names none. A file named only "movie.mkv" takes its folder's.
func ExtraDirKind ¶ added in v0.2.1
ExtraDirKind says which kind of extra a folder holds, if any.
func ExtraFileKind ¶ added in v0.2.1
ExtraFileKind says which kind of extra a file's name marks it as, if any.
func ExtraName ¶ added in v0.2.1
ExtraName is what an extra is called on screen: its file name without the kind's suffix, unless that leaves only one of the title's names. Empty means it has no name of its own, so players call it by its kind.
func FolderTrailers ¶
FolderTrailers lists the trailers in a show's or season's folder.
func IsExtraDir ¶ added in v0.2.1
IsExtraDir reports whether a folder holds extras. Only a Trailers folder counts right in a library's folder: there, "Shorts" or "Other" is more likely a group of titles than a title's extras. nested is whether the folder is inside a title's folder.
func IsExtraFile ¶ added in v0.2.1
IsExtraFile reports whether a file name marks an extra.
func IsTrailerFile ¶
IsTrailerFile reports whether a file name marks a trailer.
func MovieTrailers ¶
MovieTrailers lists the trailers for a movie file (see MovieExtras).
func Register ¶
func Register(k Kind)
Register adds a library kind. Built-in kinds register from init; plugins register theirs while the server runs.
func ShowFolders ¶
ShowFolders returns a show's folder and, when episodes are filed by season, the season's folder, given one of the episodes under it.
func SortExtras ¶ added in v0.2.1
func SortExtras(extras []Extra)
SortExtras puts extras in ExtraKinds order, then by file.
func TrailerName ¶
TrailerName is what a trailer file is called on screen.
func Unregister ¶ added in v0.1.1
func Unregister(name string)
Unregister removes a library kind, when a plugin is turned off. Libraries of that kind keep their items but aren't scanned.
Types ¶
type BookFile ¶ added in v0.1.2
type BookFile struct {
Author string
Book string
Series string
SeriesIndex *float64
Year int
Narrators []string
Overview string
Part string // the file's own title
PartIndex int
Disc int
Whole bool // the file is the whole book, chapters and all
// The book's and author's own folders, for artwork and notes; empty
// when the book or author has no folder of its own.
BookDir, AuthorDir string
}
BookFile is what an audiobook file's place on disk and its tags say.
func ParseBookPath ¶ added in v0.1.2
ParseBookPath reads the author, series and book from the folders above a file, for files without tags.
type EpisodeInfo ¶
type EpisodeInfo struct {
Show string
Season int
Episode int
Title string // episode title when the name carries one
OK bool
}
EpisodeInfo is what an episode's path says about it.
func ParseEpisode ¶
func ParseEpisode(libraryRoot, path string) EpisodeInfo
ParseEpisode understands "Show/Season 1/Show - S01E02 - Title.mkv" and release-style "Show.Name.S01E02.720p.mkv". The show name comes from the library folder layout when it's there, since file names are often abbreviated.
type Extra ¶ added in v0.2.1
Extra is one extra's file and kind.
func FolderExtras ¶ added in v0.2.1
FolderExtras lists the extras in a movie's, show's or season's folder: files named as extras, and the videos in folders for extras, two levels deep ("Extras/Deleted Scenes/Bank job.mkv"). An inner folder's kind wins.
func MovieExtras ¶ added in v0.2.1
MovieExtras lists a movie's extras. A movie in its own folder takes every extra there; one sharing the library folder with others only takes those named after it.
type File ¶
type File struct {
Library store.Library
Root string // the library folder the file was found under
Path string
Info fs.FileInfo
Probe probe.Result
}
File is one media file found during a scan.
type Finisher ¶ added in v0.1.2
type Finisher interface {
Kind
FinishScan(ctx context.Context, st *store.Store, lib store.Library) error
}
Finisher is a Kind with work to do once a scan has filed every file, such as adding up a book's parts.
type FolderWatch ¶
type FolderWatch struct {
Path string `json:"path"`
Method string `json:"method"`
// Reason says why a folder is polled: "network share (cifs)", or that
// change notifications couldn't be set up.
Reason string `json:"reason,omitempty"`
}
FolderWatch tells admins how one library folder is watched.
type Kind ¶
type Kind interface {
Name() string
Wants(path string) bool
// Playable reports whether a probed file has what this library plays.
// Files that don't are left out, along with folders holding nothing else.
Playable(pr probe.Result) bool
// Index files one file, creating any containers it lives in, and returns
// the playable item. The scanner fills in the file and probe fields.
Index(ctx context.Context, st *store.Store, f File) (store.Item, error)
}
Kind is a type of library: which files belong in it and how they're filed. Movies, TV, music and audiobooks are built in; library-type plugins register more.
func KindByName ¶
KindByName returns a registered library kind.
type MovieInfo ¶
MovieInfo is what a movie's file or folder name says about it.
func ParseMovie ¶
ParseMovie reads "Title (Year)" or release-style "Title.Year.1080p.BluRay" from the file name, falling back to the folder name when the file is generic.
type Remote ¶ added in v0.1.7
type Remote interface {
Kind
Remote()
}
Remote is a Kind whose items aren't files in folders but come from elsewhere, such as podcasts from their feeds. Scanning a library of it refreshes it with Scanner.Refresh instead of walking folders.
type ScanReport ¶ added in v0.1.11
type ScanReport struct {
Started int64 `json:"started"` // milliseconds
TookMs int64 `json:"tookMs"`
Added int `json:"added"`
Updated int `json:"updated"`
Removed int `json:"removed"`
Replaced int `json:"replaced"`
Failed int `json:"failed"`
Unplayable int `json:"unplayable"`
Error string `json:"error,omitempty"`
}
ScanReport is how a library's last full scan went, for the admin dashboard.
type Scanner ¶
type Scanner struct {
Store *store.Store
Prober probe.Prober
Log *slog.Logger
// AfterScan runs once a library scan finishes, e.g. to fetch metadata.
AfterScan func(ctx context.Context, lib store.Library)
// Added runs for each file a scan adds, e.g. to tell plugins.
Added func(ctx context.Context, lib store.Library, itemID int64)
// Refresh brings a library of a Remote kind, such as podcasts, up to
// date; nil leaves them as they are.
Refresh func(ctx context.Context, lib store.Library) (added, failed int, err error)
// MissingGrace is how long a file that a scan of just some paths (the
// watcher's) finds missing stays listed, waiting for the file that
// takes its place. Download tools often delete the old copy first and
// move the new one in later, and the watcher sees the two apart. Zero
// removes missing files right away. A full scan always does, once it has
// matched them with what replaced them (see store.Replacements).
MissingGrace time.Duration
// contains filtered or unexported fields
}
func (*Scanner) Report ¶ added in v0.1.11
func (s *Scanner) Report(libraryID int64) (since time.Time, last *ScanReport)
Report says since when a library is being scanned (zero when it isn't), and how its last full scan went, if there was one since the server started.
func (*Scanner) Scan ¶
Scan brings one library in line with its folders. Unchanged files (same size and mtime) are skipped, so rescans are cheap.
func (*Scanner) ScanPaths ¶
ScanPaths brings just these files and folders of a library in line with disk: what's there is added or updated, and what's listed under a path that's gone is removed. The watcher uses it to pick up changes without walking the whole library.
func (*Scanner) Start ¶ added in v0.1.16
Start scans a library in the background. The library counts as being scanned (Running) before Start returns, so whoever asked for the scan, and anyone polling for it to finish, never sees it idle before it has begun. It reports false when a scan of the library is already running.
type Session ¶ added in v0.1.1
Session is a Kind that sets something up for a whole scan, such as a plugin's sandbox. The scanner calls BeginScan before the first file and the function it returns after the last.
type Stats ¶
type Stats struct {
Added, Updated, Unchanged, Removed, Failed int
// Replaced counts files that took the place of a missing one (a better
// copy, or the same file renamed or moved); the old item took the new
// file and kept everyone's watch history.
Replaced int
Unplayable int // files with no playable stream, left out
Took time.Duration
}
type TrackInfo ¶
type TrackInfo struct {
Artist string // the album's artist, which the album is filed under
// TrackArtist is the track's own artist from its tags, when they name one.
TrackArtist string
Album string
Title string
Track int
Disc int
Year int
}
TrackInfo is a music file's place in the library, from tags or folders.
func ParseTrackPath ¶
ParseTrackPath reads "Artist/Album/01 - Title.flac" for files without tags.
type Unprobed ¶ added in v0.1.1
type Unprobed interface {
Kind
Unprobed()
}
Unprobed is a Kind whose files aren't audio or video, such as a plugin's games. They aren't run through ffprobe, so Playable isn't asked.
type WatchMode ¶
type WatchMode string
WatchMode says how library folders are watched.
const ( // WatchAuto uses change notifications on local disks and polling on // network shares. WatchAuto WatchMode = "auto" // WatchPoll polls every folder, for disks that look local but aren't, // like a share mounted inside a container's own filesystem. WatchPoll WatchMode = "poll" // WatchOff leaves it to the periodic rescan. WatchOff WatchMode = "off" )
type Watcher ¶
type Watcher struct {
Scanner *Scanner
Log *slog.Logger
// PollInterval is how often polled folders are checked. A pass that takes
// long (a big library on a slow share) waits longer, so polling never
// keeps the share busy.
PollInterval time.Duration
// Quiet is how long a path must hold still before it's scanned, so a
// file still being copied isn't read half way.
Quiet time.Duration
// contains filtered or unexported fields
}
func (*Watcher) Reload ¶
func (w *Watcher) Reload()
Reload starts over with the current libraries and mode. Call it when either changes.
func (*Watcher) Status ¶
func (w *Watcher) Status(libraryID int64) []FolderWatch
Status says how each folder of a library is watched; nil until the watcher has set it up.