Documentation
¶
Overview ¶
Package service owns shared artwork authorization, selection and rendering.
Index ¶
- Constants
- Variables
- func RenderUltraBlur(colors Palette, transform frontend.ArtworkTransform) ([]byte, string, error)
- func TMDBSize(w int) string
- func Transform(data []byte, contentType string, transform frontend.ArtworkTransform) ([]byte, string, error)
- type CollectionArt
- type LibraryCollageCache
- type MetadataQueue
- type Palette
- type PaletteCache
- type PaletteWant
- type Queue
- type RemoteCache
- type RemoteImage
- type Source
- func (s Source) ArtPath(ctx context.Context, req frontend.ArtworkRequest, element string) (path string, defWidth int, err error)
- func (a *Source) BindMetadata(q *MetadataQueue)
- func (a Source) ChannelImage(viewer *core.Viewer, channel livetv.Channel) frontend.Image
- func (a Source) LibraryCollage(ctx context.Context, viewer *core.User, _ core.Device, viewID string, ...) (frontend.Image, error)
- func (a Source) List(ctx context.Context, req frontend.ArtworkRequest) ([]frontend.Image, bool, error)
- func (a Source) ListPage(ctx context.Context, viewer *core.Viewer, device core.Device, ...) (map[core.RatingKey][]frontend.Image, error)
- func (a Source) PersonImages(ctx context.Context, req frontend.ArtworkRequest, title core.Title) ([]frontend.Image, error)
- func (a Source) Read(ctx context.Context, req frontend.ArtworkRequest, img frontend.Image, ...) ([]byte, string, error)
- func (a *Source) StoreMetadata(ctx context.Context, viewer *core.User, titles []core.Title) error
- func (a Source) Warm(title core.Title, device core.Device)
- type VariantsQueue
Constants ¶
const (
MaxImageBytes = 15 << 20
)
Variables ¶
var ErrRemoteImageNotFound = errors.New("image not found")
Functions ¶
func RenderUltraBlur ¶
renderUltraBlur paints the same four colours Plex provides to its clients. Palette selection itself stays in the shared UltraBlur cache and pipeline.
Types ¶
type CollectionArt ¶
type CollectionArt interface {
CollectionArtwork(context.Context, *core.User, core.RatingKey, string, int) ([]byte, string, bool, error)
}
CollectionArt is generated collection artwork. Smart-collection UltraBlur colours come from that image when it exists.
type LibraryCollageCache ¶
type LibraryCollageCache struct {
Dir string
// contains filtered or unexported fields
}
LibraryCollageCache stores generated library-view JPEGs. The file name is the identity of the view and the child posters, so a content change stops serving the previous image.
type MetadataQueue ¶
type MetadataQueue struct {
// contains filtered or unexported fields
}
MetadataQueue joins stored width, height, and hash rows on the request. Missing descriptors are hashed by the background worker. A caller with a deadline may wait for a hash already in flight, and never longer than artworkInflightWait.
func NewMetadataQueue ¶
func (*MetadataQueue) Get ¶
func (q *MetadataQueue) Get(ctx context.Context, req frontend.ArtworkRequest, img frontend.Image) frontend.Image
func (*MetadataQueue) Wait ¶
func (q *MetadataQueue) Wait()
Wait joins workers after the owning context is cancelled.
type Palette ¶
type Palette struct{ TopLeft, TopRight, BottomLeft, BottomRight string }
Palette holds neutral image corner colours, without protocol serialization flags.
func ComputeItemPalette ¶
func ComputeItemPalette(ctx context.Context, cache *RemoteCache, imageURL core.ImageURLFunc, key core.RatingKey, path string, now time.Time, art CollectionArt) (Palette, error)
ComputeItemPalette derives UltraBlur colours for one catalogue item. A smart collection uses its generated art (custom collection art) when the lookup returns bytes; every other item uses the backdrop path.
func ComputePalette ¶
func ComputePalette(ctx context.Context, cache *RemoteCache, imageURL core.ImageURLFunc, path string, now time.Time) (Palette, error)
ComputePalette fetches a backdrop's small variant through the artwork cache and derives its corner colours.
type PaletteCache ¶
type PaletteCache struct {
// contains filtered or unexported fields
}
func NewPaletteCache ¶
func (*PaletteCache) Lookup ¶
func (c *PaletteCache) Lookup(key core.RatingKey, path string) *Palette
lookup returns the colours of key's backdrop path, or nil when they are not known yet (scheduling their computation).
func (*PaletteCache) Preload ¶
func (c *PaletteCache) Preload(ctx context.Context, wants []PaletteWant)
preload fills the memory cache from the database for items it doesn't hold yet, in one query, so a restart doesn't recompute anything and a listing's first render already has colours computed earlier.
type PaletteWant ¶
ultraBlurWant is one item a listing is about to render.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue runs keyed background jobs on a fixed set of workers. A key that is already queued or running is not queued again, and jobs that don't fit the queue are dropped (the caller simply asks again on a later request), so a burst of listings can never pile up unbounded work or block a response.
type RemoteCache ¶
type RemoteCache struct {
// contains filtered or unexported fields
}
func NewRemoteCache ¶
func NewRemoteCache(budget int64, client *http.Client) *RemoteCache
func (*RemoteCache) Get ¶
func (c *RemoteCache) Get(ctx context.Context, u string, now time.Time) (*RemoteImage, error)
get returns the image at u, fetching it once for concurrent callers.
func (*RemoteCache) RasterFormat ¶
func (c *RemoteCache) RasterFormat(ctx context.Context, data []byte, contentType, format string, now time.Time) ([]byte, string, error)
RasterFormat caches explicit output formats alongside fetched artwork, within the same byte budget. Callers must authorize the source before calling it. The content digest identifies the actual source variant (including its pixel size), so refreshed bytes and different sizes cannot reuse stale conversions. Returning to a warm poster requires a hash/lookup, never a pixel decode.
type RemoteImage ¶
type Source ¶
type Source struct {
Catalog core.StoredTitleLookup
CollectionDevice string
Collections core.Collections
Playlists core.Playlists
Visibility experience.Visibility
LiveTV interface {
AllowedChannels(context.Context, *core.User) ([]livetv.Channel, error)
}
Discovery *discovery.Features
Images *RemoteCache
ImageURL core.ImageURLFunc
Palettes *PaletteCache
Now func() time.Time
Variants func(*core.Title, string) (*tmdb.Images, bool)
Metadata func(context.Context, frontend.ArtworkRequest, frontend.Image) frontend.Image
VirtualSeason func(context.Context, *core.User, core.RatingKey) (*core.Title, error)
URLImages interface {
GetUntrustedURL(context.Context, string) ([]byte, string, error)
}
Raster *artwork.SVGRasterizer
Collages *LibraryCollageCache
// contains filtered or unexported fields
}
Source has no protocol server or protocol wire model dependencies.
func (*Source) BindMetadata ¶
func (a *Source) BindMetadata(q *MetadataQueue)
BindMetadata keeps the queue so fixture ingest can store hashes before a page is served.
func (Source) ChannelImage ¶
ChannelImage describes a channel already filtered through AllowedChannels. The reference is not an authorization credential; List rechecks policy.
func (Source) LibraryCollage ¶
func (a Source) LibraryCollage(ctx context.Context, viewer *core.User, _ core.Device, viewID string, children []core.Title) (frontend.Image, error)
LibraryCollage builds a square tile of the first few visible child posters. It is a generated image, not one child's poster. An empty selection is an error.
func (Source) ListPage ¶
func (a Source) ListPage(ctx context.Context, viewer *core.Viewer, device core.Device, titles []core.Title) (map[core.RatingKey][]frontend.Image, error)
ListPage lists artwork for titles already loaded by the caller. Overlay settings and saved variants are read once for the page.
func (Source) PersonImages ¶
func (a Source) PersonImages(ctx context.Context, req frontend.ArtworkRequest, title core.Title) ([]frontend.Image, error)
PersonImages consumes an already-authorized detached title. It deliberately bypasses StoredTitle and all variant/metadata queues.
func (Source) Read ¶
func (a Source) Read(ctx context.Context, req frontend.ArtworkRequest, img frontend.Image, transform frontend.ArtworkTransform) ([]byte, string, error)
Read re-enumerates under current policy and descriptors before touching bytes.
func (*Source) StoreMetadata ¶
StoreMetadata hashes each title's images and waits until those rows are stored. A later page joins the rows and does not wait on the hash.
type VariantsQueue ¶
type VariantsQueue struct {
// contains filtered or unexported fields
}
VariantsQueue keeps item enrichment cache-only. Bounded workers fills missing TMDB responses and coalesces concurrent requests per item and language. It stops when the frontend runtime's context is cancelled.
func NewVariantsQueue ¶
func (*VariantsQueue) Wait ¶
func (q *VariantsQueue) Wait()
Wait joins workers after the owning context is cancelled.