media

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package media localises a record set's media: it collects every distinct reference, downloads each through the shared x.Client (so media rides the one rate limiter and cache), picks a video rendition, and maps each item to a deterministic local file. name.go and plan.go are pure (no network); only download.go touches the wire.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	Key    string // media key, or a derived key for avatar/banner
	Type   string // photo|video|gif|avatar|banner
	Source string // the URL to fetch (the picked rendition for video/gif)
	Path   string // repo-relative destination (empty until named)
	AltErr string // when non-empty, why this item cannot be localised (e.g. stream-only)
}

Item is one media reference to fetch and where it will land. The Path is the deterministic repo-relative destination; Kind classifies it for the manifest.

func Plan

func Plan(profile *x.User, tweets []*x.Tweet, policy Policy, video VideoPref) []Item

Plan walks the profile and a record set and returns every distinct media item to localise under the policy, deduped by destination path and ordered deterministically (TP5). Video/gif renditions are picked here; each item's local Path is computed now so the downloader only fetches. Quoted-tweet media and author avatars are included so an embedded card and the author row render offline (spec §8).

type Logf

type Logf func(format string, args ...any)

Logf is the optional progress sink.

type Policy

type Policy string

Policy selects which media a capture localises (spec §8).

const (
	PolicyAll    Policy = "all"    // photos, video, gif, avatars, banners
	PolicyPhotos Policy = "photos" // photos + avatars + banners, no video/gif
	PolicyNone   Policy = "none"   // text-only, download nothing
)

type Result

type Result struct {
	Assets     []repo.Asset
	Downloaded int // newly fetched this run
	Reused     int // already on disk, skipped
	Failed     int // fetch errored, recorded unavailable
	StreamOnly int // no progressive rendition, recorded with master URL
}

Result summarises a localisation pass for the manifest and the progress line.

func Download

func Download(ctx context.Context, c *x.Client, st *repo.Store, items []Item, log Logf) Result

Download localises every planned item through the shared x.Client (TP1), so media rides the one rate limiter, retry/backoff, and disk cache the record reads use. An item already on disk is skipped (incremental, TP6); a fetch failure is recorded as unavailable and never aborts the capture (spec §8).

type VideoPref

type VideoPref string

VideoPref selects a rendition for video and gif.

const (
	VideoBest  VideoPref = "best"
	VideoWorst VideoPref = "worst"
)

Jump to

Keyboard shortcuts

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