mediaproxy

Build your own source

A source is a small Go program. Describe your catalogue, return playable streams, and the server handles matching, artwork, users and every app.

  1. 1

    Write it

    Implement six methods with the SDK: describe, list categories, list items, details, search and resolve playback.

  2. 2

    Test it

    plugintest runs the acceptance suite against the real site until it prints ALL PASS.

  3. 3

    Publish it

    mprepo signs a repository you can host on GitHub Pages, S3 or any web server.

Download the example

A complete source plugin for public-domain films from the Internet Archive. It passes the plugintest acceptance suite against the live site.

Tested with plugintest: ALL PASS

Build it with your AI coding agent

Give Claude Code, Codex or any coding agent our plugin skill. It knows the contract, the rules and the test loop, and it doesn't stop until plugintest prints ALL PASS.

Paste this into your agent, inside a checkout of mediaproxy2:

Read /downloads/mediaproxy-plugin-skill/SKILL.md and follow it to build a MediaProxy plugin for <your source>.

To install it permanently, unzip the folder into your agent's skills directory, for Claude Code ~/.claude/skills/.

Kinds of plugins

Every plugin is a Go binary that the server starts as its own process. What it does decides how it is served and where it appears in the web admin.

How the server runs a plugin

  1. 1

    Start

    The server launches the binary and both sides check the handshake (protocol version 1). From then on they talk gRPC.

  2. 2

    Describe

    The server reads Manifest and renders the settings form in the web admin from ConfigSchema.

  3. 3

    Configure

    Saved settings and the host services arrive in Configure. The Test button calls TestConnection.

  4. 4

    Sync

    On a schedule the server calls ListCategories, pages through ListItems and GetDetails, stores everything and matches titles to TMDB.

  5. 5

    Play

    When someone presses play, the server calls ResolvePlayback and streams the result to the app.

The interface

A content source implements sdk.Provider. The types are the generated protobuf messages, so plugin and server share one vocabulary.

type Provider interface {
	Manifest() *pluginv1.Manifest
	// Configure receives the operator's values for the fields declared in
	// Manifest().ConfigSchema plus the Host services to use for HTTP/state.
	Configure(ctx context.Context, values map[string]string, host *Host) error
	TestConnection(ctx context.Context) error

	ListCategories(ctx context.Context) ([]*pluginv1.Category, error)
	ListItems(ctx context.Context, categoryKey, cursor string, limit int) (*pluginv1.ItemPage, error)
	GetDetails(ctx context.Context, extID string) (*pluginv1.Details, error)
	Search(ctx context.Context, query string, limit int) (*pluginv1.ItemPage, error)

	ResolvePlayback(ctx context.Context, extID string, maxHeight int) (*pluginv1.Playback, error)
}

func main() { sdk.Serve(&MySource{}) }

Optional

Implement any of these as well and declare them in Capabilities:

The manifest

Manifest tells the server who the plugin is, what it can do and what it may reach. Main fields:

Id
Lowercase slug, unique across all plugin kinds.
Name, Version, Description, Homepage
Shown in the web admin and in repositories.
Capabilities
What you implement: catalog, search, details, live, epg, now_playing, download and more.
Constraints
needs_exit for geo-locked content, ip_bound and url_ttl_seconds for short-lived URLs, complete_catalog to let the server remove titles that disappeared.
ConfigSchema
The settings form: text, secret, int, bool, select, url, textarea, folders and exit lists.
Permissions
The hostnames the plugin may fetch, whether it may reach the LAN, and which folders it may use.
Countries, Languages
Used by the country and language filters in repositories.
Content
catalog (films and series, matched to TMDB), clips, live or music.
SearchKinds
What Search returns: movies, series, music or live.
DefaultExit
The exit country you suggest. The operator decides.

Items and playback

pluginv1.ItemFill in everything the site gives you. The more an Item says, the better the match and the richer the apps.

ExtId
Your own stable id for the item.
Type
SHOW, MOVIE, EPISODE or LIVESTREAM.
Title, OriginalTitle, Description
As the site states them.
Image, Backdrop, Logo
Artwork as ImageRef: a URL with optional headers.
Year, AirDate, DurationSeconds
Used for TMDB matching and sorting.
ParentExtId, Season, Episode
How episodes belong to a show.
ExternalIds
TMDB or IMDb ids when the site has them.
AudioLangs, SubtitleLangs, Genres, AgeRating
Shown in the apps and used by filters.
Section
movies, series, documentaries, shows, news, sport, kids or culture.

pluginv1.PlaybackResolvePlayback returns a Playback:

Locator
Scheme (HLS, DASH, MP4, MP3, ICY) and the URL to play.
Headers
Headers the CDN needs for the manifest and segments.
Live
True for live channels and radio.
TtlSeconds, IpBound
How long the URL stays valid and whether it only plays from the resolving IP.
AudioTracks, Subtitles, Variants
Extra tracks and qualities when the site lists them.
UnavailableReason
Set instead of a locator when an item cannot be played, with a reason the apps show.

What the server gives your plugin

  • HTTP through the host

    Every request leaves through the exit the operator chose for your source.

  • Storage

    A key-value store for sessions and tokens that survives restarts.

  • Media tools

    ffmpeg, ffprobe and yt-dlp, kept up to date by the server.

  • Guardrails

    A network allowlist from your manifest, no LAN access unless declared, and a memory limit.

type Host struct {
	HTTP      *http.Client // every request leaves through the operator's exit
	Stream    *http.Client // the same, for big bodies with no size cap
	State     State        // persistent key/value store for this plugin
	Media     Media        // ffmpeg, ffprobe and yt-dlp
	Music     Music        // covers, artist photos and tracks
	Lists     Lists        // feeds of the enabled "lists" plugins
	Solver    Solver       // pages behind a browser challenge
	// … see pkg/sdk/host.go
}

The complete example

Every line of the downloadable plugin. It lists two rows, pages with a cursor, searches live and resolves the best MP4.

Example with README (.zip)
// Archive Films: a complete example MediaProxy source plugin.
//
// It lists public-domain feature films from the Internet Archive
// (archive.org), searches them, and resolves each one to a playable MP4.
// Everything here is the real plugin contract: build it inside the
// mediaproxy2 repository and drop the binary into the plugin folder.
//
//	mkdir -p cmd/plugins/archivefilms && cp main.go cmd/plugins/archivefilms/
//	go build -o bin/plugins/archivefilms ./cmd/plugins/archivefilms
//	./bin/plugintest -plugin bin/plugins/archivefilms validate
package main

import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"net/http"
	"net/url"
	"strconv"
	"strings"
	"sync"

	pluginv1 "mediaproxy2/pkg/pluginv1"
	"mediaproxy2/pkg/sdk"
)

const (
	searchURL = "https://archive.org/advancedsearch.php"
	pageSize  = 50
)

// ArchiveFilms implements sdk.Provider.
type ArchiveFilms struct {
	mu         sync.Mutex
	host       *sdk.Host
	collection string
}

// Manifest describes the plugin to the host: identity, what it can do,
// which hosts it may reach, and the settings form shown in the web admin.
func (a *ArchiveFilms) Manifest() *pluginv1.Manifest {
	return &pluginv1.Manifest{
		Id:          "archivefilms",
		Name:        "Archive Films",
		Version:     "1.0.0",
		Description: "Public-domain feature films from the Internet Archive.",
		Homepage:    "https://archive.org/details/feature_films",
		Capabilities: &pluginv1.Capabilities{
			Catalog: true, // ListCategories + ListItems
			Search:  true, // Search
			Details: true, // GetDetails
		},
		Constraints: &pluginv1.Constraints{
			CompleteCatalog: false, // we page through a slice, not everything
		},
		// The host only lets the plugin fetch these hostnames.
		Permissions: &pluginv1.Permissions{Net: []string{"archive.org", "*.archive.org"}},
		Countries:   []string{"global"},
		Languages:   []string{"en"},
		ConfigSchema: []*pluginv1.ConfigField{{
			Key:     "collection",
			Label:   "Collection",
			Type:    pluginv1.ConfigField_TEXT,
			Default: "feature_films",
			Help:    "Which archive.org collection to list, for example feature_films or silent_films.",
		}},
	}
}

// Configure receives the operator's settings and the host services.
// All HTTP must go through host.HTTP so it leaves via the operator's exit.
func (a *ArchiveFilms) Configure(_ context.Context, values map[string]string, host *sdk.Host) error {
	a.mu.Lock()
	defer a.mu.Unlock()
	a.host = host
	a.collection = strings.TrimSpace(values["collection"])
	if a.collection == "" {
		a.collection = "feature_films"
	}
	return nil
}

// TestConnection drives the Test button in the web admin.
func (a *ArchiveFilms) TestConnection(ctx context.Context) error {
	_, err := a.search(ctx, a.query(""), 1, 1)
	return err
}

// ListCategories returns the rows this source offers.
func (a *ArchiveFilms) ListCategories(context.Context) ([]*pluginv1.Category, error) {
	return []*pluginv1.Category{
		{Key: "popular", Name: "Most watched", Sort: 0, Section: sdk.SectionMovies},
		{Key: "recent", Name: "Recently added", Sort: 1, Section: sdk.SectionMovies},
	}, nil
}

// ListItems pages through one category. The cursor is ours to define:
// here it is the next archive.org page number.
func (a *ArchiveFilms) ListItems(ctx context.Context, categoryKey, cursor string, limit int) (*pluginv1.ItemPage, error) {
	page, _ := strconv.Atoi(cursor)
	if page < 1 {
		page = 1
	}
	if limit <= 0 || limit > pageSize {
		limit = pageSize
	}
	sort := "downloads desc"
	if categoryKey == "recent" {
		sort = "addeddate desc"
	}
	docs, err := a.searchSorted(ctx, a.query(""), sort, page, limit)
	if err != nil {
		return nil, err
	}
	out := &pluginv1.ItemPage{}
	for _, d := range docs {
		out.Items = append(out.Items, d.item(categoryKey))
	}
	if len(docs) == limit && page < 4 { // keep the example catalogue small
		out.NextCursor = strconv.Itoa(page + 1)
	}
	return out, nil
}

// GetDetails returns one title. Films have no episodes, so Episodes stays empty.
func (a *ArchiveFilms) GetDetails(ctx context.Context, extID string) (*pluginv1.Details, error) {
	docs, err := a.search(ctx, "identifier:"+quote(extID), 1, 1)
	if err != nil {
		return nil, err
	}
	if len(docs) == 0 {
		return nil, fmt.Errorf("%s: not found", extID)
	}
	return &pluginv1.Details{Item: docs[0].item("")}, nil
}

// Search answers the app's search box live.
func (a *ArchiveFilms) Search(ctx context.Context, query string, limit int) (*pluginv1.ItemPage, error) {
	if limit <= 0 || limit > pageSize {
		limit = pageSize
	}
	docs, err := a.search(ctx, a.query(query), 1, limit)
	if err != nil {
		return nil, err
	}
	out := &pluginv1.ItemPage{}
	for _, d := range docs {
		out.Items = append(out.Items, d.item(""))
	}
	return out, nil
}

// ResolvePlayback turns an item into something playable: here the best
// MP4 file of the archive.org item. The host proxies it to every app.
func (a *ArchiveFilms) ResolvePlayback(ctx context.Context, extID string, maxHeight int) (*pluginv1.Playback, error) {
	var meta struct {
		Files []struct {
			Name   string `json:"name"`
			Format string `json:"format"`
			Height string `json:"height"`
		} `json:"files"`
	}
	if err := a.getJSON(ctx, "https://archive.org/metadata/"+url.PathEscape(extID), &meta); err != nil {
		return nil, err
	}
	best, bestHeight := "", 0
	for _, f := range meta.Files {
		if !strings.HasSuffix(strings.ToLower(f.Name), ".mp4") {
			continue
		}
		h, _ := strconv.Atoi(f.Height)
		if maxHeight > 0 && h > maxHeight {
			continue
		}
		if best == "" || h > bestHeight {
			best, bestHeight = f.Name, h
		}
	}
	if best == "" {
		// A described outcome, not an error: the apps show the reason.
		return &pluginv1.Playback{UnavailableReason: "This item has no MP4 file."}, nil
	}
	return &pluginv1.Playback{
		Locator: &pluginv1.Locator{
			Scheme: pluginv1.Scheme_MP4,
			Url:    "https://archive.org/download/" + url.PathEscape(extID) + "/" + url.PathEscape(best),
		},
		Height: uint32(bestHeight),
		Lang:   "en",
	}, nil
}

// --- archive.org helpers -------------------------------------------------

type doc struct {
	Identifier  string `json:"identifier"`
	Title       string `json:"title"`
	Description any    `json:"description"` // a string or a list of strings
	Year        any    `json:"year"`
}

func (d doc) item(category string) *pluginv1.Item {
	year, _ := strconv.Atoi(fmt.Sprint(d.Year))
	return &pluginv1.Item{
		ExtId:       d.Identifier,
		Type:        pluginv1.ItemType_MOVIE,
		Title:       d.Title,
		Description: text(d.Description),
		Year:        int32(year),
		CategoryKey: category,
		Image:       &pluginv1.ImageRef{Url: "https://archive.org/services/img/" + d.Identifier},
		WebUrl:      "https://archive.org/details/" + d.Identifier,
		Lang:        "en",
	}
}

func (a *ArchiveFilms) query(words string) string {
	a.mu.Lock()
	q := "collection:" + quote(a.collection) + " AND mediatype:movies"
	a.mu.Unlock()
	if words = strings.TrimSpace(words); words != "" {
		q += " AND title:(" + words + ")"
	}
	return q
}

func (a *ArchiveFilms) search(ctx context.Context, q string, page, rows int) ([]doc, error) {
	return a.searchSorted(ctx, q, "downloads desc", page, rows)
}

func (a *ArchiveFilms) searchSorted(ctx context.Context, q, sort string, page, rows int) ([]doc, error) {
	v := url.Values{}
	v.Set("q", q)
	for _, f := range []string{"identifier", "title", "description", "year"} {
		v.Add("fl[]", f)
	}
	v.Set("sort[]", sort)
	v.Set("rows", strconv.Itoa(rows))
	v.Set("page", strconv.Itoa(page))
	v.Set("output", "json")
	var res struct {
		Response struct {
			Docs []doc `json:"docs"`
		} `json:"response"`
	}
	if err := a.getJSON(ctx, searchURL+"?"+v.Encode(), &res); err != nil {
		return nil, err
	}
	return res.Response.Docs, nil
}

func (a *ArchiveFilms) getJSON(ctx context.Context, u string, into any) error {
	a.mu.Lock()
	host := a.host
	a.mu.Unlock()
	if host == nil {
		return errors.New("not configured")
	}
	req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
	if err != nil {
		return err
	}
	resp, err := host.HTTP.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("archive.org answered %s", resp.Status)
	}
	return json.NewDecoder(resp.Body).Decode(into)
}

func quote(s string) string { return `"` + strings.ReplaceAll(s, `"`, ``) + `"` }

func text(v any) string {
	switch t := v.(type) {
	case string:
		return t
	case []any:
		if len(t) > 0 {
			return fmt.Sprint(t[0])
		}
	}
	return ""
}

func main() { sdk.Serve(&ArchiveFilms{}) }

Test against the real site

plugintest describes, lists, searches and resolves streams. validate is the acceptance suite: at least one category, valid items everywhere, details for two shows and three working playback probes.

go build -o bin/plugintest ./cmd/plugintest
./bin/plugintest -plugin bin/plugins/archivefilms validate

[PASS] manifest                 archivefilms v1.0.0
[PASS] test_connection          ok
[PASS] categories               2 categories
[PASS] items:popular            50 items, 0 invalid
[PASS] items:recent             50 items, 0 invalid
[PASS] resolve:sex_madness      media bytes (video/mp4) (MP4)
ALL PASS

Publish a signed repository

mprepo creates your signing key, adds builds for each platform and checks the folder. Upload it to GitHub Pages, S3 or any web server and share the URL.

go build -o mprepo ./cmd/mprepo
./mprepo keygen -key repo.key
GOOS=linux GOARCH=arm64 go build -o bin/linux_arm64/archivefilms ./cmd/plugins/archivefilms
./mprepo add -key repo.key -repo ./repo -platform linux/arm64 \
  -id archivefilms -version 1.0.0 bin/linux_arm64/archivefilms
./mprepo verify -repo ./repo

The full plugin guide covers settings forms, user accounts, programme guides, music, podcasts and the scraping rules we learned the hard way.