Documentation
¶
Overview ¶
Package importer handles completed downloads by linking episode files into the library directory tree, creating episode_files records, and marking episodes as having a file on disk.
Index ¶
- Constants
- Variables
- type AbsoluteEpisodeResolver
- type Candidate
- type CandidateEpisode
- type ManualItem
- type ManualResult
- type RetryResult
- type Service
- func (s *Service) AttachFile(ctx context.Context, episodeID, seriesID, filePath string, sizeBytes int64, ...) error
- func (s *Service) ImportFile(ctx context.Context, grabID, contentPath string) error
- func (s *Service) ImportFromHaulRecord(ctx context.Context, seriesID, contentPath string, quality plugin.Quality) error
- func (s *Service) ImportManual(ctx context.Context, items []ManualItem, move bool) []ManualResult
- func (s *Service) RetryFailedImports(ctx context.Context, now time.Time) (RetryResult, error)
- func (s *Service) ScanManual(ctx context.Context, path, seriesID string) ([]Candidate, error)
- func (s *Service) Subscribe()
Constants ¶
const ( RejectSample = "sample" RejectUnknownSeries = "unknown_series" RejectUnknownEpisode = "unknown_episode" RejectAlreadyImported = "already_imported" RejectNotAnUpgrade = "existing_file_is_equal_or_better" )
Rejection reasons on a manual import candidate. A rejected candidate can still be imported if the user chooses to.
const ( // MaxImportAttempts caps automatic retries per grab. With the backoff // below, 10 attempts span roughly two days before Pilot gives up. MaxImportAttempts = 10 )
const MaxManualScanFiles = 2000
MaxManualScanFiles caps one scan.
Variables ¶
var ErrInsufficientSpace = errors.New("not enough free space in the library")
ErrInsufficientSpace means copying a file into the library would leave less free space than the library's min_free_space_gb. It is a soft failure: the import is retried later, once space may have been freed.
var ErrInvalidPath = errors.New("path must be an absolute path to an existing folder or video file")
ErrInvalidPath is returned for a scan or import path that is not an absolute path to an existing folder or video file.
var ErrUnimportableContent = errors.New("content can never import")
ErrUnimportableContent wraps import failures that can never succeed on retry with the same content — fake uploads delivering a .exe/.scr, or a "season pack" containing no video files at all. These are the only failures that warrant blocklisting the release; transient errors (full disk, DB hiccup) must not.
Functions ¶
This section is empty.
Types ¶
type AbsoluteEpisodeResolver ¶
type AbsoluteEpisodeResolver interface {
AbsoluteToTMDBEpisode(tmdbID, abs int) (season, episode int, ok bool)
}
AbsoluteEpisodeResolver maps an anime absolute episode number to the TMDB (season, episode) tuple Pilot stores in its database. The importer uses this to attach files like "Show - 48" — fansub releases that don't carry SxxExx — to the right episode row.
Defined as an interface (rather than a concrete *animelist.Service dep) so the importer's tests can stub it without dragging in the XML loader. Production wiring passes the real service.
type Candidate ¶
type Candidate struct {
Path string
Size int64
SeriesID string // "" when no series matched
SeriesTitle string
Season int
Episodes []CandidateEpisode
Quality plugin.Quality
Languages []string
Rejections []string
}
Candidate is one video file found by a manual import scan.
type CandidateEpisode ¶
CandidateEpisode is an episode a candidate file would be attached to.
type ManualItem ¶
ManualItem is one file the user chose to import.
type ManualResult ¶
ManualResult is the outcome for one ManualItem.
type RetryResult ¶
type RetryResult struct {
Attempted int // imports re-run
Imported int // re-runs that succeeded
Held int // skipped because the library root is not writable
NotDue int // skipped because the backoff hasn't elapsed
GaveUp int // failed for the last time (hit MaxImportAttempts)
}
RetryResult summarises one RetryFailedImports run.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service subscribes to TypeDownloadDone events and imports completed files into the library directory tree.
func NewService ¶
func NewService(q db.Querier, bus *events.Bus, logger *slog.Logger, mm *mediamanagement.Service, animeR AbsoluteEpisodeResolver, blocklistSvc *blocklist.Service) *Service
NewService creates a new Service. Pass nil for animelist when the caller doesn't have one wired up; the importer just won't resolve anime absolute-numbered files in that case (same as before this dependency existed). blocklistSvc may be nil (tests); hard import failures then simply skip the blocklist step.
func (*Service) AttachFile ¶
func (s *Service) AttachFile(ctx context.Context, episodeID, seriesID, filePath string, sizeBytes int64, quality plugin.Quality) error
AttachFile transfers srcPath into the library, applying rename if configured. Creates the episode_files record and marks the episode as having a file.
func (*Service) ImportFile ¶
ImportFile performs the full import pipeline for a completed download. contentPath may be a single video file or a directory (season pack).
func (*Service) ImportFromHaulRecord ¶
func (s *Service) ImportFromHaulRecord(ctx context.Context, seriesID, contentPath string, quality plugin.Quality) error
ImportFromHaulRecord runs the import pipeline against a Haul history record without requiring a pre-existing Pilot grab_history row. Used by the "import from Haul" flow on the Activity page and the per-episode "Haul has it" badge — surfaces files that landed in Haul's downloads directory but never got attached to a Pilot episode (because the original grab lost its episode_id, or the torrent was added directly in Haul, or the file pre-dates the importer fix).
seriesID identifies the target series in Pilot's DB; contentPath is the absolute path Haul reports as save_path/name. quality is taken as the caller specifies — typically zero plugin.Quality, since the caller doesn't know what the file actually is and the parser will re-derive what it can from the filename.
func (*Service) ImportManual ¶
func (s *Service) ImportManual(ctx context.Context, items []ManualItem, move bool) []ManualResult
ImportManual imports each item: every listed episode gets the file via AttachFile. With move, the source file is removed once all its episodes are imported (unless it is the library file itself). Results are per item; one failure does not stop the rest.
func (*Service) RetryFailedImports ¶
RetryFailedImports re-runs the import for completed downloads whose previous import failed, with exponential backoff per grab.
Before retrying, it checks that the target library root is writable. If not (the classic "library dir owned by root, container runs as uid 1000" setup mistake), the grab is held without spending an attempt: no number of retries can succeed until an operator fixes the folder, and once they do, the very next run imports everything.
func (*Service) ScanManual ¶
ScanManual lists the video files under path (a folder, or one file) with a proposed series, episodes and quality for each. It changes nothing. With seriesID set, every file is proposed for that series.