Documentation
¶
Index ¶
- Constants
- Variables
- func CreateDefaultConfig() (err error)
- func GetGroupSites(name string) []string
- func GetProxy(proxies ...string) string
- func LockConfigDirFile(name string) (*flock.Flock, error)
- func MatchSite(domain string, siteConfig *SiteConfigStruct) bool
- func ParseGroupAndOtherNames(names ...string) []string
- func ParseGroupAndOtherNamesWithoutDeduplicate(names ...string) []string
- func Set() error
- func UpdateSites(updatesites []*SiteConfigStruct)
- type AliasConfigStruct
- type ClientConfigStruct
- type ConfigStruct
- type CookiecloudConfigStruct
- type GroupConfigStruct
- type SiteConfigStruct
- func (siteConfig *SiteConfigStruct) GetName() string
- func (siteConfig *SiteConfigStruct) GetTimezone() string
- func (siteConfig *SiteConfigStruct) MatchFilter(filter string) bool
- func (siteConfig *SiteConfigStruct) ParseSiteUrl(siteUrl string, appendQueryStringDelimiter bool) string
- func (siteConfig *SiteConfigStruct) Register()
Constants ¶
const ( METADATA_ARRAY_KEYS = "tags,narrator" BRUSH_CAT = "_brush" SEEDING_CAT = "_seeding" FALLBACK_CAT = "Others" // --add-category-auto fallback category if does NOT match with any site DYNAMIC_SEEDING_CAT_PREFIX = "dynamic-seeding-" XSEED_TAG = "_xseed" NOADD_TAG = "_noadd" NODEL_TAG = "_nodel" TORRENT_NODEL_TAG = "nodel" INVALID_TRACKER_TAG_PREFIX = "_invalid_tracker_" TRANSFERRED_TAG = "_transferred" // transferred to another client NOXSEED_TAG = "noxseed" // BT 客户端里含有此 tag 的种子不会被辅种 HR_TAG = "_hr" PRIVATE_TAG = "_private" PUBLIC_TAG = "_public" STATS_FILENAME = "ptool_stats.txt" HISTORY_FILENAME = "ptool_history" SITE_TORRENTS_WIDTH = 120 // min width for printing site torrents CLIENT_TORRENTS_WIDTH = 120 // min width for printing client torrents GLOBAL_INTERNAL_LOCK_FILE = "ptool.lock" GLOBAL_LOCK_FILE = "ptool-global.lock" CLIENT_LOCK_FILE = "client-%s.lock" EXAMPLE_CONFIG_FILE = "ptool.example" // .toml , .yaml DEFAULT_EXPORT_TORRENT_RENAME = "{{.name128}}.{{.infohash16}}.torrent" // New iyuu API. // iyuuplus-dev: https://github.com/ledccn/iyuuplus-dev . // Docs: https://doc.iyuu.cn/reference/config . DEFAULT_IYUU_DOMAIN = "2025.iyuu.cn" DEFAULT_TIMEOUT = int64(5) DEFAULT_SHELL_MAX_SUGGESTIONS = int64(5) DEFAULT_SHELL_MAX_HISTORY = int64(500) DEFAULT_SITE_TIMEZONE = "Asia/Shanghai" DEFAULT_CLIENT_BRUSH_MIN_DISK_SPACE = int64(5 * 1024 * 1024 * 1024) DEFAULT_CLIENT_BRUSH_SLOW_UPLOAD_SPEED_TIER = int64(100 * 1024) DEFAULT_CLIENT_BRUSH_MAX_DOWNLOADING_TORRENTS = int64(6) DEFAULT_CLIENT_BRUSH_MAX_TORRENTS = int64(9999) DEFAULT_CLIENT_BRUSH_MIN_RATION = float64(0.2) DEFAULT_CLIENT_BRUSH_DEFAULT_UPLOAD_SPEED_LIMIT = int64(10 * 1024 * 1024) DEFAULT_SITE_TIMEOUT = DEFAULT_TIMEOUT DEFAULT_SITE_BRUSH_TORRENT_MIN_SIZE_LIMIT = int64(0) DEFAULT_SITE_BRUSH_TORRENT_MAX_SIZE_LIMIT = int64(1024 * 1024 * 1024 * 1024 * 1024) //1PB=effectively no limit DEFAULT_SITE_TORRENT_UPLOAD_SPEED_LIMIT = int64(10 * 1024 * 1024) DEFAULT_SITE_FLOW_CONTROL_INTERVAL = int64(3) DEFAULT_SITE_MAX_REDIRECTS = int64(3) DEFAULT_COOKIECLOUD_TIMEOUT = DEFAULT_TIMEOUT )
Variables ¶
var ( Timeout = int64(0) // network(http) timeout. It has the highest priority. Set by --timeout global flag VerboseLevel = 0 InShell = false ConfigDir = "" // "/root/.config/ptool" ConfigFile = "" // "ptool.toml" DefaultConfigFile = "" // set when start ConfigName = "" // "ptool" ConfigType = "" // "toml" LockFile = "" Proxy = "" // proxy. It has the highest priority. Set by --proxy global flag Tz = "" // override system timezone (TZ) used by the program. Set by --timezone global flag GlobalLock = false LockOrExit = false Fork = false Insecure = false // Force disable all TLS / https cert verifications. Set by --insecure global flag )
var DefaultConfigFs embed.FS
var InternalAliases = []*AliasConfigStruct{ { Name: "add2", Cmd: "add --add-category-auto --sequential-download --rename-added", DefaultArgs: "*.torrent", MinArgs: 1, Internal: true, }, { Name: "batchadd", Cmd: "batchdl --add-category-auto --add-respect-noadd --add-client", MinArgs: 1, Internal: true, }, { Name: "dlsite", Cmd: "batchdl --download --skip-existing", MinArgs: 1, Internal: true, }, { Name: "sum", Cmd: "parsetorrent --sum", DefaultArgs: "*.torrent", Internal: true, }, { Name: "verify2", Cmd: "verifytorrent --rename-fail", DefaultArgs: "*.torrent", MinArgs: 1, Internal: true, }, }
Functions ¶
func CreateDefaultConfig ¶ added in v0.1.9
func CreateDefaultConfig() (err error)
func GetGroupSites ¶
if name is a group, return it's sites, otherwise return nil
func GetProxy ¶ added in v0.1.10
Get effective proxy, following the orders: Proxy (set by cmdline --proxy flag), proxies...
func LockConfigDirFile ¶ added in v0.1.10
Lock the file with provided name in config dir.
func MatchSite ¶ added in v0.1.1
func MatchSite(domain string, siteConfig *SiteConfigStruct) bool
func ParseGroupAndOtherNames ¶
Parse an slice of groupOrOther names, expand group name to site names, return the final slice of names
func Set ¶ added in v0.1.8
func Set() error
Re-write the whole config file using memory data. Currently, only sites will be overrided. Due to technical limitations, all existing comments will be LOST. For now, new config data will NOT take effect for current ptool process.
func UpdateSites ¶ added in v0.1.8
func UpdateSites(updatesites []*SiteConfigStruct)
Update configed sites in place, merge the provided (updated) sites with existing config.
Types ¶
type AliasConfigStruct ¶ added in v0.1.9
type AliasConfigStruct struct {
Name string `yaml:"name"`
Cmd string `yaml:"cmd"`
DefaultArgs string `yaml:"defaultArgs"`
MinArgs int64 `yaml:"minArgs"`
Comment string `yaml:"comment"`
Internal bool
}
func GetAliasConfig ¶ added in v0.1.9
func GetAliasConfig(name string) *AliasConfigStruct
func (*AliasConfigStruct) MatchFilter ¶ added in v0.1.9
func (aliasConfig *AliasConfigStruct) MatchFilter(filter string) bool
type ClientConfigStruct ¶
type ClientConfigStruct struct {
Type string `yaml:"type"`
Name string `yaml:"name"`
Comment string `yaml:"comment"`
Disabled bool `yaml:"disabled"`
Url string `yaml:"url"`
Username string `yaml:"username"`
Password string `yaml:"password"`
// 适用于本机上的 BT 客户端。当前客户端存放种子 (<info-hash>.torrent)的路径。各个客户端默认值:
// Transmission on Windows: %SystemRoot%\ServiceProfiles\LocalService\AppData\Local\transmission-daemon\Torrents .
// qBittorrent on Windows: %USERPROFILE%\AppData\Local\qBittorrent\BT_backup .
// 对于 TR 需要配置此选项才能使用部分命令(例如“导出种子”)。
// 对于 QB 此配置是可选的(因为 QB web API 提供导出种子接口),但配置后会提高相关命令的性能。
LocalTorrentsPath string `yaml:"localTorrentsPath"`
BrushMinDiskSpace string `yaml:"brushMinDiskSpace"`
BrushSlowUploadSpeedTier string `yaml:"brushSlowUploadSpeedTier"`
BrushMaxDownloadingTorrents int64 `yaml:"brushMaxDownloadingTorrents"`
BrushMaxTorrents int64 `yaml:"brushMaxTorrents"`
BrushMinRatio float64 `yaml:"brushMinRatio"`
BrushDefaultUploadSpeedLimit string `yaml:"brushDefaultUploadSpeedLimit"`
BrushMinDiskSpaceValue int64
BrushSlowUploadSpeedTierValue int64
BrushDefaultUploadSpeedLimitValue int64 ``
QbittorrentNoLogin bool `yaml:"qbittorrentNoLogin"` // if set, will NOT send login request
QbittorrentNoLogout bool `yaml:"qbittorrentNoLogout"` // if set, will NOT send logout request
}
func GetClientConfig ¶
func GetClientConfig(name string) *ClientConfigStruct
func (*ClientConfigStruct) MatchFilter ¶ added in v0.1.9
func (clientConfig *ClientConfigStruct) MatchFilter(filter string) bool
type ConfigStruct ¶
type ConfigStruct struct {
Hushshell bool `yaml:"hushshell"`
ShellMaxSuggestions int64 `yaml:"shellMaxSuggestions"` // -1 禁用
ShellMaxHistory int64 `yaml:"shellMaxHistory"` // -1 禁用
IyuuToken string `yaml:"iyuuToken"`
ReseedUsername string `yaml:"reseedUsername"`
ReseedPassword string `yaml:"reseedPassword"`
IyuuDomain string `yaml:"iyuuDomain"` // iyuu API 域名。默认使用 2025.iyuu.cn
SiteProxy string `yaml:"siteProxy"`
SiteUserAgent string `yaml:"siteUserAgent"`
SiteImpersonate string `yaml:"siteImpersonate"`
SiteHttpHeaders [][]string `yaml:"siteHttpHeaders"`
SiteJa3 string `yaml:"siteJa3"`
SiteTimeout int64 `yaml:"siteTimeout"` // 访问网站超时时间(秒)
SiteInsecure bool `yaml:"siteInsecure"` // 强制禁用所有站点 TLS 证书校验。
SiteH2Fingerprint string `yaml:"siteH2Fingerprint"`
BrushEnableStats bool `yaml:"brushEnableStats"`
Clients []*ClientConfigStruct `yaml:"clients"`
Sites []*SiteConfigStruct `yaml:"sites"`
Groups []*GroupConfigStruct `yaml:"groups"`
Aliases []*AliasConfigStruct `yaml:"aliases"`
Cookieclouds []*CookiecloudConfigStruct `yaml:"cookieclouds"`
Comment string `yaml:"comment"`
// 公网 BT 种子的分享率(Up/Dl)限制(到达后停止做种)。"add" 等命令添加公网种子到BT客户端时会自动应用此限制。
// 0 : unlimited。仅 qBittorrent 支持此选项。
PublicTorrentRatioLimit float64 `yaml:"publicTorrentRatioLimit"`
ClientsEnabled []*ClientConfigStruct
SitesEnabled []*SiteConfigStruct
}
func Get ¶
func Get() *ConfigStruct
func (*ConfigStruct) GetIyuuDomain ¶ added in v0.1.9
func (configData *ConfigStruct) GetIyuuDomain() string
func (*ConfigStruct) UpdateSitesDerivative ¶ added in v0.1.8
func (configData *ConfigStruct) UpdateSitesDerivative()
type CookiecloudConfigStruct ¶ added in v0.1.8
type CookiecloudConfigStruct struct {
Name string `yaml:"name"`
Disabled bool `yaml:"disabled"`
Server string `yaml:"server"` // CookieCloud API Server Url (with API_ROOT, if exists)
Uuid string `yaml:"uuid"`
Password string `yaml:"password"`
Proxy string `yaml:"proxy"`
Sites []string `yaml:"sites"`
Timeout int64 `yaml:"timeout"`
Comment string `yaml:"comment"`
}
func GetCookiecloudConfig ¶ added in v0.1.8
func GetCookiecloudConfig(name string) *CookiecloudConfigStruct
func (*CookiecloudConfigStruct) MatchFilter ¶ added in v0.1.9
func (cookieCloudConfig *CookiecloudConfigStruct) MatchFilter(filter string) bool
type GroupConfigStruct ¶
type GroupConfigStruct struct {
Name string `yaml:"name"`
Sites []string `yaml:"sites"`
Comment string `yaml:"comment"`
}
func GetGroupConfig ¶ added in v0.1.6
func GetGroupConfig(name string) *GroupConfigStruct
func (*GroupConfigStruct) MatchFilter ¶ added in v0.1.9
func (groupConfig *GroupConfigStruct) MatchFilter(filter string) bool
type SiteConfigStruct ¶
type SiteConfigStruct struct {
Type string `yaml:"type"`
Name string `yaml:"name"`
Aliases []string // for internal use only
Comment string `yaml:"comment"`
Disabled bool `yaml:"disabled"`
Hidden bool `yaml:"hidden"` // exclude from default groups (like "_all")
Dead bool `yaml:"dead"` // site is (currently) dead.
Url string `yaml:"url"`
Domains []string `yaml:"domains"` // other site domains (do not include subdomain part)
TorrentsUrl string `yaml:"torrentsUrl"`
SearchUrl string `yaml:"searchUrl"`
DynamicSeedingTorrentsUrl string `yaml:"dynamicSeedingTorrentsUrl"`
DynamicSeedingExcludes []string `yaml:"dynamicSeedingExcludes"`
DynamicSeedingSize string `yaml:"dynamicSeedingSize"`
DynamicSeedingTorrentMinSize string `yaml:"dynamicSeedingTorrentMinSize"`
DynamicSeedingTorrentMaxSize string `yaml:"dynamicSeedingTorrentMaxSize"`
DynamicSeedingMaxScan int64 `yaml:"dynamicSeedingMaxScan"`
DynamicSeedingMinSeeders int64 `yaml:"dynamicSeedingMinSeeders"`
DynamicSeedingMaxSeeders int64 `yaml:"dynamicSeedingMaxSeeders"`
DynamicSeedingReplaceSeeders int64 `yaml:"dynamicSeedingReplaceSeeders"`
SearchQueryVariable string `yaml:"searchQueryVariable"`
TorrentsExtraUrls []string `yaml:"torrentsExtraUrls"`
Cookie string `yaml:"cookie"`
UserAgent string `yaml:"userAgent"`
Impersonate string `yaml:"impersonate"`
HttpHeaders [][]string `yaml:"httpHeaders"`
Ja3 string `yaml:"ja3"`
Timeout int64 `yaml:"timeout"`
H2Fingerprint string `yaml:"h2Fingerprint"`
Proxy string `yaml:"proxy"`
Insecure bool `yaml:"insecure"` // 访问站点时强制跳过TLS证书安全校验
Secure bool `yaml:"secure"` // 访问站点时强制TLS证书安全校验
TorrentUploadSpeedLimit string `yaml:"torrentUploadSpeedLimit"`
GlobalHnR bool `yaml:"globalHnR"`
Timezone string `yaml:"timezone"`
BrushTorrentMinSizeLimit string `yaml:"brushTorrentMinSizeLimit"`
BrushTorrentMaxSizeLimit string `yaml:"brushTorrentMaxSizeLimit"`
BrushAllowNoneFree bool `yaml:"brushAllowNoneFree"`
BrushAllowPaid bool `yaml:"brushAllowPaid"`
BrushAllowHr bool `yaml:"brushAllowHr"`
BrushAllowZeroSeeders bool `yaml:"brushAllowZeroSeeders"`
BrushExcludes []string `yaml:"brushExcludes"`
BrushExcludeTags []string `yaml:"brushExcludeTags"`
BrushAcceptAnyFree bool `yaml:"brushAcceptAnyFree"`
SelectorTorrentsListHeader string `yaml:"selectorTorrentsListHeader"`
SelectorTorrentsList string `yaml:"selectorTorrentsList"`
SelectorTorrentBlock string `yaml:"selectorTorrentBlock"` // dom block of a torrent in list
SelectorTorrent string `yaml:"selectorTorrent"`
SelectorTorrentDownloadLink string `yaml:"selectorTorrentDownloadLink"`
SelectorTorrentDetailsLink string `yaml:"selectorTorrentDetailsLink"`
SelectorTorrentTime string `yaml:"selectorTorrentTime"`
SelectorTorrentSeeders string `yaml:"selectorTorrentSeeders"`
SelectorTorrentLeechers string `yaml:"selectorTorrentLeechers"`
SelectorTorrentSnatched string `yaml:"selectorTorrentSnatched"`
SelectorTorrentSize string `yaml:"selectorTorrentSize"`
SelectorTorrentActive string `yaml:"selectorTorrentActive"` // Is or was active
SelectorTorrentCurrentActive string `yaml:"selectorTorrentCurrentActive"` // Is currently active
SelectorTorrentFree string `yaml:"SelectorTorrentFree"`
SelectorTorrentNoTraffic string `yaml:"selectorTorrentNoTraffic"`
SelectorTorrentNeutral string `yaml:"selectorTorrentNeutral"`
SelectorTorrentHnR string `yaml:"selectorTorrentHnR"`
SelectorTorrentPaid string `yaml:"selectorTorrentPaid"`
SelectorTorrentDiscountEndTime string `yaml:"selectorTorrentDiscountEndTime"`
SelectorUserInfo string `yaml:"selectorUserInfo"`
SelectorUserInfoUserName string `yaml:"selectorUserInfoUserName"`
SelectorUserInfoUploaded string `yaml:"selectorUserInfoUploaded"`
SelectorUserInfoDownloaded string `yaml:"selectorUserInfoDownloaded"`
ImageUploadUrl string `yaml:"imageUploadUrl"`
// Additional post payload when uploading image, query string format.
// E.g. "foo=a&bar=b".
ImageUploadPayload string `yaml:"imageUploadPayload"`
ImageUploadHeaders [][]string `yaml:"imageUploadHeaders"`
ImageUploadFileField string `yaml:"imageUploadFileField"` // Default: "file"
// Default: "url". May contain dots, e.g. "data.url" will resolve to "res.data.url",
// where res is the response json object .
ImageUploadResponseUrlField string `yaml:"mageUploadResponseUrlField"`
// Payload that will be sent to site when uploading torrent.
// Key => value. Values are using jinja2 syntax. E.g. "{{title}}".
// Jinja context variables:
// title: Resource title. (this variable is guaranteed to exist, all others are optional).
// _text: full description plain text.
// _cover: uploaded cover image url.
// Rendered results will be TrimSpaced.
// If UploadTorrentPayload is nil, schema dependent default values will be used,
// and values of UploadTorrentAdditionalPayload will be assigned to previous values.
// Jinja rendering uses gonja, which, unfortunately, is not fully compatible with python version.
// For example, {{% if str.startswith("xxx") %}} will NOT work as startswith is a method of python built in string,
// which is not available in Go. All these methods must be replaced by filters instead.
UploadTorrentPayload map[string]string `yaml:"uploadTorrentPayload"`
UploadTorrentAdditionalPayload map[string]string `yaml:"uploadTorrentAdditionalPayload"`
// csv, eg: "type". It will check existence of these keys in metadata prior publishing.
UploadTorrentPayloadRequiredKeys string `yaml:"uploadTorrentPayloadRequiredKeys"`
TorrentDownloadUrl string `yaml:"torrentDownloadUrl"` // use {id} placeholders in url
TorrentDownloadUrlPrefix string `yaml:"torrentDownloadUrlPrefix"`
Passkey string `yaml:"passkey"`
UseCuhash bool `yaml:"useCuhash"` // hdcity 使用机制。种子下载地址里必须有cuhash参数
// ttg 使用机制。种子下载地址末段必须有4位数字校验码或Passkey参数(即使有 Cookie)
UseDigitHash bool `yaml:"useDigitHash"`
UsePasskey bool `yaml:"usePasskey"` // 部分站点(例如 ptt)必须使用包含 passkey 的链接下载种子
TorrentUrlIdRegexp string `yaml:"torrentUrlIdRegexp"`
FlowControlInterval int64 `yaml:"flowControlInterval"` // 暂定名。两次请求种子列表页间隔时间(秒)
NexusphpNoLetDown bool `yaml:"nexusphpNoLetDown"`
MaxRedirects int64 `yaml:"maxRedirects"`
NoCookie bool `yaml:"noCookie"` // true: 该站点不使用 cookie 鉴权方式
AcceptAnyHttpStatus bool `yaml:"acceptAnyHttpStatus"` // true: 非200的http状态不认为是错误
TorrentUploadSpeedLimitValue int64
BrushTorrentMinSizeLimitValue int64
BrushTorrentMaxSizeLimitValue int64
DynamicSeedingSizeValue int64
DynamicSeedingTorrentMinSizeValue int64
DynamicSeedingTorrentMaxSizeValue int64
AutoComment string // 自动更新 ptool.toml 时系统生成的 comment。会被写入 Comment 字段
BrushAllowAddTorrentsPercent int `yaml:"brushAllowAddTorrentsPercent"` // Site种子数量占比(0~100]: ConfigStruct.BrushMaxTorrents; 0 = no limit
}
func GetSiteConfig ¶ added in v0.1.1
func GetSiteConfig(name string) *SiteConfigStruct
func (*SiteConfigStruct) GetName ¶
func (siteConfig *SiteConfigStruct) GetName() string
func (*SiteConfigStruct) GetTimezone ¶ added in v0.1.8
func (siteConfig *SiteConfigStruct) GetTimezone() string
func (*SiteConfigStruct) MatchFilter ¶ added in v0.1.9
func (siteConfig *SiteConfigStruct) MatchFilter(filter string) bool
func (*SiteConfigStruct) ParseSiteUrl ¶
func (siteConfig *SiteConfigStruct) ParseSiteUrl(siteUrl string, appendQueryStringDelimiter bool) string
Parse a site internal url (e.g. special.php), return absolute url
func (*SiteConfigStruct) Register ¶ added in v0.1.8
func (siteConfig *SiteConfigStruct) Register()
Generate derivative info from site config and register itself