api

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombineStringsWithNewline

func CombineStringsWithNewline(strs ...string) string

Same as strings.Join([]string, "\n")

func ConvertPageNumToOffset

func ConvertPageNumToOffset(minPageNum, maxPageNum, perPage int) (int, int)

Convert the page number to the offset as one page might have x posts.

Usually for paginated results like Pixiv's mobile API (60 per page), checkPixivMax should be set to true.

func DetectGDriveLinks(text, postFolderPath string, isUrl, logUrls bool) bool

Detects if the given string contains any GDrive links and logs it if detected

func DetectOtherExtDLLink(text, postFolderPath string) bool

Detects if the given string contains any other external file hosting providers links and logs it if detected

func DetectPasswordInText

func DetectPasswordInText(text string) bool

Detects if the given string contains any passwords

func ExecuteChromedpActions

func ExecuteChromedpActions(allocCtx context.Context, allocCancelFn context.CancelFunc, actions ...chromedp.Action) error

func GetCookie

func GetCookie(sessionID, website string) *http.Cookie

Returns a cookie with given value and website to be used in requests

func GetDefaultChromedpAlloc

func GetDefaultChromedpAlloc(userAgent string, ctx context.Context) (context.Context, context.CancelFunc)

func GetMinMaxFromStr

func GetMinMaxFromStr(numStr string) (int, int, bool, error)

Returns the min, max, hasMaxNum, and error from the given string of "num" or "min-max"

E.g.

"1-10" => 1, 10, true, nil
"1" => 1, 1, true, nil
"" => 1, 1, false, nil (defaults to min = 1, max = inf)

func RemoveDuplicateIdAndPageNum

func RemoveDuplicateIdAndPageNum[T SliceTypes](idSlice, pageSlice []T) ([]T, []T)

Used for removing duplicate IDs with its corresponding page number from the given slices.

Returns the the new idSlice and pageSlice with the duplicates removed.

func RemoveSliceDuplicates

func RemoveSliceDuplicates[T SliceTypes](s []T) []T

Removes duplicates from the given slice.

func SetChromedpAllocCookies

func SetChromedpAllocCookies(cookies []*http.Cookie) chromedp.Action

func SliceContains

func SliceContains[T SliceTypes](arr []T, target T) bool

Checks if the given target is in the given arr and returns a boolean

func SliceMatchesRegex

func SliceMatchesRegex(regex *regexp.Regexp, slice []string, strict bool) (bool, string)

Checks if the slice of string all matches the given regex pattern If strict is true, then all string must match the regex pattern. Otherwise, empty strings are allowed.

Returns true if all matches, false otherwise with the outlier string

func ValidateDlDirPath added in v1.1.0

func ValidateDlDirPath(dlDirPath, targetDirName string) (validatedDirPath string, err error)

func ValidateId added in v1.1.0

func ValidateId(arg string) error

func ValidateIds

func ValidateIds(args []string) error

Validates if the slice of strings contains only numbers Otherwise, os.Exit(1) is called after printing error messages for the user to read

func ValidatePageNumInput

func ValidatePageNumInput(baseSliceLen int, pageNums []string, errMsgs []string) error

check page nums if they are in the correct format.

E.g. "1-10" is valid, but "0-9" is not valid because "0" is not accepted

func ValidateStrArgs

func ValidateStrArgs(str string, slice, errMsgs []string) (string, error)

Checks if the slice of string contains the target str. Otherwise, returns an error.

func VerifyAndGetCookie

func VerifyAndGetCookie(website, cookieValue, userAgent string) (*http.Cookie, error)

Verifies the given cookie by making a request to the website and checks if the cookie is valid If the cookie is valid, the cookie will be returned

However, if the cookie is invalid, an error message will be printed out and the program will shutdown

func VerifyCookie

func VerifyCookie(cookie *http.Cookie, website, userAgent string) (bool, error)

Verifies the given cookie by making a request to the website and returns true if the cookie is valid

func VerifyCookies added in v1.1.0

func VerifyCookies(website, userAgent string, cookies []*http.Cookie) error

Types

type SliceTypes

type SliceTypes interface {
	~string | ~int
}

Directories

Path Synopsis
web

Jump to

Keyboard shortcuts

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