Documentation
¶
Index ¶
- Variables
- func RenameExportedTorrent(client string, torrent *client.Torrent, renameTemplate *template.Template) (string, error)
- func RenameTorrent(renameTemplate *template.Template, sitename string, id string, filename string, ...) (string, error)
- type TorrentCommentMeta
- type TorrentMakeOptions
- type TorrentMeta
- func (meta *TorrentMeta) AddTracker(tracker string, tier int) error
- func (meta *TorrentMeta) DecodeComment() *TorrentCommentMeta
- func (meta *TorrentMeta) EncodeComment(commentMeta *TorrentCommentMeta) error
- func (meta *TorrentMeta) Fprint(f io.Writer, name string, showAll bool)
- func (meta *TorrentMeta) FprintFiles(f io.Writer, addRootDirPrefix bool, useRawSize bool)
- func (meta *TorrentMeta) IsPrivate() bool
- func (meta *TorrentMeta) MagnetUrl() string
- func (tm TorrentMeta) MarshalJSON() ([]byte, error)
- func (meta *TorrentMeta) MatchFilter(filter string) bool
- func (meta *TorrentMeta) MatchTracker(tracker string) bool
- func (meta *TorrentMeta) RemoveTracker(tracker string) error
- func (meta *TorrentMeta) RootFiles() (rootFiles []string)
- func (meta *TorrentMeta) SetComment(comment string)
- func (meta *TorrentMeta) SetInfoPrivate(private bool) error
- func (meta *TorrentMeta) ToBytes() ([]byte, error)
- func (meta *TorrentMeta) UpdateComment(comment string) error
- func (meta *TorrentMeta) UpdateCreatedBy(createdBy string) error
- func (meta *TorrentMeta) UpdateCreationDate(creationDate int64) error
- func (meta *TorrentMeta) UpdateInfoName(name string) error
- func (meta *TorrentMeta) UpdateInfoSource(source string) error
- func (meta *TorrentMeta) UpdateTracker(tracker string) error
- func (meta *TorrentMeta) Verify(savePath, contentPath string, checkHash, checkMinLength int64) (ts int64, err error)
- func (meta *TorrentMeta) VerifyAgaintSavePathFs(savePathFs fs.FS) error
- func (meta *TorrentMeta) XseedCheckWithClientTorrent(clientTorrentContents []*client.TorrentContentFile) int64
- type TorrentMetaFile
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoChange = errors.New("no change made") ErrSmall = errors.New("torrent contents is too small") ErrDifferentName = errors.New("this is single-file torrent. the torrent content file on disk " + "has same content with torrent meta, but they have DIFFERENT file name, " + "so it can not be directly added to client as xseed torrent") ErrDifferentRootName = errors.New("this is multiple-file torrent. the torrent content files on disk " + "has same contents with torrent meta, but they have DIFFERENT root folder name, " + "so it can not be directly added to client as xseed torrent") )
Functions ¶
func RenameExportedTorrent ¶ added in v0.1.9
func RenameExportedTorrent(client string, torrent *client.Torrent, renameTemplate *template.Template) (string, error)
Get appropriate filename for exported .torrent file. It works similar to RenameTorrent . available variables: client, size, infohash, infohash16, category, name, name128. The returned name is processed the same way as RenameTorrent .
func RenameTorrent ¶ added in v0.1.9
func RenameTorrent(renameTemplate *template.Template, sitename string, id string, filename string, tinfo *TorrentMeta) (string, error)
Rename torrent (downloaded filename or name of torrent added to client) according to renameTemplate, which is a Go text template instance. filename: original torrent filename (e.g. "abc.torrent"). Available variables: size, id, site, filename, filename128, name, name128. tinfo is optional and could be nil. The returned name is trim spaced and some (Windows) file system restrictive chars like "?" are replaced with their full-width equivalents (like "?").
Types ¶
type TorrentCommentMeta ¶ added in v0.1.10
type TorrentMakeOptions ¶ added in v0.1.10
type TorrentMakeOptions struct { ContentPath string Output string Public bool Private bool All bool Force bool Comment string InfoName string UrlList metainfo.UrlList Trackers []string CreatedBy string CreationDate string PieceLengthStr string MinSize int64 Excludes []string AllowRestrictedCharInFilename bool // If > 0, limit filename (not full path) length to at most these bytes (UTF-8 string). FilenameLengthLimit int64 }
type TorrentMeta ¶
type TorrentMeta struct { InfoHash string PiecesHash string // sha1(torrent.info.pieces) Trackers []string Size int64 SingleFileTorrent bool RootDir string ContentPath string // root folder or single file name Files []TorrentMetaFile MetaInfo *metainfo.MetaInfo // always non-nil in a parsed *TorrentMeta Info *metainfo.Info // always non-nil in a parsed *TorrentMeta // contains filtered or unexported fields }
func FromMetaInfo ¶ added in v0.1.10
func MakeTorrent ¶ added in v0.1.10
func MakeTorrent(options *TorrentMakeOptions) (tinfo *TorrentMeta, err error)
Create a torrent, return info of created torrent. It may change the values of any fields in options.
func ParseTorrent ¶
func ParseTorrent(torrentdata []byte) (*TorrentMeta, error)
func (*TorrentMeta) AddTracker ¶ added in v0.1.10
func (meta *TorrentMeta) AddTracker(tracker string, tier int) error
Add a tracker to AnnounceList at specified tier. Do not add the tracker if it already exists somewhere in AnnounceList. tier == -1: create a new tier to the end of AnnounceList and put new tracker here.
func (*TorrentMeta) DecodeComment ¶ added in v0.1.10
func (meta *TorrentMeta) DecodeComment() *TorrentCommentMeta
Decode torrent meta from 'comment' field
func (*TorrentMeta) EncodeComment ¶ added in v0.1.10
func (meta *TorrentMeta) EncodeComment(commentMeta *TorrentCommentMeta) error
Encode torrent meta to 'comment' field
func (*TorrentMeta) Fprint ¶ added in v0.1.10
func (meta *TorrentMeta) Fprint(f io.Writer, name string, showAll bool)
func (*TorrentMeta) FprintFiles ¶ added in v0.1.10
func (meta *TorrentMeta) FprintFiles(f io.Writer, addRootDirPrefix bool, useRawSize bool)
func (*TorrentMeta) IsPrivate ¶ added in v0.1.10
func (meta *TorrentMeta) IsPrivate() bool
func (*TorrentMeta) MagnetUrl ¶ added in v0.1.9
func (meta *TorrentMeta) MagnetUrl() string
Generate magnet: url of this torrent. Must be used on meta parsed from ParseTorrent with fields >= 2
func (TorrentMeta) MarshalJSON ¶ added in v0.1.10
func (tm TorrentMeta) MarshalJSON() ([]byte, error)
func (*TorrentMeta) MatchFilter ¶ added in v0.1.10
func (meta *TorrentMeta) MatchFilter(filter string) bool
func (*TorrentMeta) MatchTracker ¶ added in v0.1.10
func (meta *TorrentMeta) MatchTracker(tracker string) bool
Matches if torrent any tracker's url or domain == tracker. Specially, if tracker is "none", matches if torrent does NOT have any tracker.
func (*TorrentMeta) RemoveTracker ¶ added in v0.1.10
func (meta *TorrentMeta) RemoveTracker(tracker string) error
func (*TorrentMeta) RootFiles ¶ added in v0.1.10
func (meta *TorrentMeta) RootFiles() (rootFiles []string)
func (*TorrentMeta) SetComment ¶ added in v0.1.10
func (meta *TorrentMeta) SetComment(comment string)
func (*TorrentMeta) SetInfoPrivate ¶ added in v0.1.10
func (meta *TorrentMeta) SetInfoPrivate(private bool) error
func (*TorrentMeta) ToBytes ¶ added in v0.1.10
func (meta *TorrentMeta) ToBytes() ([]byte, error)
Generate .torrent file from current content
func (*TorrentMeta) UpdateComment ¶ added in v0.1.10
func (meta *TorrentMeta) UpdateComment(comment string) error
func (*TorrentMeta) UpdateCreatedBy ¶ added in v0.1.10
func (meta *TorrentMeta) UpdateCreatedBy(createdBy string) error
func (*TorrentMeta) UpdateCreationDate ¶ added in v0.1.10
func (meta *TorrentMeta) UpdateCreationDate(creationDate int64) error
func (*TorrentMeta) UpdateInfoName ¶ added in v0.1.10
func (meta *TorrentMeta) UpdateInfoName(name string) error
func (*TorrentMeta) UpdateInfoSource ¶ added in v0.1.10
func (meta *TorrentMeta) UpdateInfoSource(source string) error
func (*TorrentMeta) UpdateTracker ¶ added in v0.1.10
func (meta *TorrentMeta) UpdateTracker(tracker string) error
Remove all existing trackers and set the provided one as the sole tracker.
func (*TorrentMeta) Verify ¶
func (meta *TorrentMeta) Verify(savePath, contentPath string, checkHash, checkMinLength int64) (ts int64, err error)
checkHash: 0 - none; 1 - quick; 2+ - full. checkMinLength : Used with quick hash mode; if > 0, at least this size of file head & tail must be checked. ts: timestamp of newest file in torrent contents.
func (*TorrentMeta) VerifyAgaintSavePathFs ¶ added in v0.1.10
func (meta *TorrentMeta) VerifyAgaintSavePathFs(savePathFs fs.FS) error
Verify against a fs.FS of save path (e.g. os.DirFS("D:\Downloads")). It does no hash checking for now.
func (*TorrentMeta) XseedCheckWithClientTorrent ¶
func (meta *TorrentMeta) XseedCheckWithClientTorrent(clientTorrentContents []*client.TorrentContentFile) int64
return 0 if this torrent is equal with client torrent; return 1 if client torrent contains all files of this torrent. return -2 if the ROOT folder(file) of the two are different, but all innner files are SAME. return -1 if contents of the two torrents are NOT same.