javdb

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 20 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package javdb is the public Go SDK for the JavDB app JSON API.

Index

Constants

View Source
const (
	HostMirror = settings.HostMirror
	HostMain   = settings.HostMain
)

Host constants.

Variables

This section is empty.

Functions

func ActorPeriod

func ActorPeriod(period string) string

ActorPeriod is a deprecated alias for RankingPeriod. Deprecated: Use RankingPeriod instead.

func FilterMagnets

func FilterMagnets(magnets []map[string]any, cnsub, hd bool, minSize int) []map[string]any

Re-export magnet helpers for SDK callers.

func ImageAssetFormat added in v0.8.0

func ImageAssetFormat(path string) (string, bool)

ImageAssetFormat 读取本地图片文件的头部字节,返回稳定格式名 (jpg/png/gif/webp/avif/heic),供 assets download 在下载后确定最终扩展名。 文件缺失或不是已验证的图片格式时返回 false。

func LoadOrCreateDeviceUUID

func LoadOrCreateDeviceUUID(path string) (string, error)

LoadOrCreateDeviceUUID loads the stable device identifier at path or creates one when the file is absent. CLI callers use it before constructing a client; SDK callers may use it when they need the same identifier across processes.

func MagnetURI

func MagnetURI(m map[string]any) string

func MovieAssetDescriptions added in v0.8.0

func MovieAssetDescriptions(movie map[string]any) []string

MovieAssetDescriptions 返回与 MovieAssetsFromDetail 同序的 TTY 描述文本 (thumbnail / cover / preview N / preview)。 描述仅供 assets list 的人类渲染,不属于 MovieAsset 数据模型, 不得进入 JSON/pipe 输出或任何持久化状态。跳过的项不占 preview 编号。

func PickBestMagnet

func PickBestMagnet(magnets []map[string]any) map[string]any

func RankMagnets added in v0.7.2

func RankMagnets(magnets []map[string]any, count int) []map[string]any

RankMagnets 按优先规则(cnsub > hd > size > files_count)稳定排序磁力列表 并按 count 截取。count <= 0 返回全部排序结果;count > 0 返回前 count 项。 不修改输入切片。

func RankingPeriod added in v0.5.1

func RankingPeriod(period string) string

RankingPeriod re-export.

Types

type APIError

type APIError = appapi.Error

Error aliases for callers.

type AuthRequired

type AuthRequired = appapi.AuthRequired

Error aliases for callers.

type AutoHostOptions added in v0.6.0

type AutoHostOptions struct {
	PreferredHost string
	Proxy         string
	DeviceUUID    string
	Timeout       time.Duration // 每次 probe 请求的 timeout;零值沿用 transport 默认值。
	Lang          string
}

AutoHostOptions 配置显式自动线路选择。PreferredHost 是调用方提供的待验证候选 (通常来自上次选线的 route cache);SDK 不负责持久化。

type AutoHostResult added in v0.6.0

type AutoHostResult struct {
	Host            string
	Latency         time.Duration
	ReusedPreferred bool
}

AutoHostResult 是自动选线结果。Latency 是缓存验证成功或全量测速赢家的单次 /startup 耗时。调用方用 javdb.New(WithHost(result.Host), ...) 构造业务客户端。

func SelectAutoHost added in v0.6.0

func SelectAutoHost(ctx context.Context, options AutoHostOptions) (AutoHostResult, error)

SelectAutoHost 通过真实 /startup 探测选择最快的 JavDB App API host。

它显式联网选线,返回具体 URL;不会让 javdb.New(WithHost("auto")) 自动联网。调用方应先 验证 route cache 中的 PreferredHost,成功后(ReusedPreferred==true)无需写入新结果; 重测选择时再把 result.Host 持久化。

type BrowseOptions

type BrowseOptions = appapi.BrowseOptions

BrowseOptions re-export.

type Client

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

Client is a concrete app-API client.

func New

func New(opts ...Option) (*Client, error)

New builds a Client.

func (*Client) API

func (c *Client) API() *appapi.Client

API 为兼容旧调用方返回底层 adapter。该返回值不是稳定的外部 SDK 契约;新代码应优先使用 typed 方法。 Deprecated: use the documented Client methods instead.

func (*Client) AllEntityMovies

func (c *Client) AllEntityMovies(ctx context.Context, kind, entityID string, opt EntityMoviesOptions, maxPages int) ([]map[string]any, error)

AllEntityMovies aggregates filmography pages.

func (*Client) Browse

func (c *Client) Browse(ctx context.Context, opt BrowseOptions) (SearchResult, error)

Browse lists movies by category filters.

func (*Client) CheckAuth added in v0.8.5

func (c *Client) CheckAuth(ctx context.Context) error

CheckAuth verifies the current token with the server without refreshing or persisting it.

func (*Client) Collected

func (c *Client) Collected(ctx context.Context, kind string) ([]map[string]any, error)

Collected returns a user collection kind.

func (*Client) DownloadMovieAsset added in v0.8.0

func (c *Client) DownloadMovieAsset(ctx context.Context, asset MovieAsset, target string) (int64, error)

DownloadMovieAsset 下载单个影片资产到 target 路径,返回写入字节数。 image:下载 → 必要时 XOR 解包 → 图片魔数校验 → 原子写入,不做任何格式转换。 video:输出格式由 target 后缀决定——.ts 保留解密校验后的 MPEG-TS, .mp4 输出 Fast Start MP4(纯 remux,不转码);其余后缀明确拒绝。 ctx 贯穿全部阶段,取消时立即停止网络与媒体处理,不留输出文件。

func (*Client) EntityDetail

func (c *Client) EntityDetail(ctx context.Context, kind, id string) (map[string]any, error)

EntityDetail fetches entity meta.

func (*Client) EntityMovies

func (c *Client) EntityMovies(ctx context.Context, kind, entityID string, opt EntityMoviesOptions) (SearchResult, error)

EntityMovies lists filmography for an entity kind.

func (*Client) ListInfo

func (c *Client) ListInfo(ctx context.Context, listID string) (map[string]any, error)

ListInfo returns list meta payload.

func (*Client) LoadOrRefreshTaxonomy

func (c *Client) LoadOrRefreshTaxonomy(ctx context.Context, zone string, force bool) (*tags.Doc, string, error)

LoadOrRefreshTaxonomy loads disk taxonomy or refreshes.

func (*Client) Login

func (c *Client) Login(ctx context.Context, username, password string) (string, error)

Login authenticates and stores the token on the client. ctx is reserved for future cancellation; the underlying client is not yet context-aware.

func (*Client) Mark

func (c *Client) Mark(ctx context.Context, movieID, status string, score int, content string) (map[string]any, error)

Mark marks a movie watched or want_watch.

func (*Client) MovieAssets added in v0.8.0

func (c *Client) MovieAssets(ctx context.Context, movieID string) ([]MovieAsset, error)

MovieAssets 按固定顺序返回影片详情中的资产序列: thumbnail → cover(若详情提供)→ preview_images[](large_url 优先,回退 thumb_url)→ preview video。 详情中缺失的项直接跳过,因此序列长度随影片而变。

func (*Client) MovieComments

func (c *Client) MovieComments(ctx context.Context, movieID string, page, limit int) ([]map[string]any, error)

MovieComments returns one requested page from GET /api/v1/movies/{id}/reviews. It never follows later pages automatically.

func (*Client) MovieDetail

func (c *Client) MovieDetail(ctx context.Context, movieID string) (map[string]any, error)

MovieDetail returns GET /api/v4/movies/{id} nested movie map.

func (*Client) MovieMagnets

func (c *Client) MovieMagnets(ctx context.Context, movieID string) ([]map[string]any, error)

MovieMagnets returns GET /api/v1/movies/{id}/magnets (works anonymously).

func (*Client) MyLists

func (c *Client) MyLists(ctx context.Context, page, limit int, sortBy string) (SearchResult, error)

MyLists returns the current user's playlists (auth).

func (*Client) ProbeMovieAssets added in v0.8.0

func (c *Client) ProbeMovieAssets(ctx context.Context, assets []MovieAsset, options MovieAssetProbeOptions) ([]MovieAssetInfo, error)

ProbeMovieAssets 以固定 worker pool 探测媒体元数据,保持输入顺序并按 Type+URL 去重。 单项媒体错误保留零值并继续;父 context 取消或截止时间会终止整个调用。

func (*Client) RankingsActors

func (c *Client) RankingsActors(ctx context.Context, period string) (SearchResult, error)

RankingsActors fetches actor rankings; period accepts day|week|month or daily|weekly|monthly.

func (*Client) RankingsMovies

func (c *Client) RankingsMovies(ctx context.Context, type_, period string) (SearchResult, error)

RankingsMovies fetches movie rankings.

func (*Client) RankingsPlayback

func (c *Client) RankingsPlayback(ctx context.Context, filterBy, period string) (SearchResult, error)

RankingsPlayback fetches playback rankings.

func (*Client) RecentViewed

func (c *Client) RecentViewed(ctx context.Context) ([]map[string]any, error)

RecentViewed returns recently viewed movies.

func (*Client) RefreshTagTaxonomy

func (c *Client) RefreshTagTaxonomy(ctx context.Context, zone string) (*tags.Doc, error)

RefreshTagTaxonomy downloads EN+ZH taxonomies and saves tags-{zone}.json.

func (*Client) RelatedLists

func (c *Client) RelatedLists(ctx context.Context, movieID string, page, limit int) (SearchResult, error)

RelatedLists returns public lists related to a movie.

func (*Client) ResolveEntity

func (c *Client) ResolveEntity(ctx context.Context, kind, ref, zone string) (string, error)

ResolveEntity resolves name/id to entity id.

func (*Client) ResolveMovieID

func (c *Client) ResolveMovieID(ctx context.Context, number string) (string, error)

ResolveMovieID maps a printed number to internal id (search zone=all).

func (*Client) ResolveMovieIDExact added in v0.7.0

func (c *Client) ResolveMovieIDExact(ctx context.Context, number string) (string, error)

ResolveMovieIDExact 使用 zone=all 搜索,只接受大小写不敏感的完整相等番号; 零匹配与多重精确匹配都显式失败,不允许模糊搜索首项回退。

func (*Client) ResolveTags

func (c *Client) ResolveTags(ctx context.Context, refs []string, zone string) ([]string, error)

ResolveTags maps free-form tag refs to ids.

func (*Client) ResolveUserID

func (c *Client) ResolveUserID(ctx context.Context) (userID int64, username string, err error)

ResolveUserID returns the numeric user id (and optional display name) for the current token.

func (*Client) ReverseSearch added in v0.7.0

func (c *Client) ReverseSearch(ctx context.Context, request ReverseSearchRequest) (ReverseSearchResponse, error)

ReverseSearch 上传原始图片并返回规范化候选。Source 为空时使用内置 AVScan provider。provider 顶层失败返回 error;缓存命中时跳过 provider。

func (*Client) Search

func (c *Client) Search(ctx context.Context, keyword string, opt SearchOptions) (SearchResult, error)

Search runs GET /api/v2/search.

func (*Client) SearchByImage added in v0.7.0

func (c *Client) SearchByImage(ctx context.Context, request ReverseSearchRequest, opts ImageSearchOptions) (ImageSearchResult, error)

SearchByImage 反搜并对全部候选并发执行严格番号解析与(可选)完整详情; 结果按 provider 原始顺序恢复。候选级失败写入 ImageSearchMatch.Error 并继续, provider 顶层失败直接返回 error。opts.SkipMovieDetail 为 true 时跳过完整详情 请求,仅保留 movie ID(用于纯 ref/磁力路径)。

func (*Client) SetToken

func (c *Client) SetToken(token string)

SetToken updates the bearer token.

func (*Client) Token

func (c *Client) Token() string

Token returns the current bearer token.

func (*Client) Top250

func (c *Client) Top250(ctx context.Context, zone, year string, startRank, page, limit int, ignoreWatched bool) (SearchResult, error)

Top250 fetches TOP250 (auth).

func (*Client) Unmark

func (c *Client) Unmark(ctx context.Context, movieID string) (bool, error)

Unmark removes the user's review mark.

func (*Client) WantMovies

func (c *Client) WantMovies(ctx context.Context) ([]map[string]any, error)

WantMovies returns all want_watch (想看) movies.

func (*Client) WatchedMovies

func (c *Client) WatchedMovies(ctx context.Context) ([]map[string]any, error)

WatchedMovies returns all watched (看過) movies.

type EntityMoviesOptions

type EntityMoviesOptions = appapi.EntityMoviesOptions

EntityMoviesOptions re-export.

type ImageMovieResolver added in v0.8.5

type ImageMovieResolver interface {
	ResolveMovieIDExact(context.Context, string) (string, error)
	MovieDetail(context.Context, string) (map[string]any, error)
}

ImageMovieResolver provides the movie lookups used to link reverse-search candidates. Implementations may apply caller-owned authentication without repeating the provider request.

type ImageSearchError added in v0.7.0

type ImageSearchError struct {
	Stage   string `json:"stage"`
	Code    string `json:"code"`
	Message string `json:"message"`
}

ImageSearchError 是单候选联动失败的稳定错误。

func (*ImageSearchError) Error added in v0.7.0

func (e *ImageSearchError) Error() string

type ImageSearchMatch added in v0.7.0

type ImageSearchMatch struct {
	Candidate ReverseSearchCandidate `json:"candidate"`
	MovieID   string                 `json:"movie_id,omitempty"`
	Movie     map[string]any         `json:"movie,omitempty"`
	Error     *ImageSearchError      `json:"error,omitempty"`
}

ImageSearchMatch 是单个候选的联动结果;失败时 Error 非空。

type ImageSearchOptions added in v0.7.0

type ImageSearchOptions struct {
	// SkipMovieDetail 为 true 时只做严格番号 → ID 解析,跳过完整详情请求。
	// 用于纯 ref/磁力路径:magnets 只需要 movie ID 即可获取磁力列表,不需要
	// 完整详情。默认 false 保持现有行为(解析 ID + 完整详情)。
	SkipMovieDetail bool
}

ImageSearchOptions 控制候选到 JavDB 的联动解析。

type ImageSearchResult added in v0.7.0

type ImageSearchResult struct {
	ReverseSearch ReverseSearchResponse `json:"reverse_search"`
	Matches       []ImageSearchMatch    `json:"matches"`
}

ImageSearchResult 保留 provider 原始候选顺序。

func LinkImageCandidates added in v0.8.5

func LinkImageCandidates(ctx context.Context, resolver ImageMovieResolver, response ReverseSearchResponse, opts ImageSearchOptions) (ImageSearchResult, error)

LinkImageCandidates resolves candidates concurrently and preserves provider order and partial errors.

type MovieAsset added in v0.8.0

type MovieAsset struct {
	Type string `json:"type"`
	URL  string `json:"url"`
}

MovieAsset 是影片可下载媒体资产的最小描述。 Type 只有 "image" 或 "video";URL 是资产的获取地址。 刻意不包含 id/index/role 等元数据:编号只是 list 输出的位置,描述只是 TTY 渲染。

func MovieAssetsFromDetail added in v0.8.0

func MovieAssetsFromDetail(movie map[string]any) []MovieAsset

MovieAssetsFromDetail 把影片详情 map 转成资产序列(与 MovieAssetDescriptions 同序)。 详情无 typed struct(上层 API 返回 map[string]any),字段缺失/类型异常一律跳过。

type MovieAssetInfo added in v0.8.0

type MovieAssetInfo struct {
	Asset    MovieAsset         `json:"asset"`
	Metadata MovieAssetMetadata `json:"metadata"`
}

MovieAssetInfo 把稳定的下载身份与可选 probe metadata 分离。

type MovieAssetMetadata added in v0.8.0

type MovieAssetMetadata struct {
	Width    int `json:"width,omitempty"`
	Height   int `json:"height,omitempty"`
	Duration int `json:"duration,omitempty"`
}

MovieAssetMetadata 是通过读取资产媒体本身得到的 best-effort 元数据。 Duration 的单位是秒,仅用于 preview video;零值表示未知。

type MovieAssetProbeOptions added in v0.8.0

type MovieAssetProbeOptions struct {
	// Concurrency 为 0 时使用 settings.DefaultAssetProbeConcurrency;负数无效。
	Concurrency int
}

MovieAssetProbeOptions 控制媒体探测。

type Option

type Option func(*options)

Option configures New.

func WithDeviceUUID

func WithDeviceUUID(id string) Option

WithDeviceUUID sets the app device_uuid public param.

func WithHost

func WithHost(host string) Option

WithHost sets logical host (mirror|main) or absolute base URL.

func WithLang

func WithLang(lang string) Option

WithLang sets Accept-Language / app lang.

func WithProxy

func WithProxy(proxy string) Option

WithProxy sets an HTTP(S) proxy URL.

func WithReverseSearch added in v0.7.0

func WithReverseSearch(opts ReverseSearchOptions) Option

WithReverseSearch 注入反搜缓存与传输配置。javdb.New 本身仍不联网。

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets request timeout.

func WithToken

func WithToken(token string) Option

WithToken sets the bearer token.

type ReverseSearchCache added in v0.7.0

type ReverseSearchCache interface {
	Get(context.Context, string) (ReverseSearchResponse, bool, error)
	Put(context.Context, string, ReverseSearchResponse) error
}

ReverseSearchCache 是 SDK 可注入的响应缓存。key 是 "<source>:<原图 SHA-256 十六进制>"(source 隔离是硬性要求,不同 provider 对同一图片不得共享缓存);实现不得保存图片、鉴权 header 或 JavDB 详情。 CLI 以本接口注入本机文件缓存。

type ReverseSearchCandidate added in v0.7.0

type ReverseSearchCandidate struct {
	VideoCode  string               `json:"video_code"`
	Similarity float64              `json:"best_similarity,omitempty"`
	Frames     []ReverseSearchFrame `json:"frames,omitempty"`
}

ReverseSearchCandidate 是一个视频候选。

type ReverseSearchFrame added in v0.7.0

type ReverseSearchFrame struct {
	ImageName    string  `json:"image_name,omitempty"`
	Similarity   float64 `json:"similarity,omitempty"`
	Timestamp    string  `json:"timestamp,omitempty"`
	ThumbnailURL string  `json:"thumbnail_url,omitempty"`
}

ReverseSearchFrame 是候选结果中的一帧。

type ReverseSearchOptions added in v0.7.0

type ReverseSearchOptions struct {
	Cache          ReverseSearchCache
	Retries        int
	RetryWait      time.Duration
	RequestTimeout time.Duration
}

ReverseSearchOptions 配置反搜传输与缓存。零值使用默认三次总请求与 30/60 秒退避、60 秒单请求超时。

type ReverseSearchRequest added in v0.7.0

type ReverseSearchRequest struct {
	Image    []byte              `json:"image"`
	Filename string              `json:"filename,omitempty"`
	Source   ReverseSearchSource `json:"source,omitempty"`
	// BypassCache 请求级绕过缓存读写。
	BypassCache bool `json:"bypass_cache,omitempty"`
}

ReverseSearchRequest 是一次以图搜番的原始图片输入。

type ReverseSearchResponse added in v0.7.0

type ReverseSearchResponse struct {
	Source     string                   `json:"source"`
	Candidates []ReverseSearchCandidate `json:"candidates"`
}

ReverseSearchResponse 是反搜的规范化结果。

type ReverseSearchSource added in v0.7.0

type ReverseSearchSource struct {
	Name    string            `json:"name"`
	URL     string            `json:"url"`
	Headers map[string]string `json:"headers,omitempty"`
}

ReverseSearchSource 描述一个反搜 source。Name 为空或 "builtin" 时使用内置 AVScan provider;否则 URL 必须是绝对 HTTP(S) 地址,Headers 必须已展开。

type SearchOptions

type SearchOptions = appapi.SearchOptions

SearchOptions is re-exported for SDK callers.

type SearchResult

type SearchResult = appapi.SearchResult

SearchResult is re-exported.

Jump to

Keyboard shortcuts

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