Documentation
¶
Index ¶
- Constants
- Variables
- func AddInterceptors(interceptors ...Interceptor)
- func CreateCache(domain Domain, gMeta *GalleryMetadata, pageUrls []string) (cache *cacheGallery, err error)
- func CreateCacheFromUrl(ctx context.Context, gUrl string) (cache *cacheGallery, err error)
- func DeleteCache(gId int) (err error)
- func DownloadCoversIter(ctx context.Context, results coverProviders) iter.Seq2[Image, error]
- func DownloadCoversTo(ctx context.Context, results coverProviders, f func(int, Image, error)) error
- func DownloadGalleryIter(ctx context.Context, galleryUrl string, pageNums ...int) iter.Seq2[PageData, error]
- func DownloadPagesIter(ctx context.Context, pageUrls ...string) iter.Seq2[PageData, error]
- func DownloadPagesTo(ctx context.Context, pageUrls []string, f func(int, PageData, error)) error
- func EhTagDbOk() bool
- func FetchGalleryPageUrls(ctx context.Context, galleryUrl string) (pageUrls []string, err error)deprecated
- func FreeEhTagDb()
- func GetCache(gId int) *cacheGallery
- func InitEhTagDb() error
- func MetaCacheRead(gId int) *metaCache
- func RegisterIgneousUpdate(f func(igneous string))
- func SetAcceptIgneousMystery(b bool)
- func SetAutoCacheEnabled(b bool)
- func SetCacheDir(dir string)
- func SetCookie(memberId, passHash, igneous, sk string)
- func SetCookieFromString(s string) (n int, err error)
- func SetCustomIpProvider(iPprovider IpProvider)
- func SetDomainFronting(b bool)
- func SetInterceptors(interceptors ...Interceptor)
- func SetMetadataCacheEnabled(b bool)
- func SetRetryDepth(depth int)
- func SetThreads(n int)
- func SetUseEnvProxy(b bool)
- func Translate(tag string) string
- func TranslateMulti(tags []string) []string
- func UnmarshalEhTagDb(data string) error
- func WaitForWrite()
- type CacheGalleryMetadata
- type CachePageInfo
- type CachePageInfos
- type CacheState
- type Category
- type Domain
- type DomainFrontingCtxKey
- type DomainFrontingCtxValue
- type DomainFrontingInterceptor
- type EHRoundRobinIpProvider
- type EhTagDatabase
- func (db *EhTagDatabase) Free()
- func (db *EhTagDatabase) Info() map[string]int
- func (db *EhTagDatabase) Init() error
- func (db *EhTagDatabase) Ok() bool
- func (db *EhTagDatabase) Translate(tag string) string
- func (db *EhTagDatabase) TranslateMulti(tags []string) []string
- func (db *EhTagDatabase) TranslateTag(tag Tag) Tag
- func (db *EhTagDatabase) TranslateTags(tags []Tag) []Tag
- func (db *EhTagDatabase) Unmarshal(data string) error
- type Error
- type FSearchResult
- type FSearchResults
- func EHSearch(ctx context.Context, keyword string, categories ...Category) (total int, results FSearchResults, err error)deprecated
- func ExHSearch(ctx context.Context, keyword string, categories ...Category) (total int, results FSearchResults, err error)deprecated
- func FSearch(ctx context.Context, url Url, keyword string, categories ...Category) (total int, results FSearchResults, err error)
- type GIdList
- type Gallery
- type GalleryDetails
- type GalleryMetadata
- type GalleryMetadataRequest
- type GalleryMetadataResponse
- type GalleryMetadatas
- func EHSearchDetail(ctx context.Context, keyword string, categories ...Category) (total int, galleries GalleryMetadatas, err error)deprecated
- func ExHSearchDetail(ctx context.Context, keyword string, categories ...Category) (total int, galleries GalleryMetadatas, err error)deprecated
- func SearchDetail(ctx context.Context, url Url, keyword string, categories ...Category) (total int, galleries GalleryMetadatas, err error)
- type GalleryTokenRequest
- type GalleryTokenResponse
- type Image
- type ImageType
- type Interceptor
- type InterceptorRoundTrip
- type IpProvider
- type Page
- type PageData
- type PageList
- type Tag
- type TagSet
- type Tags
- type TokenList
- type Torrent
- type Url
Constants ¶
const ( DEFAULT_CACHE_DIR = `EHentaiCache` METADATA_FILE_NAME = `metadata` )
const ( ENV_COOKIE = "EHENTAI_COOKIE" // OR ENV_COOKIE_IPB_MEMBER_ID = "EHENTAI_COOKIE_IPB_MEMBER_ID" ENV_COOKIE_IPB_PASS_HASH = "EHENTAI_COOKIE_IPB_PASS_HASH" ENV_COOKIE_IGNEOUS = "EHENTAI_COOKIE_IGNEOUS" ENV_COOKIE_SK = "EHENTAI_COOKIE_SK" ENV_DOMAIN_FRONTING = "EHENTAI_DOMAIN_FRONTING" )
const API_URL = `https://api.e-hentai.org/api.php`
const CATEGORY_COUNT = 10
const EHTAG_DATABASE_URL = `https://github.com/EhTagTranslation/Database/releases/latest/download/db.text.json`
Variables ¶
var ( ErrNoGalleryProvided = errors.New("no gallery provided") ErrNoPageProvided = errors.New("no page provided") )
var ( ErrFailedToGetGalleryMetadata = errors.New("failed to get gallery metadata") ErrMismatchPageUrls = errors.New("mismatch page urls") ErrGalleryMetadataError = errors.New("gallery metadata error") ErrEmptyCache = errors.New("empty cache") ErrEmptyData = errors.New("empty data") ErrInvalidCacheMetadata = errors.New("invalid cache metadata") ErrInvalidPageNum = errors.New("invalid page number") ErrUnknownImageType = errors.New("unknown image type") ErrPageNotCached = errors.New("page not cached") )
var ( ErrNoPageUrlProvided = errors.New("no page url provided") ErrNoImageUrlProvided = errors.New("no image url provided") ErrTooManyGIds = errors.New("too many gallery ids") ErrInvalidContentType = errors.New("invalid content type") ErrEmptyBody = errors.New("empty body") ErrFoundEmptyImageData = errors.New("found empty image data") )
var ( ErrSadPanda = errors.New("sad panda") ErrIpBanned = errors.New("ip banned") ErrNoHitsFound = errors.New("no hits found") ErrRegMismatch = errors.New("regexp mismatch") ErrRegEmptyMatch = errors.New("regexp empty match") ErrNoResult = errors.New("no result") ErrEmptyTable = errors.New("empty table") ErrNoImage = errors.New("no image") ErrEndGreaterThanTotal = errors.New("end > total") ErrFoundEmptyPageUrl = errors.New("found empty page url") ErrNotANumber = errors.New("not a number") )
var ErrDownloadUnreachableCase = fmt.Errorf("download: unreachable case")
var ErrInvalidTag = errors.New("invalid tag")
var ErrUnknownCategory = errors.New("unknown category")
Functions ¶
func AddInterceptors ¶
func AddInterceptors(interceptors ...Interceptor)
func CreateCache ¶
func CreateCache(domain Domain, gMeta *GalleryMetadata, pageUrls []string) (cache *cacheGallery, err error)
CreateCache 覆盖创建画廊缓存元数据
domain 为空时使用 EXHENTAI_DOMAIN
pageUrls 需要完整以保证读取失败时直接下载, 不提供时尝试从缓存中读取
func CreateCacheFromUrl ¶
CreateCacheFromUrl 从画廊 url 覆盖创建缓存
func DeleteCache ¶
func DownloadCoversIter ¶
DownloadCoversIter 以迭代器模式通过搜索结果下载封面
func DownloadCoversTo ¶ added in v0.0.3
DownloadCoversTo 完全异步地通过搜索结果下载封面
func DownloadGalleryIter ¶
func DownloadGalleryIter(ctx context.Context, galleryUrl string, pageNums ...int) iter.Seq2[PageData, error]
DownlaodGalleryIter 以迭代器模式下载画廊下所有图片, 下载失败时自动尝试备链
不传入 pageNums 参数时下载所有页, 传入时按其顺序下载指定页, 重复、越界页将被忽略
func DownloadPagesIter ¶
DownloadPagesIter 以迭代器模式下载画廊某页的图片, 下载失败时自动尝试备链
func DownloadPagesTo ¶ added in v0.0.3
DownloadGalleryTo 完全异步地下载画廊下所有图片, 下载失败时自动尝试备链
func FetchGalleryPageUrls
deprecated
FetchGalleryPageUrls 获取画廊下所有页链接
Deprecated: use FetchGalleryDetails GalleryDetails.PageUrls instead
func MetaCacheRead ¶
func MetaCacheRead(gId int) *metaCache
MetaCacheRead 从缓存中读取画廊元数据与页链接
gallery 与 pageUrls 不一定同时存在
TODO: cache switch to [gDetailsCache]
func RegisterIgneousUpdate ¶ added in v0.0.3
func RegisterIgneousUpdate(f func(igneous string))
RegisterIgneousUpdate 注册 igneous 更新时的回调通知
回调函数将在独立协程中执行
func SetAcceptIgneousMystery ¶ added in v0.0.3
func SetAcceptIgneousMystery(b bool)
SetAcceptIgneousMystery 设置是否接受 exhentai 下发的 igneous=mystery
默认为 false
func SetAutoCacheEnabled ¶
func SetAutoCacheEnabled(b bool)
SetAutoCacheEnabled 设置自动缓存启用状态
默认为 false
启用时会同时启用元数据缓存
下载画廊时: 自动缓存所有下载的页
下载页时: 存在该画廊的缓存时, 自动缓存所下载的页
func SetCacheDir ¶
func SetCacheDir(dir string)
SetCacheDir 设置缓存文件夹路径
留空默认为 "./EHentaiCache/"
路径形如 "EHentaiCache/3138775/metadata", "EHentaiCache/3138775/1.webp", "EHentaiCache/3138775/2.webp"...
func SetCookie ¶
func SetCookie(memberId, passHash, igneous, sk string)
SetCookie 设置 cookie, 访问 exhentai 时必需
func SetCustomIpProvider ¶
func SetCustomIpProvider(iPprovider IpProvider)
SetCustomIpProvider 自定义域名前置所使用的 ip 获取器
func SetInterceptors ¶
func SetInterceptors(interceptors ...Interceptor)
func SetMetadataCacheEnabled ¶
func SetMetadataCacheEnabled(b bool)
SetMetadataCacheEnabled 设置元数据缓存启用状态
默认为 true
以避免频繁请求官方 api
func SetUseEnvProxy ¶ added in v0.0.3
func SetUseEnvProxy(b bool)
SetUseEnvProxy 设置是否使用系统环境变量中的代理
默认为 true
func TranslateMulti ¶
TranslateMulti 翻译多个 tag, 输入格式应为: namespace:tag, 若数据库未初始化, 则返回入参
func UnmarshalEhTagDb ¶ added in v0.1.0
UnmarshalEhTagDb 使用外部的 json 数据反序列化至 EhTagTranslation 数据库
主要用于 cli 在外部缓存文件
func WaitForWrite ¶ added in v0.0.3
func WaitForWrite()
Types ¶
type CacheGalleryMetadata ¶
type CacheGalleryMetadata struct {
Url string `json:"url"` // 画廊 URL
Gallery GalleryMetadata `json:"gallery"`
// PageUrls []string `json:"page_urls"`
// 画廊所有页的 URL, 读取缓存图片出错时可以直接用
// 保证一定存在
PageUrls map[string]string `json:"page_urls"`
Files struct {
Dir string `json:"dir"` // 画廊路径 `root/gid/`
Count int `json:"count"` // 缓存数量
TotalLen int `json:"total_len"` // 缓存总大小
Pages CachePageInfos `json:"pages"` // 缓存的页码列表
} `json:"files"` // 缓存文件列表
}
type CachePageInfo ¶
type CachePageInfos ¶
type CachePageInfos []CachePageInfo
func (*CachePageInfos) Exts ¶ added in v0.0.2
func (cpi *CachePageInfos) Exts() []ImageType
Exts 返回存在的图片扩展名
func (*CachePageInfos) Get ¶
func (cpi *CachePageInfos) Get(pageNum int) (pageInfo CachePageInfo)
Get 返回页码对应的缓存信息
Len 为 0 表示不存在
func (*CachePageInfos) Lookup ¶
func (cpi *CachePageInfos) Lookup(pageNums []int) (pageInfos CachePageInfos)
Lookup 构造哈希表查找页码
len(pageNums) == 0 时返回所有
len(pageInfos) == len(pageNums) , 对应页不存在时 Len 为 0
type CacheState ¶
type CacheState int
const ( CACHE_STATE_UNKNOWN CacheState = iota CACHE_STATE_NONE CACHE_STATE_PARTIAL CACHE_STATE_FULL )
func (CacheState) String ¶
func (cs CacheState) String() string
type DomainFrontingCtxValue ¶
for context kv
type DomainFrontingInterceptor ¶
type DomainFrontingInterceptor struct {
Enabled bool
IpProvider IpProvider
}
DomainFrontingInterceptor 用于实现 e-hentai 的域名前置功能
func (*DomainFrontingInterceptor) OnError ¶
func (d *DomainFrontingInterceptor) OnError(req *http.Request, err error)
func (*DomainFrontingInterceptor) OnRequest ¶
func (d *DomainFrontingInterceptor) OnRequest(req *http.Request) error
func (*DomainFrontingInterceptor) OnResponse ¶
func (d *DomainFrontingInterceptor) OnResponse(resp *http.Response) error
type EHRoundRobinIpProvider ¶
type EHRoundRobinIpProvider struct {
// contains filtered or unexported fields
}
EHRoundRobinIpProvider 用于轮询提供 e-hentai 相关域名的 ip
func (*EHRoundRobinIpProvider) AddUnavailableIp ¶
func (p *EHRoundRobinIpProvider) AddUnavailableIp(host, ip string)
func (*EHRoundRobinIpProvider) NextIp ¶
func (p *EHRoundRobinIpProvider) NextIp(host string) (ip string)
func (*EHRoundRobinIpProvider) Supports ¶
func (p *EHRoundRobinIpProvider) Supports(host string) bool
type EhTagDatabase ¶
map[namespace]map[<tag>]name
func (*EhTagDatabase) Free ¶
func (db *EhTagDatabase) Free()
func (*EhTagDatabase) Init ¶
func (db *EhTagDatabase) Init() error
func (*EhTagDatabase) Ok ¶
func (db *EhTagDatabase) Ok() bool
func (*EhTagDatabase) Translate ¶
func (db *EhTagDatabase) Translate(tag string) string
func (*EhTagDatabase) TranslateMulti ¶
func (db *EhTagDatabase) TranslateMulti(tags []string) []string
func (*EhTagDatabase) TranslateTag ¶ added in v0.0.3
func (db *EhTagDatabase) TranslateTag(tag Tag) Tag
func (*EhTagDatabase) TranslateTags ¶ added in v0.0.3
func (db *EhTagDatabase) TranslateTags(tags []Tag) []Tag
func (*EhTagDatabase) Unmarshal ¶
func (db *EhTagDatabase) Unmarshal(data string) error
Unmarshal 解析 json 到数据库
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error 附带了更详细的信息
ehErr := EHentai.UnwarpErr(err) isXxx := ehErr.Is(EHentai.ErrXXX)
-
type FSearchResult ¶
type FSearchResult struct {
Domain Domain
Gallery
Cat string // 分类
Cover string // url
Posted string // "2006-01-02 15:04"
Rating float64 // 精确到 0.5
Url string // 画廊 URL
Title string // 根据 cookie 中的 sk, 结果可能为英文或日文
Tags []string // namespace:tag
Uploader string // 上传者
Pages int // 64
}
FSearchResult 来自搜索结果页
type FSearchResults ¶
type FSearchResults []FSearchResult
func FSearch ¶ added in v0.1.0
func FSearch(ctx context.Context, url Url, keyword string, categories ...Category) (total int, results FSearchResults, err error)
FSearch 搜索并返回基本信息, results 只有第一页的结果
func (FSearchResults) GetCover ¶
func (fsr FSearchResults) GetCover() (urls []string)
type Gallery ¶
Gallery describes the gallery url
https://e-hentai.org/g/{gallery_id}/{gallery_token}/
func UrlToGallery ¶
type GalleryDetails ¶ added in v0.0.3
type GalleryDetails struct {
Domain Domain
Gallery
Cover string // url
Title string // 英文标题
TitleJpn string // 日文标题
Cat string // 分类
Uploader string // 上传者
Posted string // "2006-01-02 15:04"
Parent int // galleryId, 0 for "None"
Visible string // "Yes" / "No (Replaced)"
Language string // "Chinese" / "Japanese"
Translated string // "TR" / ""
FileSize string // "449.9 MiB"
Length int // 65
Favorited int // 3745
RatingCount int // 271
Rating float64 // 4.86
// Tags []string // namespace:tag
Tags []Tag
PageUrls []string
}
GalleryDetails 来自画廊详情页
func DetailsCacheRead ¶ added in v0.0.3
func DetailsCacheRead(gId int) *GalleryDetails
func FetchGalleryDetails ¶ added in v0.0.3
func FetchGalleryDetails(ctx context.Context, galleryUrl string) (gallery GalleryDetails, err error)
FetchGalleryDetails 获取画廊详细信息与所有页链接
func (*GalleryDetails) GetCover ¶ added in v0.0.3
func (gd *GalleryDetails) GetCover() (urls []string)
type GalleryMetadata ¶
type GalleryMetadata struct {
GId int `json:"gid"`
Token string `json:"token"`
ArchiverKey string `json:"archiver_key"`
Title string `json:"title"`
TitleJpn string `json:"title_jpn"`
Category string `json:"category"`
Thumb string `json:"thumb"`
Uploader string `json:"uploader"`
Posted string `json:"posted"`
FileCount string `json:"filecount"`
FileSize int `json:"filesize"`
Expunged bool `json:"expunged"`
Rating string `json:"rating"`
TorrentCount string `json:"torrentcount"`
Torrents []Torrent `json:"torrents"`
Tags []string `json:"tags"`
ParentGId string `json:"parent_gid"`
ParentKey string `json:"parent_key"`
FirstGId string `json:"first_gid"`
FirstKey string `json:"first_key"`
Error string `json:"error,omitzero"`
}
GalleryMetadata 来自官方 api
type GalleryMetadataRequest ¶
type GalleryMetadataResponse ¶
type GalleryMetadataResponse struct {
GMetadata []GalleryMetadata `json:"gmetadata"`
}
func PostGalleryMetadata ¶
func PostGalleryMetadata(ctx context.Context, g ...GIdList) (resp *GalleryMetadataResponse, err error)
PostGalleryMetadata posts to the official API and returns gallery metadata
type GalleryMetadatas ¶
type GalleryMetadatas []GalleryMetadata
func EHSearchDetail
deprecated
func EHSearchDetail(ctx context.Context, keyword string, categories ...Category) (total int, galleries GalleryMetadatas, err error)
EHSearchDetail 搜索 EHentai 并返回详细信息, galleries 只有第一页结果
Deprecated: simply use SearchDetail instead
EHentai.SearchDetail(ctx, EHentai.EHENTAI_URL, keyword, categories...)
func ExHSearchDetail
deprecated
func ExHSearchDetail(ctx context.Context, keyword string, categories ...Category) (total int, galleries GalleryMetadatas, err error)
ExHSearchDetail 搜索 ExHentai 并返回详细信息, galleries 只有第一页结果
Deprecated: simply use SearchDetail instead
EHentai.SearchDetail(ctx, EHentai.EXHENTAI_URL, keyword, categories...)
func SearchDetail ¶ added in v0.1.0
func SearchDetail(ctx context.Context, url Url, keyword string, categories ...Category) (total int, galleries GalleryMetadatas, err error)
SearchDetail 搜索并返回详细信息, galleries 只有第一页的结果
func (GalleryMetadatas) GetCover ¶
func (gm GalleryMetadatas) GetCover() (urls []string)
type GalleryTokenRequest ¶
type GalleryTokenResponse ¶
type GalleryTokenResponse struct {
TokenLists []TokenList `json:"tokenlist"`
}
func PostGalleryToken ¶
func PostGalleryToken(ctx context.Context, p ...PageList) (*GalleryTokenResponse, error)
PostGalleryToken posts to the official API and returns gallery token
type Image ¶
func DownloadCovers ¶
DownloadCovers 通过搜索结果下载封面
type Interceptor ¶
type Interceptor interface {
OnRequest(req *http.Request) error // 返回 error 可中断请求
OnResponse(resp *http.Response) error // 返回 error 可中断请求
OnError(req *http.Request, err error)
}
Interceptor is used to modify the request and interpret the response
Implemented by DomainFrontingInterceptor
type InterceptorRoundTrip ¶
type InterceptorRoundTrip struct {
RoundTripper http.RoundTripper
Interceptors []Interceptor
}
InterceptorRoundTrip implements http.RoundTripper, but it WILL modify the request and interpret the response
func (*InterceptorRoundTrip) OnError ¶
func (i *InterceptorRoundTrip) OnError(req *http.Request, err error)
func (*InterceptorRoundTrip) OnRequest ¶
func (i *InterceptorRoundTrip) OnRequest(req *http.Request) error
func (*InterceptorRoundTrip) OnResponse ¶
func (i *InterceptorRoundTrip) OnResponse(resp *http.Response) error
type IpProvider ¶
IpProvider 用于轮询提供某个域名的 ip 地址
全都不可用时, NextIp 也应返回下一个 ip
Implemented by EHRoundRobinIpProvider
type Page ¶
type Page struct {
PageToken string `json:"page_token"`
GalleryId int `json:"gallery_id"`
PageNum int `json:"page_num"`
}
Page describes the page url
https://e-hentai.org/s/{page_token}/{gallery_id}-{pagenumber}
type PageData ¶
PageData carrys page info and image data
func DownloadGallery ¶
DownloadGallery 下载画廊下所有图片, 下载失败时自动尝试备链
不传入 pageNums 参数时下载所有页, 传入时按其顺序下载指定页, 重复、越界页将被忽略
func DownloadPages ¶
DownloadPages 下载画廊某页的图片, 下载失败时自动尝试备链
type Tag ¶ added in v0.0.3
func TranslateTag ¶ added in v0.0.3
type Tags ¶ added in v0.0.3
type Tags []Tag
func TranslateTags ¶ added in v0.0.3
func (Tags) Namespaces ¶ added in v0.0.3
type Url ¶ added in v0.1.0
type Url = string
const ( EHENTAI_URL Url = `https://` + EHENTAI_DOMAIN EXHENTAI_URL Url = `https://` + EXHENTAI_DOMAIN )