extractors

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MIT Imports: 6 Imported by: 45

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrURLParseFailed defines url parse failed error.
	ErrURLParseFailed            = errors.New("url parse failed")
	ErrInvalidRegularExpression  = errors.New("invalid regular expression")
	ErrURLQueryParamsParseFailed = errors.New("url query params parse failed")
	ErrBodyParseFailed           = errors.New("body parse failed")
)

Functions

func Register added in v0.13.0

func Register(domain string, e Extractor)

Register registers an Extractor.

Types

type CaptionPart added in v0.13.0

type CaptionPart struct {
	Part
	Transform func([]byte) ([]byte, error) `json:"-"`
}

type Data added in v0.13.0

type Data struct {
	// URL is used to record the address of this download
	URL   string   `json:"url"`
	Site  string   `json:"site"`
	Title string   `json:"title"`
	Type  DataType `json:"type"`
	// each stream has it's own Parts and Quality
	Streams map[string]*Stream `json:"streams"`
	// danmaku, subtitles, etc
	Captions map[string]*CaptionPart `json:"caption"`
	// Err is used to record whether an error occurred when extracting the list data
	Err error `json:"err"`
}

Data is the main data structure for the whole video data.

func EmptyData added in v0.13.0

func EmptyData(url string, err error) *Data

EmptyData returns an "empty" Data object with the given URL and error.

func Extract

func Extract(u string, option Options) ([]*Data, error)

Extract is the main function to extract the data.

func (*Data) FillUpStreamsData added in v0.13.0

func (d *Data) FillUpStreamsData()

FillUpStreamsData fills up some data automatically.

type DataType added in v0.13.0

type DataType string

DataType indicates the type of extracted data, eg: video or image.

const (
	// DataTypeVideo indicates the type of extracted data is the video.
	DataTypeVideo DataType = "video"
	// DataTypeImage indicates the type of extracted data is the image.
	DataTypeImage DataType = "image"
	// DataTypeAudio indicates the type of extracted data is the audio.
	DataTypeAudio DataType = "audio"
)

type Extractor added in v0.13.0

type Extractor interface {
	// Extract is the main function to extract the data.
	Extract(url string, option Options) ([]*Data, error)
}

Extractor implements video data extraction related operations.

type Options added in v0.13.0

type Options struct {
	// Playlist indicates if we need to extract the whole playlist rather than the single video.
	Playlist bool
	// Items defines wanted items from a playlist. Separated by commas like: 1,5,6,8-10.
	Items string
	// ItemStart defines the starting item of a playlist.
	ItemStart int
	// ItemEnd defines the ending item of a playlist.
	ItemEnd int

	// ThreadNumber defines how many threads will use in the extraction, only works when Playlist is true.
	ThreadNumber int
	Cookie       string

	// EpisodeTitleOnly indicates file name of each bilibili episode doesn't include the playlist title
	EpisodeTitleOnly bool

	YoukuCcode    string
	YoukuCkey     string
	YoukuPassword string
}

Options defines optional options that can be used in the extraction function.

type Part added in v0.13.0

type Part struct {
	URL  string `json:"url"`
	Size int64  `json:"size"`
	Ext  string `json:"ext"`
}

Part is the data structure for a single part of the video stream information.

type Stream added in v0.13.0

type Stream struct {
	// eg: "1080"
	ID string `json:"id"`
	// eg: "1080P xxx"
	Quality string `json:"quality"`
	// [Part: {URL, Size, Ext}, ...]
	// Some video stream have multiple parts,
	// and can also be used to download multiple image files at once
	Parts []*Part `json:"parts"`
	// total size of all urls
	Size int64 `json:"size"`
	// the file extension after video parts merged
	Ext string `json:"ext"`
	// if the parts need mux
	NeedMux bool
}

Stream is the data structure for each video stream, eg: 720P, 1080P.

Jump to

Keyboard shortcuts

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