blackbeard

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Breakpoint added in v0.0.8

func Breakpoint(vars ...any)

Hacky breakpoint that prints a message

func Contains added in v0.0.8

func Contains[T comparable](array []T, value T) bool

Check if an array contains value

func Curl added in v0.0.17

func Curl[R Request | string](_request R) (string, bool, map[string][]string)

Performs a request using libcurl

func DebugLog added in v0.0.7

func DebugLog(vars ...any)

hacky debug log that writes to /tmp/debug.txt tail -f /tmp/debug.txt

func EpisodatePopulateEpisodesMetadata added in v0.0.4

func EpisodatePopulateEpisodesMetadata(show *Show)

Gets episode description from episodate api Fills in the episodes metadata of the show.Episodes array

func EpisodatePopulateShowMetadata added in v0.0.4

func EpisodatePopulateShowMetadata(show *Show)

Gets show description from episodate api Fills in the show metadata

func GetJson

func GetJson[T any](request Request, data T) T

Get Json request

func IndexOf added in v0.0.8

func IndexOf[T comparable](array []T, value T) int

Find index in array

func Invert added in v0.0.13

func Invert[T any](array []T) []T

Inverts an array

func IsDefault added in v0.0.8

func IsDefault[T Number | string | bool](v T) bool

Check if a value is the default

func Keys added in v0.0.5

func Keys[K comparable, V any](m map[K]V) []K

Return list of keys of a map

func Map added in v0.0.7

func Map[T Number, O Number](vars []T, f func(v T) O) []O

Run function for each element array, modifying it

func MapCopy added in v0.0.17

func MapCopy[T comparable, O any](m map[T]O) map[T]O

Create the copy of a map

func Max added in v0.0.7

func Max[T Number](vars ...T) T

Finds the maximum value among the arguments

func MergeMaps

func MergeMaps[K comparable, V any](maps ...map[K]V) map[K]V

func Min added in v0.0.7

func Min[T Number](vars ...T) T

Finds the minimum value among the arguments

func Perform

func Perform(request Request) (*http.Response, bool)

Perform a request using standart http

func Repeat added in v0.0.9

func Repeat(s string, times int) string

Repeat String

func SanitizeFilename added in v0.0.4

func SanitizeFilename(filename string) string

func ScrapePage

func ScrapePage(request Request, selector string, handler func(int, *goquery.Selection))

func Soup

func Soup(text string, selector string, handler func(int, *goquery.Selection))

Parses a string into a goquery selection object and call handler on it

func Sum added in v0.0.7

func Sum[T Number](vars ...T) T

Sums all arguments

func Timeout added in v0.0.9

func Timeout[R any](timeout int, f func() R) (R, bool)

Run a function and return nil, false if it timeouts. otherwise returns f(), true timeout in seconds

func WrapString added in v0.0.4

func WrapString(s string, wantedWidth uint) string

WrapString wraps the given string within lim width in characters.

Wrapping is currently naive and only happens at white-space. A future version of the library will implement smarter wrapping. This means that pathological cases can dramatically reach past the limit, such as a very long word.

func WrapStringReguardlessly added in v0.0.4

func WrapStringReguardlessly(s string, wantedWidth int) string

Wrap reguardles of spaces

Types

type Episode

type Episode struct {
	// Title of the episode
	Title string
	// Unique Number of the episode that follows the order of the series
	Number int
	// Url to the episode in the providers website
	Url string
	// Video struct for this episode
	Video Video
	// Metadata for this episode
	Metadata Metadata
}

An episode of a tv show

type Metadata added in v0.0.4

type Metadata struct {
	Description  string
	ThumbnailUrl string
	Urls         []string
	CurlCommand  string
}

Non essential information about shows, movies or episodes.

type Number added in v0.0.7

type Number interface {
	constraints.Integer | constraints.Float
}

type ProviderInfo added in v0.0.7

type ProviderInfo struct {
	// Name of the provider
	Name string
	// Url to the providers website
	Url string
	// Description for the provider
	Description string
	// If true, then better use curl-impersonate
	Cloudflared bool
}

Information for providers, similar to Metadata for episodes

type Request

type Request struct {
	// url for the request
	Url string
	// method for the request
	Method string
	// headers for the request
	Headers map[string]string
	// body for the request
	Body map[string]string
	// If set to true will use curl instead of go's stdlib http module
	// Useful in the cases there is a basic cloudflare protection and
	// curl-impersonate can be used
	Curl bool
	// If set to true will print body and request to stdout.
	// Usefult for when writting provider plugins, do not let this on in production.
	Debug bool
}

func (Request) New added in v0.0.5

func (r Request) New(path string) Request

Create a new request from an existing one, appending to the url

func (Request) ToCurlString added in v0.0.18

func (r Request) ToCurlString() string

Converts this request to a curl command. Useful for debugging.

type Show

type Show struct {
	// Title of the show
	Title string
	// Url to the show in the providers website
	Url string
	// List of episodes for this show
	Episodes []Episode
	// If set to true it is a movie provider, meaning there are no episodes and shows
	// are movies. By default it will be a show, meaning it has episodes.
	IsMovie bool
	// Metadata for this show
	Metadata Metadata
}

Can represent a Tv Show or a Movie

type Video

type Video struct {
	// Name of the video file to be downloaded
	Name string
	// Format of the video file
	Format string
	// Request to the providers api to fetch the video
	Request Request
	// Metadata for the video
	Metadata Metadata
}

Packages a request to the providers api to fetch the video for an episode or movie Also information about the file to be downloaded

func (Video) Download

func (video Video) Download(dir string, linepos int, prepend_str_fmt string) bool

Downloads a video to the given directory linepos is the position to print the download progress line in

type VideoProvider

type VideoProvider interface {
	// Get the list of shows for this provider.
	// If the provider is a movie provider, this will alerady be the movie list
	SearchShows(string) []Show
	// Get the list of episodes for a show and populates Show.Episodes.
	// If show.IsMovie then should return a single episode in the list, others
	// will be ignored.
	GetEpisodes(*Show) []Episode
	// Get the video for an episode and populates Episode.Video
	GetVideo(*Episode) Video
	// Get the provider information.
	Info() ProviderInfo
}

Interface for video providers

Jump to

Keyboard shortcuts

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