media

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package media provides a single entry point for obtaining media content. All consumers — Telegram direct messages, Telegram inline queries and the gRPC API — go through Loader so that source-specific download requirements (e.g. TikTok's mandatory cookies + referer headers) live in one place.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Content

type Content struct {
	Body          io.ReadCloser
	ContentLength int64
}

Content is a readable media stream with metadata.

type Loader

type Loader interface {
	// DirectURL reports a URL that any HTTP client can fetch without special
	// headers — suitable to hand to Telegram inline results or API clients.
	// ok is false when the item can only be obtained by downloading it via Open
	// (e.g. TikTok, whose CDN requires cookies + referer).
	DirectURL(item *models.MediaItem) (url string, ok bool)

	// Open streams the item's content, applying any required download headers.
	// The caller must close Content.Body.
	Open(ctx context.Context, item *models.MediaItem) (*Content, error)

	// ContentLength reports the item's size in bytes via a HEAD request, applying
	// any required download headers. Returns -1 when the source does not report a
	// size. Lets callers decide on the size without downloading the body (e.g.
	// inline queries that must offer a download link for files over Telegram's
	// upload limit).
	ContentLength(ctx context.Context, item *models.MediaItem) (int64, error)
}

Loader is the unified media-loading interface.

func Default

func Default() Loader

Default returns the process-wide loader.

func NewHTTPLoader

func NewHTTPLoader() Loader

NewHTTPLoader creates the default HTTP-based loader.

Jump to

Keyboard shortcuts

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