manualops

package
v0.9.0-dev.17 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package manualops implements the business logic for manual subtitle search and download operations. The HTTP handler glue remains in the parent server package; this package owns validation, query parsing, result building, and the background download pipeline.

Index

Constants

View Source
const MaxResults = 50

MaxResults caps the number of results a manual search returns.

Variables

This section is empty.

Functions

func LookupEpisodeMediaID

func LookupEpisodeMediaID(ctx context.Context, ls *LiveState, seriesID, season, episode int) string

LookupEpisodeMediaID resolves a Sonarr episode's stable media ID by series ID, season, and episode.

func LookupMediaTitle

func LookupMediaTitle(ctx context.Context, ls *LiveState, mediaType subflux.MediaType, arrID int) string

LookupMediaTitle resolves a media item's title by arr ID.

func LookupMovieMediaID

func LookupMovieMediaID(ctx context.Context, ls *LiveState, arrID int) string

LookupMovieMediaID resolves a Radarr movie's stable media ID by arr ID.

func ParseSearchQuery

func ParseSearchQuery(r *http.Request) (req subflux.SearchRequest, lang string, mediaType subflux.MediaType, arrID int)

ParseSearchQuery extracts search parameters from the request URL. The optional media_id parameter is the ARR internal ID (Radarr movie ID / Sonarr series ID): with season/episode it forms the MediaRef the handler resolves server-side for hash computation.

func QueryInt

func QueryInt(q interface{ Get(string) string }, key string) int

QueryInt parses a non-negative integer query parameter, returning 0 when absent or invalid.

func ResolveMediaIDs

func ResolveMediaIDs(ctx context.Context, ls *LiveState,
	mediaType subflux.MediaType, arrID, season, episode int,
) (coverageID, historyID string)

ResolveMediaIDs resolves the coverage and history media IDs for a manual download.

Types

type DownloadAccepted added in v0.1.148

type DownloadAccepted struct {
	ActivityID string `json:"activity_id"`
	Status     string `json:"status"`
}

DownloadAccepted is the 202 response body for an accepted manual download.

type DownloadRequest

type DownloadRequest struct {
	Provider    subflux.ProviderID `json:"provider"`
	SubtitleID  string             `json:"subtitle_id"`
	Language    string             `json:"language"`
	ReleaseName string             `json:"release_name,omitempty"`
	MediaType   subflux.MediaType  `json:"media_type,omitempty"`

	Score      int  `json:"score,omitempty"`
	Season     int  `json:"season,omitempty"`
	Episode    int  `json:"episode,omitempty"`
	ArrID      int  `json:"media_id,omitempty"`
	TopPick    bool `json:"top_pick,omitempty"`
	HearingImp bool `json:"hearing_impaired,omitempty"`
	Forced     bool `json:"forced,omitempty"`
	// contains filtered or unexported fields
}

DownloadRequest holds the parsed fields for a manual download. The video is addressed by MediaRef only (media_type + media_id [arr ID] + season/episode); the server resolves the video file path from the arr, so the wire carries no file path. videoPath is the server-resolved value, set by the handler after resolution, never decoded from JSON.

type DownloadStore

type DownloadStore interface {
	NextManualNumber(ctx context.Context, key subflux.ManualLockKey) int
	UpsertSubtitleFile(ctx context.Context, mediaType subflux.MediaType, mediaID string, sf *subflux.SubtitleFile) error
	SetSyncOffset(ctx context.Context, path string, offsetMs int64) error
	SaveDownload(ctx context.Context, rec *subflux.DownloadRecord) error
	// contains filtered or unexported methods
}

DownloadStore is what saving a manual download writes: the next ordinal for the numbered file, the coverage row, the timing offset, and the download record — plus store, embedded so the search and download legs cannot disagree about the read half.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler serves the manual search/download HTTP endpoints.

func NewHandler

func NewHandler(deps HandlerDeps) *Handler

NewHandler constructs a Handler from its dependencies.

func (*Handler) HandleClearLock

func (h *Handler) HandleClearLock(w http.ResponseWriter, r *http.Request)

HandleClearLock handles POST /api/search/clear-lock.

func (*Handler) HandleManualDownload

func (h *Handler) HandleManualDownload(w http.ResponseWriter, r *http.Request)

HandleManualDownload handles POST /api/search/download.

func (*Handler) HandleManualSearch

func (h *Handler) HandleManualSearch(w http.ResponseWriter, r *http.Request)

HandleManualSearch handles GET /api/search?imdb=tt1234567&lang=fr&type=movie

func (*Handler) HandleSearchResolve added in v0.1.148

func (h *Handler) HandleSearchResolve(w http.ResponseWriter, r *http.Request)

HandleSearchResolve handles GET /api/search/resolve.

type HandlerDeps

type HandlerDeps struct {
	DBFunc     func() DownloadStore
	Activity   activityTracker
	Alerts     warnRecorder
	Events     eventPublisher
	Media      mediaWriter
	StateFunc  func() *LiveState
	BGTracker  bgTracker
	ServerCtx  func() context.Context
	Resolve    *resolve.Resolver
	DecodeJSON func(w http.ResponseWriter, r *http.Request, v any, maxSize int64) bool
}

HandlerDeps holds the dependencies for the manual search/download HTTP handlers. Resolve is the typed-reference resolver: the download verb and the manual-search hash computation address the video by MediaRef and the server resolves the file path from the arr — no client-supplied paths.

type LiveState

type LiveState struct {
	Cfg       pathValidator
	Engine    manualEngine
	Scorer    tierLabeller
	Sonarr    ManualSonarrClient
	Radarr    ManualRadarrClient
	SonarrLib ResolveSonarrClient
	RadarrLib ResolveRadarrClient
	Providers []provider.Provider
}

LiveState holds the runtime state needed for a manual search pass. Sonarr/Radarr are the narrow by-ID surfaces manual downloads use; SonarrLib/RadarrLib are the library-listing surfaces the resolve endpoint uses (all nil when the corresponding arr is not configured).

type ManualProviderNotice added in v0.6.6

type ManualProviderNotice struct {
	Provider subflux.ProviderID `json:"provider"`
	// Kind is "gated" when the provider gate skipped the provider and
	// "error" when its search failed.
	Kind    string `json:"kind"`
	Message string `json:"message"`
}

ManualProviderNotice says why one provider contributed no results.

type ManualRadarrClient added in v0.1.106

type ManualRadarrClient interface {
	MovieByID(ctx context.Context, movieID int) (arrapi.Movie, error)
	RescanMovie(ctx context.Context, movieID int) error
}

ManualRadarrClient is the Radarr surface manual downloads use.

type ManualSearchResponse

type ManualSearchResponse struct {
	Results   []SearchResult         `json:"results"`
	Providers []ManualProviderNotice `json:"providers,omitempty"`
}

ManualSearchResponse is the typed response from RunSearch. It deliberately carries no lock state: manual locks are invisible infrastructure, not a user-facing concept, so the popup has nothing to display about them. Providers lists each provider that returned nothing because it was skipped or failed.

func RunSearch

func RunSearch(ctx context.Context, deps *SearchDeps, ls *LiveState,
	req *subflux.SearchRequest, lang string, mediaType subflux.MediaType, filePath string,
) ManualSearchResponse

RunSearch queries every configured provider through the engine and returns the scored manual-search response.

type ManualSonarrClient added in v0.1.106

type ManualSonarrClient interface {
	SeriesByID(ctx context.Context, seriesID int) (arrapi.Series, error)
	RescanSeries(ctx context.Context, seriesID int) error
}

ManualSonarrClient is the Sonarr surface manual downloads use.

type ResolveCandidate added in v0.1.148

type ResolveCandidate struct {
	MediaType subflux.MediaType `json:"media_type"`
	Title     string            `json:"title"`
	MediaID   int               `json:"media_id"`
	Year      int               `json:"year,omitempty"`
}

ResolveCandidate is one ambiguous match in a resolve response's candidate list.

type ResolveRadarrClient added in v0.1.148

type ResolveRadarrClient interface {
	Movies(ctx context.Context) ([]arrapi.Movie, error)
}

ResolveRadarrClient is the Radarr surface query resolution uses.

type ResolveResponse added in v0.1.148

type ResolveResponse struct {
	Items      []ResolvedItem     `json:"items,omitempty"`
	Candidates []ResolveCandidate `json:"candidates,omitempty"`
	Resolved   bool               `json:"resolved"`
}

ResolveResponse is the typed result of GET /api/search/resolve. Exactly one holds: Resolved with Items (success), Candidates (ambiguous), or all empty (no match).

type ResolveSearchIDs added in v0.1.148

type ResolveSearchIDs struct {
	Imdb string `json:"imdb,omitempty"`
	Tvdb int    `json:"tvdb,omitempty"`
	Tmdb int    `json:"tmdb,omitempty"`
}

ResolveSearchIDs carries the stable search identifiers a resolved item forwards to the search leg.

type ResolveSonarrClient added in v0.1.148

type ResolveSonarrClient interface {
	Series(ctx context.Context) ([]arrapi.Series, error)
	Episodes(ctx context.Context, seriesID int) ([]arrapi.Episode, error)
}

ResolveSonarrClient is the Sonarr surface query resolution uses: the full series list for matching and per-series episodes for expansion.

type ResolvedItem added in v0.1.148

type ResolvedItem struct {
	MediaType subflux.MediaType `json:"media_type"`
	Title     string            `json:"title"`
	SearchIDs ResolveSearchIDs  `json:"search_ids"`
	MediaID   int               `json:"media_id"`
	Year      int               `json:"year,omitempty"`
	Season    int               `json:"season,omitempty"`
	Episode   int               `json:"episode,omitempty"`
}

ResolvedItem is one searchable media item: an episode of the matched series (file-bearing only) or the matched movie. MediaID is the arr ID, the same identity the search and download endpoints consume.

type SearchDeps

type SearchDeps struct {
	DB       store
	Activity activityTracker
	Alerts   warnRecorder
	Events   eventPublisher
}

SearchDeps holds the dependencies a manual search or download pass needs.

type SearchResult

type SearchResult struct {
	Matches     map[string]int     `json:"matches,omitempty"`
	Provider    subflux.ProviderID `json:"provider"`
	Language    string             `json:"language"`
	ReleaseName string             `json:"release_name"`
	MatchedBy   string             `json:"matched_by"`
	SubtitleID  string             `json:"subtitle_id"`
	// Tier is the score's quality-tier label, computed server-side by the
	// scorer (same table as /api/score): the remote CLI renders it and has
	// no scorer of its own.
	Tier       subflux.ScoreTier `json:"tier"`
	Score      int               `json:"score"`
	HearingImp bool              `json:"hearing_impaired"`
	Forced     bool              `json:"forced"`
	OnDisk     bool              `json:"on_disk"`
}

SearchResult is one scored manual-search candidate in the API response.

func BuildSearchResults

func BuildSearchResults(scored []subflux.ScoredResult, refs []subflux.DownloadedRef, sc tierLabeller) []SearchResult

BuildSearchResults converts scored results to API response format. sc supplies the server-computed tier label per score; a nil scorer leaves tiers empty.

Jump to

Keyboard shortcuts

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