parser

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildStore added in v0.3.0

func BuildStore(n *nzbparser.Nzb) (*metapb.NzbStore, map[string]int64)

BuildStore converts a parsed NZB into a NzbStore (for persistence) plus a message-id → flat-store-index lookup used to emit SegmentRefs. Segments are stored in their natural NzbSegments order (by Number after sort).

func SanitizeNzbFilenames added in v0.3.0

func SanitizeNzbFilenames(n *nzbparser.Nzb)

SanitizeNzbFilenames normalizes poster-controlled filenames in place at the nzbparser boundary so every consumer (the pre-parse fast-fail probe, the parser, persisted metadata, and serve-time volume following) sees a canonical name. Call it immediately after nzbparser.Parse and before any code reads NzbFile.Filename. The raw subject remains available on NzbFile.Subject.

Types

type ExtractedFileInfo

type ExtractedFileInfo struct {
	Name string `json:"name"`
	Size int64  `json:"size"`
}

type FirstSegmentData

type FirstSegmentData struct {
	File                *nzbparser.NzbFile // Reference to the NZB file (for groups, subject, metadata)
	Headers             nntppool.YEncMeta  // yEnc headers (FileName, FileSize, PartSize)
	RawBytes            []byte             // Up to 16KB of raw data for PAR2 detection (may be less if segment is smaller)
	MissingFirstSegment bool               // True if first segment download failed (article not found, etc.)
	IsArticleNotFound   bool               // True only when 430 Not Found (permanent); false for timeouts/transient
	SkippedFirstSegment bool               // True when the fetch was intentionally skipped (clean-named multipart file); Headers/RawBytes are empty by design, not by failure
	OriginalIndex       int                // Original position in the parsed NZB file list
}

FirstSegmentData holds cached data from the first segment of an NZB file This avoids redundant fetching when both PAR2 extraction and file parsing need the same data

type NzbType

type NzbType string

NzbType represents the type of NZB content

const (
	NzbTypeSingleFile NzbType = "single_file"
	NzbTypeMultiFile  NzbType = "multi_file"
	NzbTypeRarArchive NzbType = "rar_archive"
	NzbType7zArchive  NzbType = "7z_archive"
	NzbTypeStrm       NzbType = "strm_file"
)

type ParseOptions added in v0.3.0

type ParseOptions struct {
	// BrokenFileIndexes contains the 0-based positions (in the Nzb.Files slice)
	// of files whose sampled segments failed a pre-parse Stat check. Their first
	// segments are short-circuited to MissingFirstSegment=true without a Body call.
	BrokenFileIndexes map[int]struct{}
	// KnownMissingSegmentIDs seeds notFoundIDs so yEnc normalisation and 16KB
	// completion never re-issue Stat/Body calls for already-known-missing IDs.
	KnownMissingSegmentIDs map[string]struct{}
}

ParseOptions carries pre-parse knowledge into ParseNzb, allowing the processor to skip Body fetches for files whose segments are already known to be missing (identified by a pre-parse Stat check).

type ParsedFile

type ParsedFile struct {
	Subject       string
	Filename      string
	Size          int64
	Segments      []*metapb.SegmentData
	SegmentRefs   []*metapb.SegmentRef // v3: refs into NzbStore (populated when Store != nil)
	Groups        []string
	IsRarArchive  bool
	Is7zArchive   bool
	IsPar2Archive bool
	Encryption    metapb.Encryption // Encryption type (e.g., "rclone"), nil if not encrypted
	Password      string            // Password from NZB meta, nil if not encrypted
	Salt          string            // Salt from NZB meta, nil if not encrypted
	ReleaseDate   time.Time         // Release date from the Usenet post
	OriginalIndex int               // Original position in the parsed NZB file list
	NzbdavID      string            // Original ID from nzbdav (for backward compatibility)
	AesKey        []byte            // AES encryption key (for nzbdav compatibility)
	AesIv         []byte            // AES initialization vector (for nzbdav compatibility)

	// FirstSegmentBytes holds the decoded leading bytes (≤16KB) of this file's first
	// segment, captured when the parser fetched it during first-segment analysis. It
	// lets the archive analysis phase (UsenetFileSystem) serve a volume's header read,
	// which starts at offset 0, from memory instead of re-fetching a segment already
	// pulled over the wire this import. Empty when the first segment was skipped/missing
	// or for files built outside the parser — those paths fall through to the network.
	// Transient (not persisted); valid only for the lifetime of the import.
	FirstSegmentBytes []byte
}

ParsedFile represents a file extracted from the NZB

type ParsedNzb

type ParsedNzb struct {
	Path          string
	Filename      string
	TotalSize     int64
	Type          NzbType
	Files         []ParsedFile
	SegmentsCount int

	ExtractedFiles []ExtractedFileInfo
	Store          *metapb.NzbStore // NzbStore for this release (built at parse time)
	SegmentIndex   map[string]int64 // message-id → flat store index
	// contains filtered or unexported fields
}

ParsedNzb contains the parsed NZB data and extracted metadata

func (*ParsedNzb) GetPassword

func (p *ParsedNzb) GetPassword() string

GetPassword returns the password for this NZB

func (*ParsedNzb) SetPassword

func (p *ParsedNzb) SetPassword(password string)

SetPassword sets the password for this NZB

type Parser

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

Parser handles NZB file parsing

func NewParser

func NewParser(poolManager pool.Manager, getConfig config.ConfigGetter) *Parser

NewParser creates a new NZB parser

func (*Parser) GetMetadata

func (p *Parser) GetMetadata(nzbXML *nzbparser.Nzb) map[string]string

GetMetadata extracts metadata from the NZB head section

func (*Parser) ParseFile

func (p *Parser) ParseFile(ctx context.Context, r io.Reader, nzbPath string, progressTracker progress.ProgressTracker) (*ParsedNzb, error)

ParseFile parses an NZB file from a reader. progressTracker, if non-nil, receives incremental updates as first segments are fetched (the longest phase). It is safe to pass nil — updates are skipped.

func (*Parser) ParseNzb added in v0.3.0

func (p *Parser) ParseNzb(ctx context.Context, n *nzbparser.Nzb, nzbPath string, progressTracker progress.ProgressTracker, opts ParseOptions) (*ParsedNzb, error)

ParseNzb processes an already-parsed *nzbparser.Nzb, performing all network operations (first-segment fetches, PAR2 extraction, yEnc normalisation). opts carries knowledge collected before the network phase, e.g. file indexes whose segments are already known to be missing from a pre-parse Stat check.

func (*Parser) ValidateNzb

func (p *Parser) ValidateNzb(parsed *ParsedNzb) error

ValidateNzb performs basic validation on the parsed NZB

type StrmParser

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

StrmParser handles STRM file parsing containing NXG links

func NewStrmParser

func NewStrmParser() *StrmParser

NewStrmParser creates a new STRM parser

func (*StrmParser) ParseStrmFile

func (p *StrmParser) ParseStrmFile(r io.Reader, strmPath string) (*ParsedNzb, error)

ParseStrmFile parses a STRM file containing an NXG link

func (*StrmParser) ValidateStrmFile

func (p *StrmParser) ValidateStrmFile(parsed *ParsedNzb) error

ValidateStrmFile performs basic validation on the parsed STRM file

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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