site

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2025 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Error that indicates the feature is not implemented in current site.
	ErrUnimplemented = fmt.Errorf("not implemented yet")
)

Functions

func CreateSiteHttpClient added in v0.1.1

func CreateSiteHttpClient(siteConfig *config.SiteConfigStruct, globalConfig *config.ConfigStruct) (
	*azuretls.Session, [][]string, error)

func DownloadTorrentByUrl added in v0.1.1

func DownloadTorrentByUrl(siteInstance Site, httpClient *azuretls.Session, torrentUrl string, torrentId string) (
	[]byte, string, error)

General download torrent func. Return torrentContent, filename, err

func Exit added in v0.1.6

func Exit()

called by main codes on program exit. clean resources

func GetConfigSiteNameByDomain added in v0.1.1

func GetConfigSiteNameByDomain(domain string) (string, error)

func GetConfigSiteNameByTypes added in v0.1.1

func GetConfigSiteNameByTypes(types ...string) (string, error)

func GetUa added in v0.1.8

func GetUa(siteInstance Site) string

return site ua from siteConfig and globalConfig

func PrintDummyStatus added in v0.1.10

func PrintDummyStatus(f io.Writer, name string, info string)

func PrintTorrents

func PrintTorrents(output io.Writer, torrents []*Torrent, filter string, now int64,
	noHeader bool, dense bool, scores map[string]float64)

func Purge added in v0.1.6

func Purge(sitename string)

Purge site cache

func Register

func Register(regInfo *RegInfo)

func SiteExists added in v0.1.6

func SiteExists(name string) bool

func UploadTorrent added in v0.1.10

func UploadTorrent(siteInstance Site, httpClient *azuretls.Session, uploadUrl string, contents []byte,
	metadata url.Values, fallbackPayloadTemplate map[string]string) (res *azuretls.Response, err error)

Do a multipart/form type post request to upload torrent to site, return site response. metadata is used as context when rendering payloadTemplate, the rendered payload be posted to site. All values in payload will be TrimSpaced. Some metadata names are specially handled:

_cover : cover image file path, got uploaded to site image server then replaced with uploaded img url.
_images (array) : images other than cover, processed similar with _cover but rendered as slice.
_raw_* : direct raw data that will be rendered and added to payload.
_site_<sitename>_* : site specific raw data.
_array_keys : variable of these keys are rendered as array.

Types

type RegInfo

type RegInfo struct {
	Name    string
	Aliases []string
	Creator func(string, *config.SiteConfigStruct, *config.ConfigStruct) (Site, error)
}

func GetConfigSiteReginfo

func GetConfigSiteReginfo(name string) *RegInfo

type Site

type Site interface {
	GetName() string
	// default sent http request headers
	GetDefaultHttpHeaders() [][]string
	GetSiteConfig() *config.SiteConfigStruct
	// download torrent by id (e.g. 12345), sitename.id (e.g. mteam.12345),
	// or absolute download url (e.g. https://kp.m-team.cc/download.php?id=12345).
	DownloadTorrent(url string) (content []byte, filename string, id string, err error)
	// download torrent by torrent id (e.g. "12345")
	DownloadTorrentById(id string) (content []byte, filename string, err error)
	GetLatestTorrents(full bool) ([]*Torrent, error)
	// sort: size|name|none(or "")
	GetAllTorrents(sort string, desc bool, pageMarker string, baseUrl string) (
		torrents []*Torrent, nextPageMarker string, err error)
	// can use "%s" as keyword placeholder in baseUrl
	SearchTorrents(keyword string, baseUrl string) ([]*Torrent, error)
	// Publish (upload) new torrent to site, return uploaded torrent id
	// Some keys in metadata should be handled specially:
	// If metadata contains "_dryrun", use dry run mode;
	PublishTorrent(contents []byte, metadata url.Values) (id string, err error)
	GetStatus() (*Status, error)
	PurgeCache()
}

func CreateSite

func CreateSite(name string) (Site, error)

func CreateSiteInternal

func CreateSiteInternal(name string,
	siteConfig *config.SiteConfigStruct, config *config.ConfigStruct) (Site, error)

type SiteCreator

type SiteCreator func(*RegInfo) (Site, error)

type Status

type Status struct {
	UserName            string
	UserDownloaded      int64
	UserUploaded        int64
	TorrentsSeedingCnt  int64
	TorrentsLeechingCnt int64
}

func (*Status) IsOk added in v0.1.8

func (status *Status) IsOk() bool

Check if (seems) as a valid site status

func (*Status) Print added in v0.1.10

func (ss *Status) Print(f io.Writer, name string, additionalInfo string)

type Torrent

type Torrent struct {
	Name               string
	Description        string
	Id                 string // optional torrent id in the site
	InfoHash           string
	DownloadUrl        string
	DownloadMultiplier float64
	UploadMultiplier   float64
	DiscountEndTime    int64
	Time               int64 // torrent timestamp
	Size               int64
	IsSizeAccurate     bool
	Seeders            int64
	Leechers           int64
	Snatched           int64
	HasHnR             bool     // true if has any type of HR
	IsActive           bool     // true if torrent is or had ever been downloaded / seeding
	IsCurrentActive    bool     // true if torrent is currently downloading / seeding. If true, so will be IsActive
	Paid               bool     // "付费"种子: (第一次)下载或汇报种子时扣除魔力/积分
	Bought             bool     // 适用于付费种子:已购买
	Neutral            bool     // 中性种子:不计算上传、下载、做种魔力
	Tags               []string // labels, e.g. category and other meta infos.
}

@todo: considering changing it to interface

func (*Torrent) HasAnyTag added in v0.1.10

func (torrent *Torrent) HasAnyTag(tags []string) bool

Return true if torrent has any tag of the tags list.

func (*Torrent) HasTag added in v0.1.10

func (torrent *Torrent) HasTag(tag string) bool

func (*Torrent) ID added in v0.1.10

func (torrent *Torrent) ID() string

Get real (number) id, removing sitename prefix

func (*Torrent) MatchFilter added in v0.1.4

func (torrent *Torrent) MatchFilter(filter string) bool

func (*Torrent) MatchFiltersAndOr added in v0.1.9

func (torrent *Torrent) MatchFiltersAndOr(filtersArray [][]string) bool

Matches if every list of filtersArray is successed with MatchFiltersOr(). If filtersArray is empty, return true.

func (*Torrent) MatchFiltersOr added in v0.1.7

func (torrent *Torrent) MatchFiltersOr(filters []string) bool

Matches if any filter in list matches

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳