csf

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 12 Imported by: 0 modules, 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 csf 是 ChineseSubFinder(自动下载中文字幕的工具)的外部接口客户端:整理出新视频以后交给它下载字幕。

接口出自 ChineseSubFinder 的源码(github.com/ChineseSubFinder/ChineseSubFinder,MIT): /api/v1 下的接口认请求头 Authorization: Bearer <API Key>(设置里开了「API Key」才有); POST /api/v1/add-job 加一个下载字幕的任务(video_type 电影 0、剧集 1,physical_video_file_full_path 是 ChineseSubFinder 看到的视频路径,task_priority_level 0 最高、10 最低),回 {"job_id","message"}:message 是 ok 或 job is already in queue 算加上了,physical video file not found 是那边没有这个文件;剧集要读这一集旁边的 NFO 与剧的目录,读不到时回 500。

Index

Constants

View Source
const (
	VideoMovie  = 0
	VideoSeries = 1
)

视频的种类(add-job 的 video_type)。

View Source
const Priority = 3

Priority 是 pt-tools 交的任务的优先级(0 最高、10 最低;ChineseSubFinder 自己扫到的是 5)。

Variables

View Source
var (
	// ErrBadConfig 是地址或 API Key 不对(没填、不是 http/https 的地址)。
	ErrBadConfig = errors.New("ChineseSubFinder 的设置不对")
	// ErrUnauthorized 是 API Key 不对(ChineseSubFinder 回 401)。
	ErrUnauthorized = errors.New("ChineseSubFinder 的 API Key 不对")
	// ErrFileNotFound 是 ChineseSubFinder 那边没有这个视频文件(多半是库目录填得不对)。
	ErrFileNotFound = errors.New("ChineseSubFinder 那边找不到这个视频文件")
	// ErrUnavailable 是连不上,或者回的不是 ChineseSubFinder 的应答(地址填错了)。
	ErrUnavailable = errors.New("连不上 ChineseSubFinder")
)

Functions

func NewHTTPClient

func NewHTTPClient() *http.Client

NewHTTPClient 是访问 ChineseSubFinder 用的 HTTP 客户端:多半在局域网里,不走代理、不跟跳转,15 秒超时(同媒体服务器)。

func NormalizeURL

func NormalizeURL(raw string) (string, error)

NormalizeURL 检查并规整地址:http 或 https、有主机、不带用户名密码与查询参数;规整成以 / 结尾。

func PathFor

func PathFor(lib, prefix, target string) (string, bool)

PathFor 是库里一个文件在 ChineseSubFinder 那边的路径:target 在库目录 lib 下的相对路径接到 prefix(ChineseSubFinder 里这个库的目录) 后面;prefix 为空时就是 target。prefix 像 Windows 路径(有盘符或 \)时用 \ 连接。target 不在库目录里时 ok 为假。

Types

type Client

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

Client 是一台 ChineseSubFinder。

func New

func New(rawURL, key string, hc *http.Client) (*Client, error)

New 按地址与 API Key 建客户端;hc 为空时用 NewHTTPClient。

func (*Client) AddJob

func (c *Client) AddJob(ctx context.Context, j Job) (string, error)

AddJob 让 ChineseSubFinder 给这个视频下载字幕,返回任务编号;已经在队列里也算成功。

func (*Client) Test

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

Test 访问一次 GET api/v1/job-status(不带任务编号,不建任务):地址与 API Key 都对时 ChineseSubFinder 回 200。

type Job

type Job struct {
	VideoType int
	// Path 是 ChineseSubFinder 看到的视频路径(见 PathFor)
	Path     string
	IsBluray bool
}

Job 是交给 ChineseSubFinder 的一个视频。

Jump to

Keyboard shortcuts

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