downloader

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2019 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTransferNotFound    = errors.New("download not found")
	ErrInsufficientStorage = errors.New("insufficient storage")
)

Functions

func EnsureDir

func EnsureDir(dirName string) error

func Ffprobe

func Ffprobe(filename string) (*ffprobeInfo, error)

func Ffthumb

func Ffthumb(videofile, thumbfile, args string, jpg bool) error

func GET

func GET(ctx context.Context, rawurl string) (*http.Response, error)

Types

type Config

type Config struct {
	UploadSpeed   int64
	DownloadSpeed int64
	Logger        *zap.SugaredLogger
	Space         func() int64

	TorrentAddr string

	TransferSlots int
	DownloadDir   string
	TorrentRatio  float64
	// contains filtered or unexported fields
}

func (*Config) GetDownloadDir

func (c *Config) GetDownloadDir() string

DownloadDir

func (*Config) GetTorrentRatio

func (c *Config) GetTorrentRatio() float64

TorrentRatio

func (*Config) GetTransferSlots

func (c *Config) GetTransferSlots() int

TransferSlots

func (*Config) Lock

func (c *Config) Lock(loc string)

func (*Config) RLock

func (c *Config) RLock(loc string)

func (*Config) RUnlock

func (c *Config) RUnlock(loc string)

func (*Config) SetDownloadDir

func (c *Config) SetDownloadDir(path string)

func (*Config) SetTorrentRatio

func (c *Config) SetTorrentRatio(ratio float64)

func (*Config) SetTransferSlots

func (c *Config) SetTransferSlots(n int)

func (*Config) Unlock

func (c *Config) Unlock(loc string)

type DownloadOptions

type DownloadOptions struct {
	Name      string
	Subsf     string
	IsSubs    bool
	IsConvert bool
	IsSeeding bool
}

func NewDefaultOptions

func NewDefaultOptions() *DownloadOptions

type Downloader

type Downloader struct {
	Config *Config
	// contains filtered or unexported fields
}

func NewDownloader

func NewDownloader(cfg *Config) (*Downloader, error)

func (*Downloader) Active

func (l *Downloader) Active() int

func (*Downloader) Add

func (l *Downloader) Add(rawurl string, opt *DownloadOptions) (Transfer, error)

func (*Downloader) Busy

func (l *Downloader) Busy() bool

func (*Downloader) Downloading

func (l *Downloader) Downloading(name string) bool

func (*Downloader) Find

func (l *Downloader) Find(id string) (Transfer, error)

func (*Downloader) FindByURL

func (l *Downloader) FindByURL(rawurl string) (Transfer, error)

func (*Downloader) ListActive

func (l *Downloader) ListActive() []Transfer

func (*Downloader) ListPending

func (l *Downloader) ListPending() []Transfer

func (*Downloader) Lock

func (l *Downloader) Lock(loc string)

func (*Downloader) PostProcess

func (l *Downloader) PostProcess(ctx context.Context, t *Transfer) error

func (*Downloader) RLock

func (l *Downloader) RLock(loc string)

func (*Downloader) RUnlock

func (l *Downloader) RUnlock(loc string)

func (*Downloader) Remove

func (l *Downloader) Remove(id string) error

func (*Downloader) Unlock

func (l *Downloader) Unlock(loc string)

func (*Downloader) Uploading

func (l *Downloader) Uploading(name string) bool

func (*Downloader) Waiting

func (l *Downloader) Waiting() int

type Transfer

type Transfer struct {
	ID        string
	URL       *url.URL
	Created   time.Time
	Started   time.Time
	Completed time.Time
	Cancel    *context.CancelFunc

	DownloadDir string
	Uploading   bool
	SeedRatio   float64
	PostOptions *DownloadOptions

	Torrent *torrent.Torrent
	Error   error

	// Friend downloads
	DownloadID   string
	DownloadSize int64
}

func (Transfer) DownloadedBytes

func (t Transfer) DownloadedBytes() int64

DownloadedBytes returns the downloaded bytes.

func (Transfer) Files

func (t Transfer) Files() ([]os.FileInfo, error)

Files returns all the files inside the download dir.

func (Transfer) IsActive

func (t Transfer) IsActive() bool

IsActive returns true when the transfer is started but not completed.

func (Transfer) IsCompleted

func (t Transfer) IsCompleted() bool

IsCompleted returns true when the transfer has been completed.

func (Transfer) IsStarted

func (t Transfer) IsStarted() bool

IsStarted returns true when the transfer has been started.

func (Transfer) MarkDownloading

func (t Transfer) MarkDownloading() error

MarkDownloading creates the .downloading file

func (Transfer) MarkUploading

func (t Transfer) MarkUploading() error

MarkUploading creates the .uploading file

func (Transfer) String

func (t Transfer) String() string

String returns the title of the transfer.

func (Transfer) TotalSeedSize

func (t Transfer) TotalSeedSize() int64

TotalSeedSize returns the length of the seeding target size in bytes.

func (Transfer) TotalSize

func (t Transfer) TotalSize() int64

TotalSize returns the completed size of the download in bytes.

func (Transfer) UnmarkDownloading

func (t Transfer) UnmarkDownloading() error

UnmarkDownloading removes the .downloading file for the download

func (Transfer) UnmarkUploading

func (t Transfer) UnmarkUploading() error

UnmarkUploading removes the .uploading file for the upload

func (Transfer) UploadedBytes

func (t Transfer) UploadedBytes() int64

UploadedBytes returns uploaded bytes.

Jump to

Keyboard shortcuts

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