internal

package
v0.0.0-...-c7421ae Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPath = "."
View Source
const DefaultReferer = "https://www.google.com"
View Source
const Timeout = 15 * time.Second

Variables

This section is empty.

Functions

func GetFileNameFromUrl

func GetFileNameFromUrl(imageUrl string) (string, error)

func GetRootUrl

func GetRootUrl(u string) (string, error)

func IsUrlValid

func IsUrlValid(rawUrl string) bool
func ProcessLinks(url string, rawLinks []string) []string

func RandomInt

func RandomInt(min, max int) int

func RemoveDuplicates

func RemoveDuplicates(original []string) []string

func Run

func Run(links []string, parameters *Parameters, httpClient HttpClient, fileSystem FileSystem) error

Types

type DefaultFileSystem

type DefaultFileSystem struct{}

func (*DefaultFileSystem) CreateDirectory

func (f *DefaultFileSystem) CreateDirectory(directory string) error

func (*DefaultFileSystem) Exists

func (f *DefaultFileSystem) Exists(path string) bool

func (*DefaultFileSystem) ReadLines

func (f *DefaultFileSystem) ReadLines(path string) ([]string, error)

func (*DefaultFileSystem) Save

func (f *DefaultFileSystem) Save(body io.ReadCloser, path string) error

type DefaultHttpClient

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

func (*DefaultHttpClient) Request

func (c *DefaultHttpClient) Request(url string, headers map[string]string) (*http.Response, error)

type DownloadInput

type DownloadInput struct {
	Url      string
	FilePath string
}

func PrepareLinksForDownload

func PrepareLinksForDownload(links []string, parameters *Parameters) []DownloadInput

type DownloadResult

type DownloadResult struct {
	Url  string
	Err  error
	Path string
}

func DownloadImages

func DownloadImages(links []DownloadInput, httClient HttpClient, fileSystem FileSystem, parameters *Parameters) []DownloadResult

type FileSystem

type FileSystem interface {
	CreateDirectory(directory string) error
	Save(body io.ReadCloser, path string) error
	ReadLines(path string) ([]string, error)
	Exists(path string) bool
}

func NewFileSystem

func NewFileSystem() FileSystem

type HttpClient

type HttpClient interface {
	Request(url string, headers map[string]string) (*http.Response, error)
}

func NewHttpClient

func NewHttpClient(userAgent string) HttpClient

type JsonPrinter

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

func (*JsonPrinter) PrintProgress

func (p *JsonPrinter) PrintProgress(validLinks int)

func (*JsonPrinter) PrintResults

func (p *JsonPrinter) PrintResults(results []DownloadResult)

type OutputFormat

type OutputFormat string
const (
	PlainText OutputFormat = "plain"
	Json      OutputFormat = "json"
)

type Parameters

type Parameters struct {
	ImageTypes       []string
	Directory        string
	Concurrent       int
	UserAgent        string
	Referer          string
	OutputFormat     OutputFormat
	SleepInterval    int
	MaxSleepInterval int
}

type PlainTextPrinter

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

func (*PlainTextPrinter) PrintProgress

func (p *PlainTextPrinter) PrintProgress(validLinks int)

func (*PlainTextPrinter) PrintResults

func (p *PlainTextPrinter) PrintResults(results []DownloadResult)

type Printer

type Printer interface {
	PrintResults(results []DownloadResult)
	PrintProgress(validLinks int)
}

func NewStdoutPrinter

func NewStdoutPrinter(outputFormat OutputFormat) Printer

type Sleeper

type Sleeper interface {
	Sleep()
}

func NewSleeper

func NewSleeper(interval, maxInterval int) Sleeper

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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