Documentation
¶
Index ¶
- Constants
- Variables
- func Btoi(b bool) int
- func DirExists(path string) (bool, error)
- func EmptyDir(path string) error
- func EnsureDir(path string) error
- func EnsureDirAll(path string) error
- func FileExists(path string) (bool, error)
- func FileType(filePath string) (types.Type, error)
- func FindDuplicates(hashes []*Phash, distance int) [][]int
- func FixWindowsPath(str string) string
- func FlipCaseSingle(s string) (string, error)
- func GenerateRandomKey(l int) string
- func GetBase64StringFromData(data []byte) string
- func GetDataFromBase64String(encodedString string) ([]byte, error)
- func GetDir(path string) string
- func GetFunscriptPath(path string) string
- func GetHomeDirectory() string
- func GetIntraDir(pattern string, depth, length int) string
- func GetNameFromPath(path string, stripExtension bool) string
- func GetParent(path string) *string
- func GetUserAgent() string
- func GetVTTTime(fracSeconds float64) string
- func GetYMDFromDatabaseDate(dateString string) string
- func IntAppendUnique(vs []int, toAdd int) []int
- func IntAppendUniques(vs []int, toAdd []int) []int
- func IntExclude(vs []int, toExclude []int) []int
- func IntFromString(str string) uint64
- func IntInclude(vs []int, t int) bool
- func IntIndex(vs []int, t int) int
- func IsFsPathCaseSensitive(path string) (bool, error)
- func IsPathInDir(dir, pathToCheck string) bool
- func IsTrue(b *bool) bool
- func IsValidFloat64(value float64) bool
- func IsZipFileUncompressed(path string) (bool, error)
- func ListDir(path string) ([]string, error)
- func MD5FromBytes(data []byte) string
- func MD5FromFilePath(filePath string) (string, error)
- func MD5FromReader(src io.Reader) (string, error)
- func MD5FromString(str string) string
- func MatchEntries(dir, pattern string) ([]string, error)
- func OSHashFromFilePath(filePath string) (string, error)
- func ParseDateStringAsFormat(dateString string, format string) (string, error)
- func ParseDateStringAsTime(dateString string) (time.Time, error)
- func PhashToString(phash int64) string
- func ProcessBase64Image(imageString string) (string, []byte, error)
- func ProcessImageInput(imageInput string) ([]byte, error)
- func RandomSequence(n int) string
- func ReadImageFromURL(url string) ([]byte, error)
- func RemoveDir(path string) error
- func SafeMove(src, dst string) error
- func ServeFileNoCache(w http.ResponseWriter, r *http.Request, filepath string)
- func ServeImage(image []byte, w http.ResponseWriter, r *http.Request) error
- func StrAppendUnique(vs []string, toAdd string) []string
- func StrAppendUniques(vs []string, toAdd []string) []string
- func StrDelete(vs []string, toDel string) []string
- func StrFilter(vs []string, f func(string) bool) []string
- func StrFormat(format string, m StrFormatMap) string
- func StrInclude(vs []string, t string) bool
- func StrIndex(vs []string, t string) int
- func StrMap(vs []string, f func(string) string) []string
- func StrUnique(vs []string) []string
- func StringSliceToIntSlice(ss []string) ([]int, error)
- func StringToPhash(s string) (int64, error)
- func SymWalk(path string, walkFn filepath.WalkFunc) error
- func Timeout(todo func(), waitTime time.Duration, onTimeout func(done chan struct{}))
- func Touch(path string) error
- func ValueOnlyContext(ctx context.Context) context.Context
- func WriteFile(path string, file []byte) error
- type ByteRange
- type Phash
- type StrFormatMap
Constants ¶
const FirefoxLinux = "Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0"
const FirefoxLinuxArm = "Mozilla/5.0 (X11; Linux armv7l; rv:86.0) Gecko/20100101 Firefox/86.0"
const FirefoxLinuxArm64 = "Mozilla/5.0 (X11; Linux aarch64; rv:86.0) Gecko/20100101 Firefox/86.0"
const FirefoxWindows = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0"
const Safari = "" /* 131-byte string literal not displayed */
valid UA from https://user-agents.net
Variables ¶
var PendingGenerateResource, _ = GetDataFromBase64String("iVBORw0KGgoAAAANSUhEUgAAAfQAAADwBAMAAAAEHosbAAAAG1BMVEUAAADMzMyZmZkzMzNmZmZ/f38ZGRmysrJMTEwh+DPkAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEOklEQVR4nO3YzW/bNhjHcfpN9jGP8iIfI2xrdrQLrLs67Zpdo21pelTWdbnGSTPvaBdosT+7z8OXxAFkIDu0Vrfv59AmpEjoJ1IkFecAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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Tzb53TKXuggrvBSXMhvo50u3rXvbXXT3vvje3UXXj9a/H2xuzv1cfEzX/jEvTtxKfxmV18v76LGLsK8Xs95imZU3qfTr1vyXuv+83gsd42Lbd7EVI/tyy7d9F1uRyateOd72XWyHfaY2/d32f8C2q1YeTD6/7Pn1ybbvAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAL+ITrOa6fKadMcEAAAAASUVORK5CYII=")
Functions ¶
func DirExists ¶
func DirExists(path string) (bool, error)
DirExists returns true if the given path exists and is a directory
func EmptyDir ¶
func EmptyDir(path string) error
EmptyDir will recursively remove the contents of a directory at the given path
func EnsureDir ¶
func EnsureDir(path string) error
EnsureDir will create a directory at the given path if it doesn't already exist
func EnsureDirAll ¶ added in v0.2.0
func EnsureDirAll(path string) error
EnsureDirAll will create a directory at the given path along with any necessary parents if they don't already exist
func FileExists ¶
func FileExists(path string) (bool, error)
FileExists returns true if the given path exists
func FileType ¶
func FileType(filePath string) (types.Type, error)
FileType uses the filetype package to determine the given file path's type
func FindDuplicates ¶ added in v0.7.0
func FindDuplicates(hashes []*Phash, distance int) [][]int
func FixWindowsPath ¶
func FixWindowsPath(str string) string
FixWindowsPath replaces \ with / in the given path because sometimes the \ isn't recognized as valid on windows
func FlipCaseSingle ¶ added in v0.8.0
func FlipCaseSingle(s string) (string, error)
FlipCaseSingle flips the case ( lower<->upper ) of a single char from the string s If the string cannot be flipped, the original string value and an error are returned
func GenerateRandomKey ¶ added in v0.2.0
func GenerateRandomKey(l int) string
func GetBase64StringFromData ¶
func GetBase64StringFromData(data []byte) string
GetBase64StringFromData returns the given byte slice as a base64 encoded string
func GetDataFromBase64String ¶
func GetDataFromBase64String(encodedString string) ([]byte, error)
GetDataFromBase64String returns the given base64 encoded string as a byte slice
func GetFunscriptPath ¶ added in v0.8.0
func GetFunscriptPath(path string) string
GetFunscriptPath returns the path of a file with the extension changed to .funscript
func GetHomeDirectory ¶
func GetHomeDirectory() string
GetHomeDirectory returns the path of the user's home directory. ~ on Unix and C:\Users\UserName on Windows
func GetIntraDir ¶ added in v0.2.0
func GetIntraDir(pattern string, depth, length int) string
GetIntraDir returns a string that can be added to filepath.Join to implement directory depth, "" on error eg given a pattern of 0af63ce3c99162e9df23a997f62621c5 and a depth of 2 length of 3 returns 0af/63c or 0af\63c ( dependin on os) that can be later used like this filepath.Join(directory, intradir, basename)
func GetNameFromPath ¶ added in v0.7.0
func GetNameFromPath(path string, stripExtension bool) string
GetNameFromPath returns the name of a file from its path if stripExtension is true the extension is omitted from the name
func GetUserAgent ¶ added in v0.6.0
func GetUserAgent() string
GetUserAgent returns a valid User Agent string that matches the running os/arch
func GetVTTTime ¶
func GetVTTTime(fracSeconds float64) string
GetVTTTime returns a timestamp appropriate for VTT files (hh:mm:ss.mmm)
func GetYMDFromDatabaseDate ¶
func GetYMDFromDatabaseDate(dateString string) string
func IntAppendUnique ¶ added in v0.4.0
func IntAppendUnique(vs []int, toAdd int) []int
IntAppendUnique appends toAdd to the vs int slice if toAdd does not already exist in the slice. It returns the new or unchanged int slice.
func IntAppendUniques ¶ added in v0.4.0
func IntAppendUniques(vs []int, toAdd []int) []int
IntAppendUniques appends a slice of int values to the vs int slice. It only appends values that do not already exist in the slice. It returns the new or unchanged int slice.
func IntExclude ¶ added in v0.5.0
func IntExclude(vs []int, toExclude []int) []int
IntExclude removes all instances of any value in toExclude from the vs int slice. It returns the new or unchanged int slice.
func IntFromString ¶ added in v0.3.0
func IntFromString(str string) uint64
func IntInclude ¶ added in v0.4.0
func IntInclude(vs []int, t int) bool
IntInclude returns true if the provided int value exists in the provided int slice.
func IntIndex ¶ added in v0.4.0
func IntIndex(vs []int, t int) int
IntIndex returns the first index of the provided int value in the provided int slice. It returns -1 if it is not found.
func IsFsPathCaseSensitive ¶ added in v0.8.0
func IsFsPathCaseSensitive(path string) (bool, error)
IsFsPathCaseSensitive checks the fs of the given path to see if it is case sensitive if the case sensitivity can not be determined false and an error != nil are returned
func IsPathInDir ¶ added in v0.5.0
func IsPathInDir(dir, pathToCheck string) bool
IsPathInDir returns true if pathToCheck is within dir.
func IsTrue ¶ added in v0.6.0
func IsTrue(b *bool) bool
IsTrue returns true if the bool pointer is not nil and true.
func IsValidFloat64 ¶
func IsValidFloat64(value float64) bool
IsValidFloat64 ensures the given value is a valid number (not NaN) which is not equal to 0
func IsZipFileUncompressed ¶ added in v0.2.0
func IsZipFileUncompressed(path string) (bool, error)
IsZipFileUnmcompressed returns true if zip file in path is using 0 compression level
func ListDir ¶
func ListDir(path string) ([]string, error)
ListDir will return the contents of a given directory path as a string slice
func MD5FromBytes ¶
func MD5FromBytes(data []byte) string
func MD5FromFilePath ¶
func MD5FromFilePath(filePath string) (string, error)
func MD5FromReader ¶ added in v0.4.0
func MD5FromReader(src io.Reader) (string, error)
func MD5FromString ¶
func MD5FromString(str string) string
func MatchEntries ¶ added in v0.5.0
func MatchEntries(dir, pattern string) ([]string, error)
MatchEntries returns a string slice of the entries in directory dir which match the regexp pattern. On error an empty slice is returned MatchEntries isn't recursive, only the specific 'dir' is searched without being expanded.
func OSHashFromFilePath ¶ added in v0.3.0
func OSHashFromFilePath(filePath string) (string, error)
OSHashFromFilePath calculates the hash using the same algorithm that OpenSubtitles.org uses.
Calculation is as follows: size + 64 bit checksum of the first and last 64k bytes of the file.
func ParseDateStringAsFormat ¶
func ParseDateStringAsFormat(dateString string, format string) (string, error)
func ParseDateStringAsTime ¶
func ParseDateStringAsTime(dateString string) (time.Time, error)
func PhashToString ¶ added in v0.7.0
func PhashToString(phash int64) string
func ProcessBase64Image ¶
func ProcessBase64Image(imageString string) (string, []byte, error)
ProcessBase64Image transforms a base64 encoded string from a form post and returns the MD5 hash of the data and the image itself as a byte slice.
func ProcessImageInput ¶ added in v0.6.0
func ProcessImageInput(imageInput string) ([]byte, error)
ProcessImageInput transforms an image string either from a base64 encoded string, or from a URL, and returns the image as a byte slice
func RandomSequence ¶ added in v0.6.0
func RandomSequence(n int) string
func ReadImageFromURL ¶ added in v0.6.0
func ReadImageFromURL(url string) ([]byte, error)
ReadImageFromURL returns image data from a URL
func RemoveDir ¶
func RemoveDir(path string) error
RemoveDir removes the given dir (if it exists) along with all of its contents
func ServeFileNoCache ¶ added in v0.3.0
func ServeFileNoCache(w http.ResponseWriter, r *http.Request, filepath string)
ServeFileNoCache serves the provided file, ensuring that the response contains headers to prevent caching.
func ServeImage ¶ added in v0.3.0
func ServeImage(image []byte, w http.ResponseWriter, r *http.Request) error
func StrAppendUnique ¶ added in v0.7.0
func StrAppendUnique(vs []string, toAdd string) []string
StrAppendUnique appends toAdd to the vs string slice if toAdd does not already exist in the slice. It returns the new or unchanged string slice.
func StrAppendUniques ¶ added in v0.7.0
func StrAppendUniques(vs []string, toAdd []string) []string
StrAppendUniques appends a slice of string values to the vs string slice. It only appends values that do not already exist in the slice. It returns the new or unchanged string slice.
func StrDelete ¶ added in v0.8.0
func StrDelete(vs []string, toDel string) []string
StrDelete returns the vs string slice with toDel values removed.
func StrFormat ¶ added in v0.8.0
func StrFormat(format string, m StrFormatMap) string
StrFormat formats the provided format string, replacing placeholders in the form of "{fieldName}" with the values in the provided StrFormatMap.
For example,
StrFormat("{foo} bar {baz}", StrFormatMap{
"foo": "bar",
"baz": "abc",
})
would return: "bar bar abc"
func StrInclude ¶
func StrInclude(vs []string, t string) bool
func StrUnique ¶ added in v0.7.0
func StrUnique(vs []string) []string
StrUnique returns the vs string slice with non-unique values removed.
func StringSliceToIntSlice ¶ added in v0.3.0
func StringSliceToIntSlice(ss []string) ([]int, error)
StringSliceToIntSlice converts a slice of strings to a slice of ints. Returns an error if any values cannot be parsed.
func StringToPhash ¶ added in v0.8.0
func StringToPhash(s string) (int64, error)
func SymWalk ¶ added in v0.4.0
func SymWalk(path string, walkFn filepath.WalkFunc) error
SymWalk extends filepath.Walk to also follow symlinks
func Timeout ¶ added in v0.7.0
func Timeout(todo func(), waitTime time.Duration, onTimeout func(done chan struct{}))
Timeout executes the provided todo function, and waits for it to return. If the function does not return before the waitTime duration is elapsed, then onTimeout is executed, passing a channel that will be closed when the function returns.
func Touch ¶
func Touch(path string) error
Touch creates an empty file at the given path if it doesn't already exist
func ValueOnlyContext ¶ added in v0.8.0
func ValueOnlyContext(ctx context.Context) context.Context
Types ¶
type ByteRange ¶ added in v0.3.0
type ByteRange struct {
Start int64
End *int64
RawString string
}
func CreateByteRange ¶ added in v0.3.0
func CreateByteRange(s string) ByteRange
func (ByteRange) ToHeaderValue ¶ added in v0.3.0
func (r ByteRange) ToHeaderValue(fileLength int64) string
type Phash ¶ added in v0.7.0
type Phash struct {
SceneID int `db:"id"`
Hash int64 `db:"phash"`
Neighbors []int
Bucket int
}
type StrFormatMap ¶ added in v0.8.0
type StrFormatMap map[string]interface{}