internal

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

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

Go to latest
Published: Jun 9, 2024 License: MPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusPending = iota
	StatusDownloading
	StatusCompleted
	StatusErrored
)

Variables

This section is empty.

Functions

func PlaylistDetect

func PlaylistDetect(req DownloadRequest, mq *MessageQueue, db *MemoryDB, logger *slog.Logger) error

Types

type AbortRequest

type AbortRequest struct {
	Id string `json:"id"`
}

struct representing the intent to stop a specific process

type CustomTemplate

type CustomTemplate struct {
	Id      string `json:"id"`
	Name    string `json:"name"`
	Content string `json:"content"`
}

represents a user defined collection of yt-dlp arguments

type DownloadFormats

type DownloadFormats struct {
	Formats   []Format `json:"formats"`
	Best      Format   `json:"best"`
	Thumbnail string   `json:"thumbnail"`
	Title     string   `json:"title"`
	URL       string   `json:"url"`
}

Used to deser the formats in the -J output

type DownloadInfo

type DownloadInfo struct {
	URL         string    `json:"url"`
	Title       string    `json:"title"`
	Thumbnail   string    `json:"thumbnail"`
	Resolution  string    `json:"resolution"`
	Size        int32     `json:"filesize_approx"`
	VCodec      string    `json:"vcodec"`
	ACodec      string    `json:"acodec"`
	Extension   string    `json:"ext"`
	OriginalURL string    `json:"original_url"`
	FileName    string    `json:"filename"`
	CreatedAt   time.Time `json:"created_at"`
}

Used to deser the yt-dlp -J output

type DownloadOutput

type DownloadOutput struct {
	Path          string
	Filename      string
	SavedFilePath string `json:"savedFilePath"`
}

Defines where and how the download needs to be saved

type DownloadProgress

type DownloadProgress struct {
	Status     int     `json:"process_status"`
	Percentage string  `json:"percentage"`
	Speed      float32 `json:"speed"`
	ETA        float32 `json:"eta"`
}

Progress for the Running call

type DownloadRequest

type DownloadRequest struct {
	Id     string
	URL    string   `json:"url"`
	Path   string   `json:"path"`
	Rename string   `json:"rename"`
	Params []string `json:"params"`
}

struct representing the intent to start a download

type Format

type Format struct {
	Format_id   string  `json:"format_id"`
	Format_note string  `json:"format_note"`
	FPS         float32 `json:"fps"`
	Resolution  string  `json:"resolution"`
	VCodec      string  `json:"vcodec"`
	ACodec      string  `json:"acodec"`
	Size        float32 `json:"filesize_approx"`
}

A skimmed yt-dlp format node

type LoadBalancer

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

func (*LoadBalancer) Balance

func (b *LoadBalancer) Balance(work chan Process)

type MemoryDB

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

In-Memory Thread-Safe Key-Value Storage with optional persistence

func (*MemoryDB) All

func (m *MemoryDB) All() *[]ProcessResponse

Returns a slice of all currently stored processes progess

func (*MemoryDB) Delete

func (m *MemoryDB) Delete(id string)

Removes a process progress, given the process id

func (*MemoryDB) Get

func (m *MemoryDB) Get(id string) (*Process, error)

Get a process pointer given its id

func (*MemoryDB) Keys

func (m *MemoryDB) Keys() *[]string

func (*MemoryDB) Persist

func (m *MemoryDB) Persist() error

Persist the database in a single file named "session.dat"

func (*MemoryDB) Restore

func (m *MemoryDB) Restore(mq *MessageQueue, logger *slog.Logger)

Restore a persisted state

func (*MemoryDB) Set

func (m *MemoryDB) Set(process *Process) string

Store a pointer of a process and return its id

type MessageQueue

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

func NewMessageQueue

func NewMessageQueue(l *slog.Logger) (*MessageQueue, error)

Creates a new message queue. By default it will be created with a size equals to nthe number of logical CPU cores -1. The queue size can be set via the qs flag.

func (*MessageQueue) Publish

func (m *MessageQueue) Publish(p *Process)

Publish a message to the queue and set the task to a peding state.

func (*MessageQueue) SetupConsumers

func (m *MessageQueue) SetupConsumers()

type Node

type Node[T any] struct {
	Value T
}

type Pool

type Pool []*Worker

func (Pool) Len

func (h Pool) Len() int

func (Pool) Less

func (h Pool) Less(i, j int) bool

func (*Pool) Pop

func (h *Pool) Pop() any

func (*Pool) Push

func (h *Pool) Push(x any)

func (Pool) Swap

func (h Pool) Swap(i, j int)

type Process

type Process struct {
	Id       string
	Url      string
	Params   []string
	Info     DownloadInfo
	Progress DownloadProgress
	Output   DownloadOutput

	Logger *slog.Logger
	// contains filtered or unexported fields
}

Process descriptor

func (*Process) Complete

func (p *Process) Complete()

Keep process in the memoryDB but marks it as complete Convention: All completed processes has progress -1 and speed 0 bps.

func (*Process) GetFileName

func (p *Process) GetFileName(o *DownloadOutput) error

func (*Process) GetFormatsSync

func (p *Process) GetFormatsSync() (DownloadFormats, error)

Returns the available format for this URL TODO: Move out from process.go

func (*Process) Kill

func (p *Process) Kill() error

Kill a process and remove it from the memory

func (*Process) SetMetadata

func (p *Process) SetMetadata() error

func (*Process) SetPending

func (p *Process) SetPending()

func (*Process) Start

func (p *Process) Start()

Starts spawns/forks a new yt-dlp process and parse its stdout. The process is spawned to outputting a custom progress text that Resembles a JSON Object in order to Unmarshal it later. This approach is anyhow not perfect: quotes are not escaped properly. Each process is not identified by its PID but by a UUIDv4

type ProcessResponse

type ProcessResponse struct {
	Id       string           `json:"id"`
	Progress DownloadProgress `json:"progress"`
	Info     DownloadInfo     `json:"info"`
	Output   DownloadOutput   `json:"output"`
	Params   []string         `json:"params"`
}

struct representing the response sent to the client as JSON-RPC result field

type ProgressTemplate

type ProgressTemplate struct {
	Percentage string  `json:"percentage"`
	Speed      float32 `json:"speed"`
	Size       string  `json:"size"`
	Eta        float32 `json:"eta"`
}

Used to unmarshall yt-dlp progress

type Session

type Session struct {
	Processes []ProcessResponse `json:"processes"`
}

struct representing the current status of the memoryDB used for serializaton/persistence reasons

type SetCookiesRequest

type SetCookiesRequest struct {
	Cookies string `json:"cookies"`
}

struct representing request of creating a netscape cookies file

type Stack

type Stack[T any] struct {
	Nodes []*Node[T]
	// contains filtered or unexported fields
}

func NewStack

func NewStack[T any]() *Stack[T]

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

func (*Stack[T]) IsNotEmpty

func (s *Stack[T]) IsNotEmpty() bool

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() *Node[T]

func (*Stack[T]) Push

func (s *Stack[T]) Push(val T)

type Worker

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

func (*Worker) Work

func (w *Worker) Work(done chan *Worker)

Jump to

Keyboard shortcuts

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