common

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TorrentURL is the map of site names to URLs (loaded from config)
	TorrentURL = map[string]string{}
	// UserAgent for HTTP requests
	UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
)

Functions

func AddSite

func AddSite(name, url, language string) error

AddSite adds a new site configuration

func CheckNetWorkFromURL

func CheckNetWorkFromURL(url string) bool

CheckNetWorkFromURL function checks network status

func CollectData

func CollectData(s []Scraping, keyword string, spinner *Spinner) map[string]string

CollectData function executes web scraping based on each scrapper

func CollectDataEx

func CollectDataEx(s []ScrapingEx, keyword string, spinner *Spinner) map[string][]string

CollectDataEx function executes web scraping based on each scrapper

func EnableSite

func EnableSite(name string, enabled bool) error

EnableSite enables or disables a site

func GetAvailableSites

func GetAvailableSites(oldItems []Scraping) ([]Scraping, *Spinner)

GetAvailableSites function gets available torrent sites

func GetAvailableSitesEx

func GetAvailableSitesEx(oldItems []ScrapingEx) ([]ScrapingEx, *Spinner)

GetAvailableSitesEx function gets available torrent sites

func GetConfigPath

func GetConfigPath() string

GetConfigPath returns the config file path

func GetEnabledSites

func GetEnabledSites(language string) map[string]SiteConfig

GetEnabledSites returns all enabled sites for a language

func GetResponseFromURL

func GetResponseFromURL(url string) (resp *http.Response, ok bool)

GetResponseFromURL returns *http.Response from url

func ListSites

func ListSites()

ListSites prints all configured sites

func PrintData

func PrintData(data map[string]string)

PrintData function prints scraped data to console

func PrintDataEx

func PrintDataEx(data map[string][]string)

PrintDataEx function prints scraped data to console

func PrintDoctorStatus

func PrintDoctorStatus(statuses []SiteStatus)

PrintDoctorStatus prints the doctor status in a formatted way

func RemoveNonAscII

func RemoveNonAscII(s string) string

RemoveNonAscII remove non-ASCII characters

func RemoveSite

func RemoveSite(name string) error

RemoveSite removes a site from configuration

func SaveConfig

func SaveConfig(c *Config) error

SaveConfig saves the configuration to file

func SetSiteURL

func SetSiteURL(name, url string) error

SetSiteURL updates a site's URL

func URLJoin

func URLJoin(baseURL string, relURL string) string

URLJoin function join baseURL and relURL

Types

type Config

type Config struct {
	Sites     map[string]SiteConfig `json:"sites"`
	UserAgent string                `json:"user_agent"`
	Timeout   int                   `json:"timeout_seconds"`
}

Config holds the application configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration

func GetConfig

func GetConfig() *Config

GetConfig returns the current configuration

func LoadConfig

func LoadConfig() *Config

LoadConfig loads the configuration from file or creates default

type Scraping

type Scraping interface {
	Crawl(string) map[string]string
}

Scraping interface is for web scraping

type ScrapingEx

type ScrapingEx interface {
	Crawl(string) map[string][]string
}

ScrapingEx interface is for web scraping

type SiteConfig

type SiteConfig struct {
	URL      string `json:"url"`
	Enabled  bool   `json:"enabled"`
	Language string `json:"language"` // "kr" or "jp"
}

SiteConfig holds configuration for a single torrent site

type SiteStatus

type SiteStatus struct {
	Name      string
	URL       string
	Available bool
	Latency   time.Duration
	Error     string
	Language  string
	Enabled   bool
}

SiteStatus represents the health status of a site

func Doctor

func Doctor(language string) []SiteStatus

Doctor checks all configured sites and returns their status

type Spinner

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

Spinner for progress animation

func NewSpinner

func NewSpinner(message string) *Spinner

NewSpinner creates a new spinner

func (*Spinner) IncrDone

func (s *Spinner) IncrDone()

IncrDone increments the done counter

func (*Spinner) SetTotal

func (s *Spinner) SetTotal(total int)

SetTotal sets the total number of tasks

func (*Spinner) Start

func (s *Spinner) Start()

Start begins the spinner animation

func (*Spinner) Stop

func (s *Spinner) Stop()

Stop stops the spinner

func (*Spinner) StopWithMessage

func (s *Spinner) StopWithMessage(msg string)

StopWithMessage stops and prints final message

func (*Spinner) UpdateMessage

func (s *Spinner) UpdateMessage(msg string)

UpdateMessage updates the spinner message

Jump to

Keyboard shortcuts

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