Documentation
¶
Overview ¶
golang do NOT allow non-primitive constants so some values are defined as variables. However, all variables in this package never change in runtime.
Index ¶
Constants ¶
const BIG_FILE_SIZE = 10 * 1024 * 1024 // 10MiB
const CLIENT_DEFAULT_DOWNLOADING_SPEED_LIMIT = 300 * 1024 * 1024 / 8 // BT客户端默认下载速度上限:300Mbps
const ENV_PROXY = "env"
a special proxy value to indicate force use proxy from HTTP(S)_PROXY env.
const FILENAME_INVALID_CHARS_REGEX = `[<>:"/\|\?\*]+`
Invalid characters of file name / file path in Windows + NTFS. Most of theses chars (except '/') are valid in Linux.
const FILENAME_SUFFIX_ADDED = ".added"
const FILENAME_SUFFIX_BACKUP = ".bak"
const FILENAME_SUFFIX_FAIL = ".fail"
const FILENAME_SUFFIX_OK = ".ok"
const FILEPATH_INVALID_CHARS_REGEX = `[<>:"|\?\*]+`
const FILE_HEADER_CHUNK_SIZE = 512
const HELP_ARG_CATEGORY = `Filter torrents by category. Use "` + NONE + `" to select uncategoried torrents`
const HELP_ARG_CATEGORY_XSEED = `Only xseed torrents that belongs to this category. Use "` + NONE + `" to select uncategoried torrents`
const HELP_ARG_FILTER_TORRENT = "Filter torrents by name"
const HELP_ARG_PATH_MAPPERS = `E.g. ` +
`"/root/Downloads|/var/Downloads" will map "/root/Downloads" or "/root/Downloads/..." path to ` +
`"/var/Downloads" or "/var/Downloads/...". You can also use ":" instead of "|" as the separator ` +
`if both pathes do not contain ":" char`
const HELP_ARG_TAG = `Filter torrents by tag. Comma-separated list. ` + `Torrent which tags contain any one in the list matches. Use "` + NONE + `" to select untagged torrents`
const HELP_ARG_TAG_XSEED = `Comma-separated tag list. Only xseed torrents which tags ` + `contain any one in the list. Use "` + NONE + `" to select untagged torrents`
const HELP_ARG_TEMPLATE = `The Go text template contents string (See https://pkg.go.dev/text/template ). ` +
`If it starts with "@" char, it (the rest part after @) is treated as a file name and template contents ` +
`will be read from it instead. You can use all Sprig ( https://github.com/Masterminds/sprig ) functions in template`
const HELP_ARG_TIMES = `Time string (local timezone). ` +
`Supported formats: "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd", a unix timestamp integer (seconds), ` +
`or a time duration (e.g. "5d") which references to a past time point from now`
const HELP_ARG_TRACKER = `Filter torrents by tracker url or domain. Use "` + NONE + `" to select torrents without tracker`
const HELP_INFOHASH_ARGS = `` /* 749-byte string literal not displayed */
const HELP_TIP_TTY_BINARY_OUTPUT = "binary .torrent file will mess up the terminal. Use pipe to redirect stdout"
const HELP_TORRENT_ARGS = `` /* 674-byte string literal not displayed */
const INFINITE_SIZE = 1024 * 1024 * 1024 * 1024 * 1024 * 1024 // 1EiB
const INFINITE_TIMEOUT = 86400 * 365 * 100
Some funcs require a (positive) timeout parameter. Use a very long value to emulate infinite. (Seconds)
const METADATA_FILE = "metadata.nfo"
const METADATA_KEY_ARRAY_KEYS = "_array_keys"
const METADATA_KEY_COVER = "_cover"
const METADATA_KEY_DRY_RUN = "_dryrun"
const METADATA_KEY_IMAGES = "_images"
const METADATA_KEY_NO_COVER = "_no_cover" // If set to "1", do not upload cover.* image.
const META_TORRENT_FILE = ".torrent"
const NONE = "none"
如果 ptool.toml 配置文件里字符串类型配置项值为空,使用系统默认值;使用 NONE 值显式设置该配置项为空值。 部分 flag 参数使用 NONE 值显式指定为空值。
const PERM = 0600 // 程序创建的所有文件的 PERM
const PERM_DIR = 0700 // 程序创建的所有文件夹的 PERM
const STATUS_FMT = "%-6s %-15s %-27s %-27s %-s\n"
type, name, ↑info, ↓info, others
const TEST_FILE = ".ptool-test"
file created for testing dir permissions & accessibility
const TORRENT_CONTENT_FILENAME_LENGTH_LIMIT = 240
Longer names in torrent will be truncated by libtorrent / qBottorrent, which could cause problems. See: https://github.com/qbittorrent/qBittorrent/issues/7038 .
const TORRENT_DEFAULT_PIECE_LENGTH = "16MiB"
Variables ¶
var DefaultIgnorePatterns = []string{
".*",
"$*",
"~$*",
"*.aria2",
"*.bak",
"*.lnk",
"*.swp",
"*.tmp",
"*.temp",
"*.!qB",
"*.xltd",
"*.downloading",
"*.dropbox",
"*.torrent",
"node_modules/",
"lost+found/",
"__MACOSX/",
"System Volume Information/",
"desktop.ini",
"Thumbs.db",
"@eaDir",
}
Ignored file patterns in .gitignore style. Several cmds skip handling these files.
var ErrDryRun = fmt.Errorf("dry run")
Returned if the action is not processed due to in dry run mode It must be returned as is (Do not wrap it).
var FilenameInvalidCharsRegex = regexp.MustCompile(FILENAME_INVALID_CHARS_REGEX)
var FilenameRestrictedCharacterReplacement = map[rune]rune{
'/': '/',
'\\': '\',
}
var FilenameRestrictedCharacterReplacer *strings.Replacer
Replace invalid Windows filename chars to alternatives. E.g. '/' => '/', '?' => '?'
var FilepathInvalidCharsRegex = regexp.MustCompile(FILEPATH_INVALID_CHARS_REGEX)
var FilepathRestrictedCharacterReplacement = map[rune]rune{
'*': '*',
':': ':',
'<': '<',
'>': '>',
'|': '|',
'?': '?',
'"': '"',
}
It's a subset of https://rclone.org/overview/#restricted-filenames-caveats . Only include invalid filename characters in Windows (NTFS).
var FilepathRestrictedCharacterReplacer *strings.Replacer
Replace invalid Windows file path chars to alternatives. Similar to FilenameRestrictedCharacterReplacer, but do not replace '/' or '\'.
var ImgExts = []string{".webp", ".png", ".jpg", ".jpeg"}
var OpenTrackers = []string{
"udp://open.stealth.si:80/announce",
"udp://tracker.opentrackr.org:1337/announce",
"udp://exodus.desync.com:6969/announce",
"udp://open.demonii.com:1337/announce",
"udp://tracker.torrent.eu.org:451/announce",
"http://sukebei.tracker.wf:8888/announce",
"http://nyaa.tracker.wf:7777/announce",
}
Sources: https://github.com/nyaadevs/nyaa/blob/master/trackers.txt , https://github.com/ngosang/trackerslist/blob/master/trackers_best.txt . Only include most popular & stable trackers in this list.
var ProcessedFilenameSuffixes = []string{ FILENAME_SUFFIX_ADDED, FILENAME_SUFFIX_OK, FILENAME_SUFFIX_FAIL, FILENAME_SUFFIX_BACKUP, }
Some ptool cmds could add a suffix to processed (torrent) filenames. Current Values: [".added", ".ok", ".fail", ".bak"].
var TorrentFileMagicNumbers = []string{"d8:announce", "d13:announce-list", "d10:created by", "d13:creation date"}
.torrent file magic number. See: https://en.wikipedia.org/wiki/Torrent_file , https://en.wikipedia.org/wiki/Bencode . 大部分 .torrent 文件第一个字段是 announce, 个别种子没有 announce / announce-list 字段,第一个字段是 created by / creation date 等, 这类种子可以通过 DHT 下载成功。 values: ["d8:announce", "d10:created by", "d13:creation date"]
Functions ¶
This section is empty.
Types ¶
This section is empty.