torrents

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SearchVideoTorrentList

func SearchVideoTorrentList(torrents []Torrent, filters SearchFilters) (map[VideoQuality]*Torrent, error)

SearchVideoTorrentList will find the first torrent in the list for each video quality, that also match the given filters. Since it returns one torrent for each known quality, the MinQuality and MaxQuality of the given filters are ignored. Returns nil if none are found.

Types

type Mirror

type Mirror struct {
	URL     string `json:"url"`
	Country string `json:"country"`
	Status  bool   `json:"status"`
}

Mirror represents a PirateBay mirror and its status.

func FallbackMirror

func FallbackMirror() Mirror

FallbackMirror returns a default Pirate Bay mirror for when the list of mirrors is unavailable. The mirror chosen for this, is one that I have personally experienced to be generally available and reliable, for the time being, and it should in no way reflect a long-term solution for mirror availability.

type MirrorFilters

type MirrorFilters struct {
	Preferred string   `toml:"preferred"`
	Whitelist []string `toml:"whitelist"`
	Blacklist []string `toml:"blacklist"`
}

MirrorFilters define filters for picking a Pirate Bay mirror.

func (*MirrorFilters) IsOk

func (m *MirrorFilters) IsOk(mirror Mirror) bool

IsOk returns true if the given mirror complies with the filters.

type MirrorScraper

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

MirrorScraper holds the url to a torrents proxy list. By default the scraper will use proxybay.github.io.

func NewMirrorScraper added in v0.14.0

func NewMirrorScraper(proxySourceURL string, mirrorFilters MirrorFilters) *MirrorScraper

NewMirrorScraper initializes a new scraper for a list of piratebay mirrors.

func (*MirrorScraper) GetMirrors

func (m *MirrorScraper) GetMirrors() ([]Mirror, error)

GetMirrors retrieves a list of PirateBay mirrors.

func (*MirrorScraper) GetProxySourceURL

func (m *MirrorScraper) GetProxySourceURL() string

GetProxySourceURL retrieves the current URL at which the scraper will attempt to fetch a list of Pirate Bay proxies from.

func (*MirrorScraper) GetTorrents

func (m *MirrorScraper) GetTorrents(query string) ([]Torrent, error)

GetTorrents fetches all available Pirate Bay mirrors and returns the first Pirate Bay page that it finds.

func (*MirrorScraper) PickMirror

func (m *MirrorScraper) PickMirror(query string) (*Mirror, error)

PickMirror fetches all available Pirate Bay mirrors and returns the first one that responds to HTTP get for the given query.

func (*MirrorScraper) SetProxySourceURL

func (m *MirrorScraper) SetProxySourceURL(url string)

SetProxySourceURL overrides the URL at which MirrorScraper will attempt to fetch a list of Pirate Bay proxies from.

type PirateBayAPIResponse added in v0.15.2

type PirateBayAPIResponse []PirateBayAPIResponseTorrent

PirateBayAPIResponse represents the response returned by the PirateBay API.

func (PirateBayAPIResponse) GetTorrents added in v0.15.2

func (response PirateBayAPIResponse) GetTorrents(mirrorURL *url.URL) []Torrent

GetTorrents converts the response from the PirateBay API into a list of torrents.

type PirateBayAPIResponseTorrent added in v0.15.2

type PirateBayAPIResponseTorrent struct {
	ID       string `json:"id"`
	Name     string `json:"name"`
	InfoHash string `json:"info_hash"`
	Leechers string `json:"leechers"`
	Seeders  string `json:"seeders"`
	NumFiles string `json:"num_files"`
	Size     string `json:"size"`
	Username string `json:"username"`
	Added    string `json:"added"`
	Status   string `json:"status"`
	Category string `json:"category"`
	IMDB     string `json:"imdb"`
}

PirateBayAPIResponseTorrent represents a torrents, as it is returned by the PirateBay API.

type PirateBayScaper

type PirateBayScaper interface {
	URL() string
	SearchURLs(query string) []string
	APISearchURLs(query string) []string
	Search(query string) ([]Torrent, error)
	SearchTimeout(query string, timeout time.Duration) ([]Torrent, error)
	SearchVideoTorrents(query string, filters SearchFilters) ([]Torrent, error)
	ParseSearchPage(doc *goquery.Document) []Torrent
}

PirateBayScaper holds the url of a PirateBay mirror on which to run torrent searches.

func FindScraper

func FindScraper(query string) (PirateBayScaper, error)

FindScraper will use the default MirrorScraper to find a suitable Pirate Bay mirror, then return a scraper for that mirror.

func NewScraper

func NewScraper(mirrorURL string) PirateBayScaper

NewScraper initializes a new PirateBay scapper from a mirror url.

type SearchFilters

type SearchFilters struct {
	VerifiedUploader bool            `long:"trusted" description:"Only consider torrents where the uploader is either VIP or Trusted." toml:"trusted"`
	MinQuality       VideoQuality    `long:"min-quality" description:"Minimum acceptable torrent quality (inclusive)." toml:"min-quality"`
	MaxQuality       VideoQuality    `long:"max-quality" description:"Maximum acceptable torrent quality (inclusive)." toml:"max-quality"`
	MinSize          string          `long:"min-size" description:"Minimum acceptable torrent size." toml:"min-size"`
	MaxSize          string          `long:"max-size" description:"Maximum acceptable torrent size." toml:"max-size"`
	MinSeeders       int             `long:"min-seeders" description:"Minimum acceptable amount of seeders." toml:"min-seeders"`
	Uploaders        UploaderFilters `toml:"uploaders"`

	// Internal, used to pass multiple substrings for filtering.
	SearchTerms   []string
	MirrorURL     string
	ProxyListURL  string
	MirrorFilters MirrorFilters
}

SearchFilters holds conditions and filters, used to search for specific torrents.

func (SearchFilters) FilterTorrents

func (f SearchFilters) FilterTorrents(torrents []Torrent) []Torrent

FilterTorrents filters the given list of torrents, returning only the ones that comply with the filters.

func (SearchFilters) FilterTorrentsCount

func (f SearchFilters) FilterTorrentsCount(torrents []Torrent, count uint) []Torrent

FilterTorrentsCount filters the given list of torrents, returning only the ones that comply with the filters, while also limiting the result to the number specified by count.

func (SearchFilters) IsOk

func (f SearchFilters) IsOk(torrent *Torrent) bool

IsOk returns true if the given torrent complies with the filters.

func (SearchFilters) MaxSizeKB

func (f SearchFilters) MaxSizeKB() (int64, error)

MaxSizeKB returns the specified minimum size in kilobytes.

func (SearchFilters) MinSizeKB

func (f SearchFilters) MinSizeKB() (int64, error)

MinSizeKB returns the specified minimum size in kilobytes.

func (SearchFilters) SearchTorrents added in v0.14.0

func (f SearchFilters) SearchTorrents(query string) ([]Torrent, error)

SearchTorrents is a shortcut function, to search for torrents given the filters, so that either the specified `MirrorURL` is used or all of them are searched.

func (SearchFilters) SearchVideoTorrents added in v0.14.0

func (f SearchFilters) SearchVideoTorrents(query string) ([]Torrent, error)

SearchVideoTorrents is a shortcut function, to search for video torrents given the filters, so that either the specified `MirrorURL` is used or all of them are searched.

func (SearchFilters) UploaderOk

func (f SearchFilters) UploaderOk(uploader string) bool

UploaderOk will return true if the given uploader's name is acceptable according to the blacklist and whitelist of the filters.

type Torrent

type Torrent struct {
	Title            string       `json:"title"`
	Size             int64        `json:"size"` // In kilobytes
	Seeders          int          `json:"seeders"`
	Leeches          int          `json:"leeches"`
	VerifiedUploader bool         `json:"verified_uploader"`
	VideoQuality     VideoQuality `json:"video_quality"`
	VideoRelease     VideoRelease `json:"video_release"`
	MirrorURL        string       `json:"mirror_url"`
	TorrentURL       string       `json:"torrent_path"`
	Magnet           string       `json:"magnet"`
	UploadTime       time.Time    `json:"upload_time"`
	Uploader         string       `json:"uploader"`
}

Torrent holds all the information regarding a torrent.

func PickVideoTorrent

func PickVideoTorrent(torrents []Torrent, filters SearchFilters) (*Torrent, error)

PickVideoTorrent functions similar to SearchTorrentList(), but instead returns the torrent with the best available video quality with at least one seeder.

func SearchTorrentList

func SearchTorrentList(torrents []Torrent, filters SearchFilters) (*Torrent, error)

SearchTorrentList will return the first torrent in the list that matches the given filters, returning nil if none is found.

func (Torrent) FullURL

func (t Torrent) FullURL() string

FullURL returns the absolute URL for this torrent, including the mirror it was scraped from.

func (*Torrent) MarshalJSON

func (t *Torrent) MarshalJSON() ([]byte, error)

MarshalJSON will override the json marshalling process so as to include the torrent's full url and its size in human readable format.

func (Torrent) PeersString

func (t Torrent) PeersString() string

PeersString returns a string representation of the torrent's connected peers in the Seeds/Peers format.

func (Torrent) SizeString

func (t Torrent) SizeString() string

SizeString returns a formatted string representation of the torrent's file size.

type UploaderFilters

type UploaderFilters struct {
	Whitelist []string `long:"whitelist" description:"Add to a whitelist of uploaders, to only consider torrents from them." toml:"whitelist"`
	Blacklist []string `long:"blacklist" description:"Add to a blacklist of uploaders, to avoid torrents from them." toml:"blacklist"`
}

UploaderFilters holds filters regarding the acceptance of a torrent's uploader.

type VideoQuality

type VideoQuality string

VideoQuality defines the standard video qualities for torrents.

const (
	// Default acts as the default quality when no other is found in the title.
	Default VideoQuality = "HDTV"

	// Low represents the 480p quality.
	Low VideoQuality = "480p"

	// Medium represents the 720p quality.
	Medium VideoQuality = "720p"

	// High represents the 1080p quality.
	High VideoQuality = "1080p"

	// UHD represents the 2160p quality.
	UHD VideoQuality = "2160p"
)

func (VideoQuality) BetterThan

func (q VideoQuality) BetterThan(quality VideoQuality) bool

BetterThan will return true if the quality passed as an argument is better than this one.

func (VideoQuality) WorseThan

func (q VideoQuality) WorseThan(quality VideoQuality) bool

WorseThan will return true if the quality passed as an argument is worse than this one.

type VideoRelease

type VideoRelease string

VideoRelease defines the release type of a video torrent.

const (
	// Cam is a copy made in a cinema using a camcorder.
	Cam VideoRelease = "Cam"

	// Telesync is a bootleg recording of a film recorded in a movie theater.
	Telesync VideoRelease = "Telesync"

	// Workprint is a copy made from an unfinished version of a film produced by the studio.
	Workprint VideoRelease = "Workprint"

	// Telecine is a opy captured from a film print using a machine that transfers the movie from its analog reel to digital format.
	Telecine VideoRelease = "Telecine"

	// PPVRip come from Pay-Per-View sources.
	PPVRip VideoRelease = "Pay-Per-View Rip"

	// Screener are early DVD or BD releases of the theatrical version of a film, typically sent to movie reviewers.
	Screener VideoRelease = "Screener"

	// DDC stands for Digital Distribution Copy and is basically the same as a Screener, but sent digitally to companies instead of via the postal system.
	DDC VideoRelease = "Digital Distribution Copy"

	// R5 is a studio produced unmastered telecine put out quickly and cheaply to compete against telecine piracy in Russia.
	R5 VideoRelease = "R5"

	// DVDRip is a final retail version of a film, typically released before it is available outside its originating region.
	DVDRip VideoRelease = "DVD-Rip"

	// DVDR is a final retail version of a film in DVD format, generally a complete copy from the original DVD.
	DVDR VideoRelease = "DVD-R"

	// TVRip is a capture source from an analog capture card (coaxial/composite/s-video connection).
	TVRip VideoRelease = "HDTV, PDTV or DSRip"

	// VODRip stands for Video-On-Demand Rip and is recorded or captured from an On-Demand service such as through a cable or satellite TV service.
	VODRip VideoRelease = "VODRip"

	// WEBDL is a file losslessly ripped from a streaming service.
	WEBDL VideoRelease = "WEB-DL"

	// WEBRip is captured from a streaming service, similarly to WEBRip, but by recording the web video stream instead of directly downloading the video.
	WEBRip VideoRelease = "WEBRip"

	// WEBCap is a rip created by capturing video from a DRM-enabled streaming service.
	WEBCap VideoRelease = "WEBCap"

	// BDRip are encoded directly from a Blu-ray disc.
	BDRip VideoRelease = "Blu-ray"
)

func ExtractVideoRelease

func ExtractVideoRelease(torrentTitle string) VideoRelease

ExtractVideoRelease parses a torrent's title and returns its video release type, if it exists.

Jump to

Keyboard shortcuts

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