media

package
v0.0.0-...-0bda71a Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultImageProcessor

type DefaultImageProcessor struct{}

DefaultImageProcessor implements ImageProcessor using standard libraries

func NewDefaultImageProcessor

func NewDefaultImageProcessor() *DefaultImageProcessor

NewDefaultImageProcessor creates a new image processor

func (*DefaultImageProcessor) CreateThumbnail

func (p *DefaultImageProcessor) CreateThumbnail(sourcePath, outputPath string, maxWidth, maxHeight int) error

CreateThumbnail creates a thumbnail from an image file

func (*DefaultImageProcessor) DecodeImage

func (p *DefaultImageProcessor) DecodeImage(r io.Reader) (image.Image, string, error)

DecodeImage decodes an image from a reader and returns the image and format

func (*DefaultImageProcessor) EncodeImage

func (p *DefaultImageProcessor) EncodeImage(w io.Writer, img image.Image, format string) error

EncodeImage encodes an image to the specified format

func (*DefaultImageProcessor) ResizeImage

func (p *DefaultImageProcessor) ResizeImage(src image.Image, width, height uint) image.Image

ResizeImage resizes an image to the specified dimensions while maintaining aspect ratio

type DefaultMediaDetector

type DefaultMediaDetector struct{}

DefaultMediaDetector implements MediaDetector using file analysis

func NewDefaultMediaDetector

func NewDefaultMediaDetector() *DefaultMediaDetector

NewDefaultMediaDetector creates a new media detector

func (*DefaultMediaDetector) DetectMediaType

func (d *DefaultMediaDetector) DetectMediaType(filePath string) (MediaType, error)

DetectMediaType determines the media type from file extension and content

func (*DefaultMediaDetector) GetMediaInfo

func (d *DefaultMediaDetector) GetMediaInfo(filePath string) (*MediaInfo, error)

GetMediaInfo extracts comprehensive information about a media file

func (*DefaultMediaDetector) IsSupported

func (d *DefaultMediaDetector) IsSupported(filePath string) bool

IsSupported checks if the file type is supported for preview

type DefaultThumbnailGenerator

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

DefaultThumbnailGenerator implements ThumbnailGenerator with file-based caching

func NewDefaultThumbnailGenerator

func NewDefaultThumbnailGenerator(cacheDir string, processor ImageProcessor) *DefaultThumbnailGenerator

NewDefaultThumbnailGenerator creates a new thumbnail generator

func (*DefaultThumbnailGenerator) ClearCache

func (g *DefaultThumbnailGenerator) ClearCache() error

ClearCache removes all cached thumbnails

func (*DefaultThumbnailGenerator) GenerateThumbnail

func (g *DefaultThumbnailGenerator) GenerateThumbnail(filePath string, maxWidth, maxHeight int) (string, error)

GenerateThumbnail creates a thumbnail for the given file and returns the thumbnail path

func (*DefaultThumbnailGenerator) GenerateVideoThumbnail

func (g *DefaultThumbnailGenerator) GenerateVideoThumbnail(filePath string, maxWidth, maxHeight int) (string, error)

GenerateVideoThumbnail creates a thumbnail for video files

func (*DefaultThumbnailGenerator) GetCachedThumbnail

func (g *DefaultThumbnailGenerator) GetCachedThumbnail(filePath string, maxWidth, maxHeight int) (string, bool)

GetCachedThumbnail returns the cached thumbnail path if it exists

type ImageProcessor

type ImageProcessor interface {
	// ResizeImage resizes an image to the specified dimensions
	ResizeImage(src image.Image, width, height uint) image.Image

	// DecodeImage decodes an image from a reader
	DecodeImage(r io.Reader) (image.Image, string, error)

	// EncodeImage encodes an image to the specified format
	EncodeImage(w io.Writer, img image.Image, format string) error

	// CreateThumbnail creates a thumbnail from an image file
	CreateThumbnail(sourcePath, outputPath string, maxWidth, maxHeight int) error
}

ImageProcessor processes images for thumbnails and previews

type Manager

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

Manager coordinates all media-related operations

func NewManager

func NewManager(cacheDir string) *Manager

NewManager creates a new media manager with all components

func (*Manager) Cleanup

func (m *Manager) Cleanup() error

Cleanup removes cached thumbnails

func (*Manager) GenerateThumbnail

func (m *Manager) GenerateThumbnail(filePath string, maxWidth, maxHeight int) (string, error)

GenerateThumbnail creates a thumbnail for a media file

func (*Manager) GetCacheDir

func (m *Manager) GetCacheDir() string

GetCacheDir returns the cache directory path

func (*Manager) GetMediaInfo

func (m *Manager) GetMediaInfo(filePath string) (*MediaInfo, error)

GetMediaInfo returns information about a media file

func (*Manager) GetMediaTypeString

func (m *Manager) GetMediaTypeString(filePath string) string

GetMediaTypeString returns a human-readable media type string

func (*Manager) GetSupportedImageFormats

func (m *Manager) GetSupportedImageFormats() []string

GetSupportedImageFormats returns a list of supported image formats

func (*Manager) GetSupportedVideoFormats

func (m *Manager) GetSupportedVideoFormats() []string

GetSupportedVideoFormats returns a list of supported video formats

func (*Manager) GetThumbnailPath

func (m *Manager) GetThumbnailPath(filePath string, maxWidth, maxHeight int) (string, bool)

GetThumbnailPath returns the thumbnail path for a file

func (*Manager) IsImageFile

func (m *Manager) IsImageFile(filePath string) bool

IsImageFile checks if the file is an image

func (*Manager) IsMediaFile

func (m *Manager) IsMediaFile(filePath string) bool

IsMediaFile checks if the file is a supported media type

func (*Manager) IsVideoFile

func (m *Manager) IsVideoFile(filePath string) bool

IsVideoFile checks if the file is a video

func (*Manager) SetCacheDir

func (m *Manager) SetCacheDir(cacheDir string)

SetCacheDir updates the cache directory (useful for configuration changes)

func (*Manager) ValidateFile

func (m *Manager) ValidateFile(filePath string) error

ValidateFile checks if a file exists and is accessible

type ManagerInterface

type ManagerInterface interface {
	// GetMediaInfo returns information about a media file
	GetMediaInfo(filePath string) (*MediaInfo, error)

	// GenerateThumbnail creates a thumbnail for a media file
	GenerateThumbnail(filePath string, maxWidth, maxHeight int) (string, error)

	// IsMediaFile checks if the file is a supported media type
	IsMediaFile(filePath string) bool

	// GetThumbnailPath returns the thumbnail path for a file
	GetThumbnailPath(filePath string, maxWidth, maxHeight int) (string, bool)

	// Cleanup removes cached thumbnails
	Cleanup() error
}

ManagerInterface defines the public interface for the media manager

type MediaDetector

type MediaDetector interface {
	// DetectMediaType determines the media type from file extension and content
	DetectMediaType(filePath string) (MediaType, error)

	// GetMediaInfo extracts comprehensive information about a media file
	GetMediaInfo(filePath string) (*MediaInfo, error)

	// IsSupported checks if the file type is supported for preview
	IsSupported(filePath string) bool
}

MediaDetector detects media file types and properties

type MediaInfo

type MediaInfo struct {
	Type          MediaType `json:"type"`
	Width         int       `json:"width,omitempty"`
	Height        int       `json:"height,omitempty"`
	Duration      int       `json:"duration,omitempty"` // in seconds for video/audio
	Size          int64     `json:"size"`               // file size in bytes
	MimeType      string    `json:"mime_type"`
	ThumbnailPath string    `json:"thumbnail_path,omitempty"`
}

MediaInfo contains information about a media file

type MediaType

type MediaType int

MediaType represents the type of media file

const (
	MediaTypeUnknown MediaType = iota
	MediaTypeImage
	MediaTypeVideo
	MediaTypeAudio
	MediaTypeDocument
)

func (MediaType) String

func (mt MediaType) String() string

String returns the string representation of MediaType

type ThumbnailGenerator

type ThumbnailGenerator interface {
	// GenerateThumbnail creates a thumbnail for the given file and returns the thumbnail path
	GenerateThumbnail(filePath string, maxWidth, maxHeight int) (string, error)

	// GenerateVideoThumbnail creates a thumbnail for video files
	GenerateVideoThumbnail(filePath string, maxWidth, maxHeight int) (string, error)

	// GetCachedThumbnail returns the cached thumbnail path if it exists
	GetCachedThumbnail(filePath string, maxWidth, maxHeight int) (string, bool)

	// ClearCache removes all cached thumbnails
	ClearCache() error
}

ThumbnailGenerator generates thumbnails for media files

Jump to

Keyboard shortcuts

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