helper

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Overview

Utilities funcs that have side effects.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGetTorrentUrlIsMagnet                   = fmt.Errorf("magnet or bt url is NOT supported")
	ErrGetTorrentUrlParseFail                  = fmt.Errorf("failed to parse torrent domain")
	ErrGetTorrentStdoutOutputNotSupportInShell = fmt.Errorf(`"-" arg can not be used in shell`)
)

Functions

func AskYesNoConfirm added in v0.1.10

func AskYesNoConfirm(prompt string) bool

Ask user to confirm an (dangerous) action via typing yes in tty

func GetTemplate added in v0.1.10

func GetTemplate(tpl string) (*template.Template, error)

Get a Go text template instance from tpl string. If tpl starts with "@" char, treat it (the rest part after @) as a file name and read template contents from it instead.

func GetTorrentContent

func GetTorrentContent(torrent string, defaultSite string,
	forceLocal bool, forceRemote bool, stdin []byte, ignoreParsingError bool,
	beforeDownload func(sitename string, id string) error) (
	content []byte, tinfo *torrentutil.TorrentMeta, siteInstance site.Site, sitename string,
	filename string, id string, isLocal bool, err error)

Read a torrent and return it's contents. torrent could be: local filename (e.g. abc.torrent), site torrent id (e.g. mteam.1234) or url (e.g. https://kp.m-team.cc/details.php?id=488424), or "-" to read torrent contents from os.Stdin. Params: forceLocal: force treat torrent as local filename. forceRemote: force treat torrent as site torrent id or url. ignoreParsingError: ignore torrent parsing error, in which case the returned tinfo may by nil. stdin: if not nil, use it as torrent contents when torrent == "-" instead of reading from os.Stdin. beforeDownload: a optional func that be called before downloading each torrent from remote, if the func return a non-nil error, will NOT do download and instead return that err. Return: siteInstance : if torrent is a site torrent, the created corresponding site instance. sitename & filename & id : if torrent is a site torrent, the downloaded torrent sitename & filename & id. isLocal: whether torrent is a local or remote torrent.

func GetWildcardFilenames added in v0.1.10

func GetWildcardFilenames(filestr string) []string

"*.torrent" => ["./a.torrent", "./b.torrent"...]. Return nil if filestr does not contains wildcard char. Windows cmd / powershell 均不支持命令行 *.torrent 参数扩展。必须应用自己实现。做个简易版的.

func ParseFilenameArgs added in v0.1.10

func ParseFilenameArgs(args ...string) []string

func ParseInfoHashesFromArgs added in v0.1.10

func ParseInfoHashesFromArgs(args []string) (infoHashes []string, err error)

Parse info-hash list from args. If args is a single "-", read the list from stdin instead. It returns an error if parsed info-hash list is empty.

func ParseTorrentsFromArgs added in v0.1.10

func ParseTorrentsFromArgs(args []string) (torrents []string, stdinTorrentContents []byte, err error)

Parse torrent list from args. If args is a single "-", read the list from stdin instead, unless stdin contents is a valid .torrent file, in which case returned torrents is ["-"] and stdin contents returned as stdinTorrentContents. It returns an error if parsed torrents list is empty.

func ReadArgsFromStdin

func ReadArgsFromStdin() ([]string, error)

Read whitespace splitted tokens from stdin

Types

This section is empty.

Jump to

Keyboard shortcuts

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