videoembed

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Assets embed.FS

Assets - the module's templates/ and static/, built into the binary (modules.Assets, paths.SetModuleAssets): a site runs without the module's source directory.

Functions

func RegisterRoutes

func RegisterRoutes(r modulekit.Mux, store *sessions.CookieStore, c *Controller, admin func(http.Handler) http.Handler)

RegisterRoutes registers the settings page (behind admin) and the editor's check of a link (signed in, rate limited: it may ask a video service).

func Wire

func Wire(d modulekit.Deps) modulekit.Parts

Wire - the module's text filter (the videos in texts, the editor's button) and ways of showing a link field (its videos), the background job asking the services about new links, the settings page and the editor's check of a link; uninstalling removes the previews' copies.

Types

type Controller

type Controller struct {
	*modulekit.BaseController
	// contains filtered or unexported fields
}

Controller - the module's settings page and the editor's check of a link.

func NewController

func NewController(base *modulekit.BaseController, service *Service) *Controller

NewController creates a Controller.

func (*Controller) Resolve

func (c *Controller) Resolve(w http.ResponseWriter, r *http.Request)

Resolve handles GET /api/video-embed?url=: the editor's "Video" button and cards (signed in). The service is asked once; afterwards the answer is the table's.

func (*Controller) SaveSettings

func (c *Controller) SaveSettings(w http.ResponseWriter, r *http.Request)

SaveSettings handles POST /admin/config/video-embed.

func (*Controller) Settings

func (c *Controller) Settings(w http.ResponseWriter, r *http.Request)

Settings renders GET /admin/config/video-embed: the services, the preview and the player's loading.

type Embed

type Embed struct {
	URL           string
	Provider      string
	Title         string
	ThumbnailURL  string
	ThumbnailFile string
	Width         int
	Height        int
	Failed        bool
	FetchedAt     time.Time
}

Embed - what a video's service says about it (oEmbed or Open Graph): Title, the preview (ThumbnailURL - the service's, ThumbnailFile - the site's copy, relative to the public files, "" - none), the player's proportions (0 - unknown); Failed - the service didn't answer (asked again after retryAfter).

type Fetcher

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

Fetcher asks a video's service about it (oEmbed, else its page's Open Graph tags) and copies its preview to the site.

func NewFetcher

func NewFetcher() *Fetcher

NewFetcher creates a Fetcher keeping the previews under the public files' video_embed/.

func (*Fetcher) Fetch

func (f *Fetcher) Fetch(ctx context.Context, m Match, local bool) Embed

Fetch returns what the service says about the video: a failed one when it doesn't answer. With local, the preview is copied to the site.

type Filter

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

Filter turns the video links standing alone in a paragraph into the videos (the module's text filter).

func NewFilter

func NewFilter(service *Service, templates modulekit.TemplateService, logger *slog.Logger) *Filter

NewFilter creates a Filter.

func (*Filter) Apply

func (f *Filter) Apply(ctx context.Context, s string) string

Apply returns s with the video links standing alone in a paragraph made the videos; s itself when it has none.

func (*Filter) FieldFormatters

func (f *Filter) FieldFormatters() []modulekit.FieldFormatter

FieldFormatters - the module's ways of showing a link field (modulekit.AddFieldFormatter): with the services' sites to offer as the field's allowed ones and the content form's preview of a link.

func (*Filter) TextFilter

func (f *Filter) TextFilter() modulekit.TextFilter

TextFilter - the module's text filter, with the editor's "Video" button (modulekit.AddTextFilter).

type Match

type Match struct {
	Provider *Provider
	URL      string
	Player   string
	Width    int
	Height   int
}

Match - a link recognized as a provider's video: URL as written, the player's address (PlayerAutoplay - starting at once), the proportions its link kind fixes (0 - none).

func MatchURL

func MatchURL(link string, on map[string]bool) (Match, bool)

MatchURL recognizes link as a video of one of the providers on (on - by name); false - not a video link of theirs.

func (Match) PlayerAutoplay

func (m Match) PlayerAutoplay() string

PlayerAutoplay - the player's address starting the video at once (a click on the preview asked for it).

func (Match) Portrait

func (m Match) Portrait() bool

Portrait - whether the link's kind fixes vertical videos.

type Provider

type Provider struct {
	Name           string        `json:"name"`
	Label          string        `json:"label"`
	Hosts          string        `json:"hosts"`
	Sites          []string      `json:"sites"`
	On             bool          `json:"on"`
	URLs           []providerURL `json:"urls"`
	Player         string        `json:"player"`
	Autoplay       string        `json:"autoplay"`
	OEmbed         string        `json:"oembed"`
	OpenGraph      bool          `json:"opengraph"`
	ThumbnailHosts []string      `json:"thumbnail_hosts"`
}

Provider - a video service (providers.json): Name - its machine name (the settings' list), Label, Hosts - what the settings page shows; Sites - the hosts of its links (a link field's allowed sites); On - on unless the settings say otherwise; URLs - the links to its videos; Player - the player's address, {id}/{oid} from the link; Autoplay - the query parameter starting it at once (after a click); OEmbed - the address of its oEmbed answer ({url} - the link), or OpenGraph - the video's page's Open Graph tags instead; ThumbnailHosts - the hosts (and their subdomains) its previews may come from.

type Repo

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

Repo - the module's tables.

func NewRepo

func NewRepo(db *sql.DB) *Repo

NewRepo creates a Repo on db, in the repositories' dialect.

func (*Repo) Embeds

func (r *Repo) Embeds(ctx context.Context, links []string) (map[string]Embed, error)

Embeds returns what's known about the links, by link (a link not asked about yet - absent).

func (*Repo) SaveEmbed

func (r *Repo) SaveEmbed(ctx context.Context, e Embed) error

SaveEmbed stores what the service said about the link (replacing what was known).

func (*Repo) SaveSettings

func (r *Repo) SaveSettings(ctx context.Context, s Settings) error

SaveSettings saves the module's settings.

func (*Repo) Settings

func (r *Repo) Settings(ctx context.Context) (Settings, error)

Settings returns the module's settings (the defaults until saved).

type Service

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

Service knows the videos linked in texts: what's known in memory (a text is shown often), from the table otherwise; a link not known yet waits for the background job (FetchPending), the editor's "Video" button asks at once (Resolve).

func NewService

func NewService(repo *Repo, fetcher *Fetcher, logger *slog.Logger) *Service

NewService creates a Service.

func (*Service) Embeds

func (s *Service) Embeds(ctx context.Context, matches []Match) map[string]Embed

Embeds returns what's known about the matched links; one not known (or failed long enough ago) is queued for FetchPending.

func (*Service) FetchPending

func (s *Service) FetchPending(ctx context.Context) error

FetchPending asks the services about the links waiting (up to fetchPerRun at a time) - the module's background job.

func (*Service) Resolve

func (s *Service) Resolve(ctx context.Context, m Match) (Embed, error)

Resolve asks the service about the link now (the editor's button) and keeps the answer.

func (*Service) SaveSettings

func (s *Service) SaveSettings(ctx context.Context, st Settings) error

SaveSettings saves the settings.

func (*Service) Settings

func (s *Service) Settings(ctx context.Context) Settings

Settings returns the module's settings (kept in memory once read).

type Settings

type Settings struct {
	Providers     []string
	ClickToPlay   bool
	LocalPreviews bool
}

Settings - the module's settings: Providers - the services on, by name; ClickToPlay - a preview first, the player on a click; LocalPreviews - the previews are the site's copies.

func (Settings) On

func (s Settings) On() map[string]bool

On - the providers on, by name.

Directories

Path Synopsis
ent
Package ent - the video embed module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
Package ent - the video embed module's own ent schema (schema/), its generated client (generated/, go generate) and migration files (migrations/<dialect>/, scripts/migrations_gen.sh writes them), apart from the core's: the module's set of migrations (Schema).
schema
Package schema - the video embed module's own ent schema: what the video services say about the videos linked in texts, and the module's settings.
Package schema - the video embed module's own ent schema: what the video services say about the videos linked in texts, and the module's settings.
Package manifest declares the video embed module (its registry entry): a link to a video on its own line in a text shows as the video's player.
Package manifest declares the video embed module (its registry entry): a link to a video on its own line in a text shows as the video's player.

Jump to

Keyboard shortcuts

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