godler

package module
v0.0.0-...-1854c87 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package godler provides ...

Package godler provides ...

Package godler provides ...

Package godler provides ...

Package godler provides ...

Package godler provides ...

Package godler provides ...

Package godler provides ...

Package godler provides ...

Package godler provides ...

Index

Constants

View Source
const (
	PermFile fs.FileMode = 0666
	PermDir              = 0755
)
View Source
const (
	DOWNLOAD_DIR string = "~/Downloads"
)
View Source
const (
	SEGMENT_SIZE int = 16 * 1024 * 1024
)

Variables

View Source
var (
	LoggerPath string
)

Functions

func AppendFile

func AppendFile(filePath string, b []byte) error

func FileExists

func FileExists(filepath string) bool

判断地址是否存在

func GetDefaultDownloadDir

func GetDefaultDownloadDir() string

func GetDownloadDir

func GetDownloadDir() string

func GetReaderFromURI

func GetReaderFromURI(uri string) (io.Reader, error)

从地址获取 io.Reader

func ProcessDownloadTasker

func ProcessDownloadTasker(t IDownloadTasker)

func RunDownloadTasker

func RunDownloadTasker(t IDownloadTasker) error

func WriteFile

func WriteFile(filePath string, b []byte) error

Types

type DownloadConfig

type DownloadConfig struct {
	DownloadDir string
	Name        string
	Debug       bool
}

func NewDownloadConfig

func NewDownloadConfig(downloadDir string, name string) *DownloadConfig

type DownloadInfo

type DownloadInfo struct {
	Segment
	Type  string      `json:"type"`
	Extra interface{} `json:"extra"`
}

type DownloadTaskConfig

type DownloadTaskConfig struct {
	*TaskerConfig
	*DownloadConfig
}

func NewDownloadTaskConfig

func NewDownloadTaskConfig(
	downloadDir string, name string,
) *DownloadTaskConfig

type DownloadTasker

type DownloadTasker struct {
	*Tasker
	*Downloader
}

func NewDownloadTasker

func NewDownloadTasker(
	uri string, config *DownloadTaskConfig,
) (*DownloadTasker, error)

func (*DownloadTasker) AfterRun

func (dt *DownloadTasker) AfterRun() error

func (DownloadTasker) RunTask

func (d DownloadTasker) RunTask(task *Task) error

运行下载任务

type DownloadType

type DownloadType string
const (
	TYPE_M3U8 DownloadType = "m3u8"
	TYPE_FILE              = "file"
)

type Downloader

type Downloader struct {
	*tools.URL
	Config   *DownloadConfig // 下载配置
	Segments *[]Segment      // 下载片段集合
	// contains filtered or unexported fields
}

下载器父类

func NewDownloader

func NewDownloader(uri string, config *DownloadConfig) (*Downloader, error)

初始化 Downloader

func (*Downloader) Build

func (d *Downloader) Build() error

func (Downloader) Download

func (d Downloader) Download(info *DownloadInfo) error

func (Downloader) FormatPath

func (d Downloader) FormatPath(uri string) string

func (Downloader) FormatURI

func (d Downloader) FormatURI(uri string) string

func (Downloader) GetCacheDir

func (d Downloader) GetCacheDir() string

func (Downloader) GetDir

func (d Downloader) GetDir() string

func (Downloader) GetName

func (d Downloader) GetName() string

func (Downloader) GetPath

func (d Downloader) GetPath() string

func (Downloader) Match

func (d Downloader) Match() bool

func (Downloader) Process

func (d Downloader) Process() float64

获取进度

type FileDownloader

type FileDownloader struct {
	*DownloadTasker
	RangeSegments *[]RangeSegment
	WithPart      bool
	CacheDir      string
}

func NewFileDownloader

func NewFileDownloader(dt *DownloadTasker) *FileDownloader

func (*FileDownloader) AfterRun

func (f *FileDownloader) AfterRun() error

func (*FileDownloader) Build

func (f *FileDownloader) Build() error

func (*FileDownloader) BuildTasks

func (f *FileDownloader) BuildTasks() error

func (FileDownloader) Match

func (f FileDownloader) Match() bool

func (FileDownloader) MergeFile

func (f FileDownloader) MergeFile()
type Header struct {
	ContentLength []string `json:"Content-Length"`
	AcceptRanges  []string `json:"Accept-Ranges"`
}

func (*Header) ConverHttpHeader

func (h *Header) ConverHttpHeader(header http.Header) error

func (Header) GetAcceptRanges

func (h Header) GetAcceptRanges() string

func (Header) GetContentLength

func (h Header) GetContentLength() int

func (Header) GetRangeSegments

func (h Header) GetRangeSegments(SegmentSize int) []RangeSegment

type IDownloadTasker

type IDownloadTasker interface {
	ITasker
	IDownloader
	RunTask(*Task) error
}

下载任务管理器

func MatchDownloadTasker

func MatchDownloadTasker(
	uri string, config *DownloadTaskConfig,
) (IDownloadTasker, error)

匹配下载任务器

type IDownloader

type IDownloader interface {
	Match() bool
	Build() error
	Download(*DownloadInfo) error
	Process() float64
}

下载接口

type IPathFormater

type IPathFormater interface {
	FormatPath(string) string
}

type ITasker

type ITasker interface {
	Build() error
	BuildTasks() error
	AddTask(*Task)
	GetTasks() []*Task
	Run(TaskFunc) error
	SyncRun(TaskFunc) error
	AfterRun() error
	BeforeRun() error
}

type IType

type IType interface {
	Match(string) DownloadType
}

type IURIFormater

type IURIFormater interface {
	FormatURI(string) string
}

type Logger

type Logger interface {
	Infof(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Debugf(format string, v ...interface{})
}
var (
	Log Logger
)

func NewLogger

func NewLogger(output io.Writer, prefix string, flag int) Logger

NewLogger create a Logger wraps the *log.Logger

type M3U8Downloader

type M3U8Downloader struct {
	*DownloadTasker
	M3U8PlayList m3u8.Playlist
	M3U8ListType m3u8.ListType
}

func NewM3U8Downloader

func NewM3U8Downloader(dt *DownloadTasker) *M3U8Downloader

func (*M3U8Downloader) Build

func (m *M3U8Downloader) Build() error

func (*M3U8Downloader) BuildTasks

func (m *M3U8Downloader) BuildTasks() error

func (M3U8Downloader) FormatPath

func (m M3U8Downloader) FormatPath(uri string) string

func (M3U8Downloader) Match

func (m M3U8Downloader) Match() bool

func (*M3U8Downloader) ParserM3U8

func (m *M3U8Downloader) ParserM3U8()

解析 m3u8

func (M3U8Downloader) SaveM3U8

func (m M3U8Downloader) SaveM3U8(mediaPlaylist *m3u8.MediaPlaylist)

保存 m3u8 数据

type NewDownloaderFunc

type NewDownloaderFunc func(*DownloadTasker) IDownloadTasker

type RangeSegment

type RangeSegment struct {
	Start int
	End   int
}

type Segment

type Segment struct {
	Url    string            `json:"url"`  // 下载片段地址
	Path   string            `json:"path"` // 保存地址
	Header map[string]string `json:"header"`
}

type Task

type Task struct {
	RetryTime int         `json:"retry_count"`
	Err       error       `json:"err"`
	Info      interface{} `json:"info"`
}

type TaskFunc

type TaskFunc func(*Task) error

type Tasker

type Tasker struct {
	TaskId string
	Config *TaskerConfig
	Tasks  []*Task

	WaitGroup sync.WaitGroup
	// contains filtered or unexported fields
}

func NewTasker

func NewTasker(config *TaskerConfig) *Tasker

func (*Tasker) AddTask

func (t *Tasker) AddTask(task *Task)

func (*Tasker) AfterRun

func (t *Tasker) AfterRun() error

func (*Tasker) BeforeRun

func (t *Tasker) BeforeRun() error

func (*Tasker) Build

func (t *Tasker) Build() error

func (*Tasker) BuildTasks

func (t *Tasker) BuildTasks() error

func (Tasker) GetTasks

func (t Tasker) GetTasks() []*Task

func (*Tasker) Run

func (t *Tasker) Run(runTaskFunc TaskFunc) error

func (*Tasker) SyncRun

func (t *Tasker) SyncRun(runTaskFunc TaskFunc) error

type TaskerConfig

type TaskerConfig struct {
	ProcessNum     int
	RetryMaxTime   int
	UseProgressBar bool
}

func NewTaskerConfig

func NewTaskerConfig() *TaskerConfig

type UrlType

type UrlType struct {
}

func (UrlType) Match

func (ut UrlType) Match(uri string) (DownloadType, error)

Directories

Path Synopsis
cmd
godler
Package main provides ...
Package main provides ...

Jump to

Keyboard shortcuts

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