util

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package util 常用方法集合。

包含配置、目录、编码、文件、网络、图片、文本、线程等多个方法集合。

Index

Constants

View Source
const (
	// TOKYOHOT 东京热网站名称常量
	TOKYOHOT = "東京熱"
	// FC2 fc2网站名称常量
	FC2 = "FC2"
	// HEYZO heyzo网站名称常量
	HEYZO = "HEYZO"
)
View Source
const (
	USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) " +
		"AppleWebKit/537.36 (KHTML, like Gecko) " +
		"Chrome/68.0.3440.106 Safari/537.36"
)

Variables

This section is empty.

Functions

func Base64

func Base64(file string) (string, error)

Base64 将指定文件编码为 Base64 字符串, 返回编码信息及错误信息。

file 字符串参数,传入文件路径

func CheckDomainPrefix

func CheckDomainPrefix(domain string) string

CheckDomainPrefix 检查域名最后是否存在斜线并返回无斜线域名

domain 字符串,传入域名

func ConvertJPG

func ConvertJPG(sourceFile, newFile string) error

ConvertJPG 将图片转换为jpg格式,并返回错误信息

sourceFile 字符串,传入原始图片路径, newFile 字符串,传入转换后图片保存路径。

func Exists

func Exists(file string) bool

Exists 检查文件是否存在

func FailFile

func FailFile(file, fail string)

FailFile 将整理失败的文件存储到fail目录中

file 字符串参数,传入失败文件路径, fail 字符串参数,传入fail目录路径。

func GetCode

func GetCode(filename, filter string) string

GetCode 从文件中提取番号信息

filename 字符串,传入要提取的文件名称, filter 字符串,要对文件名称进行过滤的规则信息。

func GetFileSize

func GetFileSize(file string) int64

GetFileSize 获取指定文件大小,失败则返回0

file 字符串参数,传入文件路径

func GetLargeSample added in v1.0.9

func GetLargeSample(img string) string

图片样图大图

func GetNumberPath

func GetNumberPath(replaceStr map[string]string, cfg *ConfigStruct) string

GetNumberPath 通过配置信息,获取到正确的保存路径

replaceStr map对象,通过转换后的媒体各项数据, cfg 配置信息,用以读取保存路径规则。

func GetResult

func GetResult(uri, proxy string, cookies []*http.Cookie) ([]byte, error)

GetResult 获取远程字节集数据,并返回字节集数据及错误信息

uri 字符串参数,传入请求地址, proxy 字符串参数,传入代理地址, cookies cookie数组,传入cookie信息。

func GetRoot

func GetRoot(uri, proxy string, cookies []*http.Cookie) (*goquery.Document, error)

GetRoot 获取远程树结构,并返回树结构及错误信息

uri 字符串参数,传入请求地址, proxy 字符串参数,传入代理地址, cookies cookie数组,传入cookie信息。

func GetRunPath

func GetRunPath() string

GetRunPath 获取程序当前执行路径

func IntroFilter

func IntroFilter(intro string) string

IntroFilter 简介信息过滤

func MD5String

func MD5String(str string) string

MD5String 将指定字符串加密为 md5, 返回加密后的 md5 字符串。

str 字符串参数,传入要加密的字符串

func MakeRequest

func MakeRequest(
	method, uri, proxy string,
	body io.Reader,
	header map[string]string,
	cookies []*http.Cookie) (
	data []byte,
	status int,
	err error)

MakeRequest 创建一个远程请求对象

请求参数:

method 字符串参数,传入请求类型, uri 字符串参数,传入请求地址, proxy 字符串参数,传入代理地址, body io读取接口,传入远程内容对象, header map结构,传入头部信息, cookies cookie数组,传入cookie信息。

返回数据:

data 字节集,返回读取到的内容字节集, status 整数,返回请求状态码, err 错误信息。

func MoveFile

func MoveFile(oldPath, newPath string) error

MoveFile 移动文件到指定路径,并返回错误信息

oldPath 字符串参数,传入文件原始路径, newPath 字符串参数,传入文件移动路径。

func NewIGout added in v1.0.13

func NewIGout(useragent, cookies, proxy string) *igout

func NewSave

func NewSave() *save

func PosterCover

func PosterCover(srcPhoto, newPhoto string, cfg *ConfigStruct) error

PosterCover 将指定图片进行裁剪,并返回错误信息

scrPhoto 字符串,要裁剪的图片路径, newPhoto 字符串,裁剪后的图片保存路径, cfg 配置信息,主要用于读取腾讯API信息。

func SavePhoto

func SavePhoto(uri, savePath, proxy string, needConvert bool) error

SavePhoto 下载远程图片到本地,并返回错误信息

uri 字符串参数,远程图片地址, savePath 字符串参数,本地保存路径, proxy 字符串参数,代理地址, needConvert 逻辑参数,是否需要将图片转换为jpg。

func WalkDir

func WalkDir(dirPath, success, fail string) ([]string, error)

WalkDir 遍历指定目录下的视频文件, 返回文件路径列表及错误信息。

dirPath 字符串参数,传入要遍历的目录路径, success 字符串参数,传入要过滤的success目录名称, fail 字符串参数,传入要过滤的fail目录名称。

func WriteFile

func WriteFile(file string, data []byte) error

WriteFile 将字节集数据写入到指定文件中,并返回错误信息

file 字符串参数,传入写入文件路径, data 字节集参数,传入写入的数据。

Types

type BaseStruct

type BaseStruct struct {
	Proxy  string // 代理地址
	Socket string // 代理地址
}

BaseStruct 配置信息基础节点

type ConfigStruct

type ConfigStruct struct {
	Base  BaseStruct  // 基础配置
	Path  PathStruct  // 路径配置
	Media MediaStruct // 媒体库配置
	Site  SiteStruct  // 免翻地址配置
}

ConfigStruct 程序配置信息结构

func GetConfig

func GetConfig() (*ConfigStruct, error)

GetConfig 读取配置信息,返回配置信息对象, 若没有配置文件,则创建一份默认配置文件并读取返回。

func WriteConfig

func WriteConfig() (*ConfigStruct, error)

WriteConfig 在程序执行路径下写入一份默认配置文件, 若写入成功则返回配置信息,若写入失败,则返回错误信息。

type MediaStruct

type MediaStruct struct {
	Library   string // 媒体库类型
	URL       string // Emby访问地址
	API       string // Emby API Key
	SecretID  string // 腾讯云 SecretId
	SecretKey string // 腾讯云 SecretKey
}

MediaStruct 配置信息媒体库节点

type PathStruct

type PathStruct struct {
	PathIn     string // 执行目录
	IsTransfer bool   // 是否转移视频到成功和失败目录, 只想重新搜刮,不像转移视频
	Success    string // 成功存储目录
	Fail       string // 失败存储目录
	Directory  string // 影片存储路径格式
	Filter     string // 文件名过滤规则
}

PathStruct 配置信息路径节点

type SiteStruct

type SiteStruct struct {
	JavBus string // javbus免翻地址
	JavDB  string // javdb免翻地址
}

SiteStruct 配置信息网站节点

type WaitGroup

type WaitGroup struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

WaitGroup 线程池

func NewWaitGroup

func NewWaitGroup(parallel int) (w *WaitGroup)

NewWaitGroup returns a pointer to a new `WaitGroup` object. parallel 为最大并发数, 0 代表无限制

func (*WaitGroup) AddDelta

func (w *WaitGroup) AddDelta()

AddDelta sync.WaitGroup.Add(1)

func (*WaitGroup) Done

func (w *WaitGroup) Done()

Done sync.WaitGroup.Done()

func (*WaitGroup) Parallel

func (w *WaitGroup) Parallel() int

Parallel 返回当前正在进行的任务数量

func (*WaitGroup) Wait

func (w *WaitGroup) Wait()

Wait 参照 sync.WaitGroup 的 Wait 方法

Jump to

Keyboard shortcuts

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