scraper

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package scraper provides a modular interface for torrent search providers. It defines the Scraper interface and common types. Users can implement custom scrapers for their preferred sources or use the GenericScraper which works with any site that provides magnet links.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestSearch

func TestSearch(ctx context.Context, baseURL string) (int, error)

TestSearch performs a test search to verify the site works

func ValidateURL

func ValidateURL(ctx context.Context, rawURL string) (string, error)

ValidateURL checks if a URL is reachable and looks like a torrent site

Types

type DummyScraper

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

DummyScraper is a no-op scraper that returns empty results. It serves as the default scraper when no sources are configured, ensuring the TUI remains functional without any external dependencies.

func NewDummyScraper

func NewDummyScraper() *DummyScraper

NewDummyScraper creates a dummy scraper that returns no results.

func (*DummyScraper) GetFiles

func (s *DummyScraper) GetFiles(ctx context.Context, t *Torrent) error

GetFiles is a no-op.

func (*DummyScraper) Name

func (s *DummyScraper) Name() string

Name returns the scraper name.

func (*DummyScraper) Search

func (s *DummyScraper) Search(ctx context.Context, query string) ([]Torrent, error)

Search returns empty results.

type ExampleScraper

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

ExampleScraper demonstrates how to implement the Scraper interface. This is a reference implementation for developers who want to create their own scraper for a specific site.

To create a custom scraper:

  1. Implement the Scraper interface (Name, Search, GetFiles)
  2. Parse HTML responses to extract torrent information
  3. Return properly populated Torrent structs

Example usage:

scraper := NewExampleScraper()
results, err := scraper.Search(ctx, "query")

func NewExampleScraper

func NewExampleScraper() *ExampleScraper

NewExampleScraper creates an example scraper instance. In a real implementation, you would pass configuration here such as the base URL, authentication credentials, etc.

func (*ExampleScraper) GetFiles

func (s *ExampleScraper) GetFiles(ctx context.Context, t *Torrent) error

GetFiles fetches the file list for a torrent. This is called when viewing torrent details in the TUI. A real implementation would:

  1. Navigate to the torrent's detail page (using InfoURL)
  2. Parse the page to find file listings
  3. Populate the Files slice on the Torrent struct
  4. Optionally fetch the magnet link if not already present

func (*ExampleScraper) Name

func (s *ExampleScraper) Name() string

Name returns the scraper's display name. This appears in the TUI's source list and search results.

func (*ExampleScraper) Search

func (s *ExampleScraper) Search(ctx context.Context, query string) ([]Torrent, error)

Search queries the source for torrents matching the query. This example returns empty results. A real implementation would:

  1. Construct a search URL with the query
  2. Make an HTTP request
  3. Parse the HTML response
  4. Extract torrent metadata (name, size, seeders, etc.)
  5. Return a slice of Torrent structs

type FileInfo

type FileInfo struct {
	Name string
	Size string
}

FileInfo represents a file within a torrent

type GenericScraper

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

GenericScraper attempts to scrape any torrent site using heuristics

func NewGenericScraper

func NewGenericScraper(name, baseURL string) *GenericScraper

NewGenericScraper creates a scraper for an arbitrary torrent site

func (*GenericScraper) GetFiles

func (s *GenericScraper) GetFiles(ctx context.Context, t *Torrent) error

GetFiles fetches additional info from torrent detail page

func (*GenericScraper) Name

func (s *GenericScraper) Name() string

Name returns the source name

func (*GenericScraper) Search

func (s *GenericScraper) Search(ctx context.Context, query string) ([]Torrent, error)

Search queries the site for torrents

type MultiScraper

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

MultiScraper aggregates results from multiple sources

func NewMultiScraper

func NewMultiScraper(scrapers ...Scraper) *MultiScraper

NewMultiScraper creates a scraper that queries multiple sources

func (*MultiScraper) Search

func (m *MultiScraper) Search(ctx context.Context, query string) ([]Torrent, error)

Search queries all scrapers and merges results

type Scraper

type Scraper interface {
	// Name returns the source name
	Name() string

	// Search queries for torrents
	Search(ctx context.Context, query string) ([]Torrent, error)

	// GetFiles fetches file list for a torrent (if supported)
	GetFiles(ctx context.Context, t *Torrent) error
}

Scraper interface for torrent search providers

type Torrent

type Torrent struct {
	Name     string
	Size     string
	Seeders  int
	Leechers int
	Magnet   string
	InfoURL  string
	Source   string
	Files    []FileInfo
}

Torrent represents a search result

func (Torrent) Health

func (t Torrent) Health() int

Health returns a health score 0-100 based on seeders/leechers ratio

Jump to

Keyboard shortcuts

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