torrent

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: GPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPieceHasher

func NewPieceHasher(files []fileEntry, pieceLen int64, numPieces int, display Displayer, failOnSeasonPackWarning bool) *pieceHasher

Types

type BatchConfig

type BatchConfig struct {
	Jobs    []BatchJob `yaml:"jobs"`
	Version int        `yaml:"version"`
}

BatchConfig represents the YAML configuration for batch torrent creation

type BatchJob

type BatchJob struct {
	Output              string   `yaml:"output"`
	Path                string   `yaml:"path"`
	Name                string   `yaml:"-"`
	Comment             string   `yaml:"comment"`
	Source              string   `yaml:"source"`
	Trackers            []string `yaml:"trackers"`
	WebSeeds            []string `yaml:"webseeds"`
	ExcludePatterns     []string `yaml:"exclude_patterns"`
	IncludePatterns     []string `yaml:"include_patterns"`
	PieceLength         uint     `yaml:"piece_length"`
	TargetPieceCount    uint     `yaml:"target_piece_count"`
	Private             bool     `yaml:"private"`
	NoDate              bool     `yaml:"no_date"`
	SkipPrefix          bool     `yaml:"skip_prefix"`
	Entropy             bool     `yaml:"entropy"`
	FailOnSeasonWarning bool     `yaml:"fail_on_season_warning"`
}

BatchJob represents a single torrent creation job within a batch

func (*BatchJob) ToCreateOptions

func (j *BatchJob) ToCreateOptions(verbose bool, quiet bool, infoOnly bool, version string) CreateOptions

ToCreateOptions converts a BatchJob to CreateOptions

type BatchResult

type BatchResult struct {
	Error    error
	Info     *TorrentInfo
	Trackers []string
	Job      BatchJob
	Success  bool
}

BatchResult represents the result of a single job in the batch

func ProcessBatch

func ProcessBatch(configPath string, verbose bool, quiet bool, infoOnly bool, version string) ([]BatchResult, error)

ProcessBatch processes a batch configuration file and creates multiple torrents. It reads a YAML configuration file containing multiple torrent creation jobs and processes them in parallel for efficient batch operations.

type CreateOptions

type CreateOptions struct {
	PieceLengthExp          *uint
	MaxPieceLength          *uint
	TargetPieceCount        *uint
	Path                    string
	Name                    string
	TrackerURLs             []string
	Comment                 string
	Source                  string
	Version                 string
	OutputPath              string
	OutputDir               string
	WebSeeds                []string
	ExcludePatterns         []string
	IncludePatterns         []string
	Workers                 int
	IsPrivate               bool
	NoDate                  bool
	NoCreator               bool
	Verbose                 bool
	Entropy                 bool
	Quiet                   bool
	InfoOnly                bool
	SkipPrefix              bool
	FailOnSeasonPackWarning bool
	// ProgressCallback is called during hashing to report progress.
	// If nil, no progress callbacks will be made.
	ProgressCallback ProgressCallback
}

CreateOptions contains all options for creating a torrent

type Display

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

func NewDisplay

func NewDisplay(formatter *Formatter) *Display

func (*Display) FinishProgress

func (d *Display) FinishProgress()

func (*Display) IsBatch

func (d *Display) IsBatch() bool

func (*Display) SetBatch

func (d *Display) SetBatch(isBatch bool)

func (*Display) SetQuiet

func (d *Display) SetQuiet(quiet bool)

SetQuiet enables/disables quiet mode (output redirected to io.Discard)

func (*Display) ShowBatchResults

func (d *Display) ShowBatchResults(results []BatchResult, duration time.Duration)

func (*Display) ShowError

func (d *Display) ShowError(msg string)

func (*Display) ShowFileTree

func (d *Display) ShowFileTree(info *metainfo.Info)

ShowFileTree displays the file structure of a multi-file torrent The decision to show the tree is now handled in cmd/inspect.go

func (*Display) ShowFiles

func (d *Display) ShowFiles(files []fileEntry, numWorkers int)

ShowFiles displays the list of files being processed and the number of workers used.

func (*Display) ShowMessage

func (d *Display) ShowMessage(msg string)

func (*Display) ShowOutputPathWithTime

func (d *Display) ShowOutputPathWithTime(path string, duration time.Duration)

func (*Display) ShowProgress

func (d *Display) ShowProgress(total int)

func (*Display) ShowSeasonPackWarnings

func (d *Display) ShowSeasonPackWarnings(info *SeasonPackInfo)

func (*Display) ShowTorrentInfo

func (d *Display) ShowTorrentInfo(t *Torrent, info *metainfo.Info)

func (*Display) ShowVerificationResult

func (d *Display) ShowVerificationResult(result *VerificationResult, duration time.Duration)

ShowVerificationResult displays the results of a torrent verification check

func (*Display) ShowWarning

func (d *Display) ShowWarning(msg string)

func (*Display) UpdateProgress

func (d *Display) UpdateProgress(completed int, hashrate float64)

type Displayer

type Displayer interface {
	ShowProgress(total int)
	UpdateProgress(completed int, hashrate float64)
	ShowFiles(files []fileEntry, numWorkers int)
	ShowSeasonPackWarnings(info *SeasonPackInfo)
	FinishProgress()
	IsBatch() bool
}

Displayer defines the interface for displaying progress during torrent creation

type FileEntry

type FileEntry struct {
	Name string
	Path string
	Size int64
}

FileEntry represents a file in the torrent

type Formatter

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

func NewFormatter

func NewFormatter(verbose bool) *Formatter

func (*Formatter) FormatBytes

func (f *Formatter) FormatBytes(bytes int64) string

func (*Formatter) FormatDuration

func (f *Formatter) FormatDuration(dur time.Duration) string

type ModifyOptions

type ModifyOptions struct {
	IsPrivate      *bool
	PieceLengthExp *uint
	MaxPieceLength *uint
	PresetName     string
	PresetFile     string
	Name           string
	OutputDir      string
	OutputPattern  string
	TrackerURLs    []string
	Comment        string
	Source         string
	Version        string
	WebSeeds       []string
	NoDate         bool
	NoCreator      bool
	DryRun         bool
	Verbose        bool
	Quiet          bool
	Entropy        *bool
	SkipPrefix     bool
	SourceSet      bool // true when --source flag was explicitly provided (allows empty string to clear)
	CommentSet     bool // true when --comment flag was explicitly provided (allows empty string to clear)
	RemovePrivate  bool // true when --no-private flag is provided (removes private field entirely)
}

ModifyOptions represents the options for modifying a torrent, including both preset-related options and flag-based overrides.

type ProgressCallback

type ProgressCallback func(completed, total int, hashRate float64)

ProgressCallback is called during torrent creation to report progress. completed: number of pieces hashed so far total: total number of pieces to hash hashRate: current hashing rate in bytes per second

type Result

type Result struct {
	Error       error
	Path        string
	OutputPath  string
	WasModified bool
}

Result represents the result of modifying a torrent

func ModifyTorrent

func ModifyTorrent(path string, opts ModifyOptions) (*Result, error)

ModifyTorrent modifies a single torrent file according to the given options. It can change trackers, comment, source, piece length, and other metadata. Returns a Result containing the operation outcome and output path.

func ProcessTorrents

func ProcessTorrents(paths []string, opts ModifyOptions) ([]*Result, error)

ProcessTorrents modifies multiple torrent files according to the given options. It processes each torrent file and returns the results for all operations. This function provides parallel processing for better performance with multiple files.

type SeasonPackInfo

type SeasonPackInfo struct {
	Episodes        []int
	MissingEpisodes []int
	Season          int
	MaxEpisode      int
	VideoFileCount  int
	IsSeasonPack    bool
	IsSuspicious    bool
}

func AnalyzeSeasonPack

func AnalyzeSeasonPack(files []fileEntry) *SeasonPackInfo

type Torrent

type Torrent struct {
	*metainfo.MetaInfo
}

Torrent represents a torrent file with additional functionality

func CreateTorrent

func CreateTorrent(opts CreateOptions) (*Torrent, error)

CreateTorrent creates a new torrent file from the given options. Returns a Torrent struct containing the metainfo. This is the lower-level function; use Create() for a higher-level interface.

func LoadFromFile

func LoadFromFile(path string) (*Torrent, error)

LoadFromFile loads a torrent file from disk and returns a Torrent struct. The returned Torrent wraps the metainfo and provides additional functionality.

func (*Torrent) GetInfo

func (t *Torrent) GetInfo() *metainfo.Info

type TorrentInfo

type TorrentInfo struct {
	MetaInfo *metainfo.MetaInfo
	Path     string
	InfoHash string
	Announce string
	Size     int64
	Files    int
}

TorrentInfo contains summary information about the created torrent

func Create

func Create(opts CreateOptions) (*TorrentInfo, error)

Create creates a new torrent file with the given options. Returns TorrentInfo containing summary information about the created torrent. The torrent file is automatically saved to disk based on the output options. This is the main high-level function for torrent creation.

type VerificationResult

type VerificationResult struct {
	BadPieceIndices []int
	MissingFiles    []string
	TotalPieces     int
	GoodPieces      int
	BadPieces       int
	MissingPieces   int
	Completion      float64
}

VerificationResult holds the outcome of a torrent data verification check

func VerifyData

func VerifyData(opts VerifyOptions) (*VerificationResult, error)

VerifyData checks the integrity of content files against a torrent file. It compares the actual file data against the piece hashes in the torrent. Returns detailed verification results including bad pieces and missing files.

type VerifyOptions

type VerifyOptions struct {
	TorrentPath string
	ContentPath string
	Verbose     bool
	Quiet       bool
	Workers     int // Number of worker goroutines for verification
}

VerifyOptions holds options for the verification process

Jump to

Keyboard shortcuts

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