bhdapi

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 11 Imported by: 1

README

About

BHD API. See: Go reference

Using:

go get github.com/moistari/bhdapi

Example:

// example/example.go
package main

import (
	"context"
	"flag"
	"fmt"
	"log"

	"github.com/moistari/bhdapi"
)

func main() {
	api := flag.String("api", "", "api key")
	rss := flag.String("rss", "", "rss key")
	flag.Parse()
	cl := bhdapi.New(
		bhdapi.WithApiKey(*api),
		bhdapi.WithRssKey(*rss, false),
	)
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()
	req := bhdapi.Search("fight club framestor")
	var found *bhdapi.Torrent
	for req.Next(ctx, cl) {
		torrent := req.Cur()
		if torrent.Name == "Fight Club 1999 BluRay 1080p DTS-HD MA 5.1 AVC REMUX-FraMeSToR" {
			found = &torrent
			break
		}
	}
	if err := req.Err(); err != nil {
		log.Fatal(err)
	}
	if found == nil {
		log.Fatal("could not find torrent")
	}
	fmt.Printf("found: %d: %s (%d)\n", found.ID, found.Name, found.Size)
	buf, err := cl.Torrent(ctx, found.ID)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("retrieved found torrent with length: %d\n", len(buf))
}

Documentation

Overview

Package bhdapi provides a bhd client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bool

type Bool bool

Bool is a bool type.

func (Bool) Int

func (b Bool) Int() int

Int returns the bool as an int.

func (Bool) MarshalJSON

func (b Bool) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the json.Marshaler interface.

func (Bool) String

func (b Bool) String() string

String satisfies the fmt.Stringer interface.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(buf []byte) error

UnmarshalJSON satisfies the json.Unmarshaler interface.

type Client

type Client struct {
	AddRssKey bool
	ApiKey    string
	RssKey    string
	Transport http.RoundTripper
	// contains filtered or unexported fields
}

Client is a BHD client.

func New

func New(opts ...Option) *Client

New creates a new BHD client.

func (*Client) Do

func (cl *Client) Do(ctx context.Context, action string, params, result interface{}) error

Do executes the action and params, decoding the result.

func (*Client) Search

func (cl *Client) Search(ctx context.Context, query ...string) (*SearchResponse, error)

Search searches for a query.

func (*Client) Torrent added in v0.1.2

func (cl *Client) Torrent(ctx context.Context, id int) ([]byte, error)

Torrent retrieves a torrent for the id.

type Option

type Option func(cl *Client)

Option is a BHD client option.

func WithApiKey

func WithApiKey(apiKey string) Option

WithApiKey is a client option to set the api key.

func WithRssKey

func WithRssKey(rssKey string, addRssKey bool) Option

WithApiKey is a client option to set the rss key.

func WithTransport added in v0.1.4

func WithTransport(transport http.RoundTripper) Option

WithTransport is a client option to set the http transport used.

type SearchRequest

type SearchRequest struct {
	// The torrent name. It does support !negative searching. Example: Christmas Movie
	Search string `json:"search,omitempty"`
	// The torrent info_hash. This is an exact match.
	InfoHash string `json:"info_hash,omitempty"`
	// The torrent folder name. This is an exact match.
	FolderName string `json:"folder_name,omitempty"`
	// The torrent included file names. This is an exact match.
	FileName string `json:"file_name,omitempty"`
	// The torrent size. This is an exact match.
	Size int64 `json:"size,omitempty"`
	// The uploaders username. Only non anonymous results will be returned.
	UploadedBy string `json:"uploaded_by,omitempty"`
	// The ID of the matching IMDB page.
	ImdbID string `json:"imdb_id,omitempty"`
	// The ID of the matching TMDB page.
	TmdbID string `json:"tmdb_id,omitempty"`
	// Any categories separated by comma(s). (TV, Movies)
	Categories []string `json:"categories,omitempty"`
	// Any types separated by comma(s). (BD Remux, 1080p, etc.)
	Types []string `json:"types,omitempty"`
	// Any sources separated by comma(s). (Blu-ray, WEB, DVD, etc.)
	Sources []string `json:"sources,omitempty"`
	// Any genres separated by comma(s). (Action, Anime, Stand-Up, Western, etc.)
	Genres []string `json:"genres,omitempty"`
	// Any internal release groups separated by comma(s). (FraMeSToR, BHDStudio, BeyondHD, RPG, iROBOT, iFT, ZR, MKVULTRA)
	Groups []string `json:"groups,omitempty"`
	// The torrent freeleech status. 1 = Must match.
	Freeleech Bool `json:"freeleech,omitempty"`
	// The torrent limited UL promo. 1 = Must match.
	Limited Bool `json:"limited,omitempty"`
	// The torrent 25% promo. 1 = Must match.
	Promo25 Bool `json:"promo25,omitempty"`
	// The torrent 50% promo. 1 = Must match.
	Promo50 Bool `json:"promo50,omitempty"`
	// The torrent 75% promo. 1 = Must match.
	Promo75 Bool `json:"promo75,omitempty"`
	// The torrent refund promo. 1 = Must match.
	Refund Bool `json:"refund,omitempty"`
	// The torrent rescue promo. 1 = Must match.
	Rescue Bool `json:"rescue,omitempty"`
	// The torrent rewind promo. 1 = Must match.
	Rewind Bool `json:"rewind,omitempty"`
	// The torrent Stream Optimized flag. 1 = Must match.
	Stream Bool `json:"stream,omitempty"`
	// The torrent SD flag. 1 = Must match.
	SD Bool `json:"sd,omitempty"`
	// The torrent TV pack flag. 1 = Must match.
	Pack Bool `json:"pack,omitempty"`
	// The torrent x264/h264 codec flag. 1 = Must match.
	H264 Bool `json:"h_264,omitempty"`
	// The torrent x265/h265 codec flag. 1 = Must match.
	H265 Bool `json:"h_265,omitempty"`
	// Any features separated by comma(s). (DV, HDR10, HDR10P, Commentary)
	Features []string `json:"features,omitempty"`
	// The torrent has at least 1 seeder. 1 = Must match.
	Alive Bool `json:"alive,omitempty"`
	// The torrent has less than 3 seeders. 1 = Must match.
	Dying Bool `json:"dying,omitempty"`
	// The torrent has no seeders. 1 = Must match.
	Dead Bool `json:"dead,omitempty"`
	// The torrent has no seeders and an active reseed request. 1 = Must match.
	Reseed Bool `json:"reseed,omitempty"`
	// The torrent is seeded by you. 1 = Must match.
	Seeding Bool `json:"seeding,omitempty"`
	// The torrent is being leeched by you. 1 = Must match.
	Leeching Bool `json:"leeching,omitempty"`
	// The torrent has been completed by you. 1 = Must match.
	Completed Bool `json:"completed,omitempty"`
	// The torrent has not been completed by you. 1 = Must match.
	Incomplete Bool `json:"incomplete,omitempty"`
	// The torrent has not been downloaded you. 1 = Must match.
	NotDownloaded Bool `json:"notdownloaded,omitempty"`
	// The minimum BHD rating.
	MinBHD int `json:"min_bhd,omitempty"`
	// The minimum number of BHD votes.
	VoteBHD int `json:"vote_bhd,omitempty"`
	// The minimum IMDb rating.
	MinImdb int `json:"min_imdb,omitempty"`
	// The minimum number of IMDb votes.
	VoteImdb int `json:"vote_imdb,omitempty"`
	// The minimum TMDb rating.
	MinTmbd int `json:"min_tmdb,omitempty"`
	// The minimum number of TDMb votes.
	VoteTmbd int `json:"vote_tmdb,omitempty"`
	// The earliest release year.
	MinYear int `json:"min_year,omitempty"`
	// The latest release year.
	MaxYear int `json:"max_year,omitempty"`
	// Any production countries separated by comma(s). (France, Japan, etc.)
	Countries []string `json:"countries,omitempty"`
	// Any spoken languages separated by comma(s). (French, English, etc.)
	Languages []string `json:"languages,omitempty"`
	// Any audio tracks separated by comma(s). (English, Japanese, etc.)
	Audios []string `json:"audios,omitempty"`
	// Any subtitles separated by comma(s). (Dutch, Finnish, Swedish, etc.)
	Subtitles []string `json:"subtitles,omitempty"`
	// Field to sort results by. (bumped_at, created_at, seeders, leechers, times_completed, size, name, imdb_rating, tmdb_rating, bhd_rating). Default is bumped_at
	Sort string `json:"sort,omitempty"`
	// The direction of the sort of results. (asc, desc). Default is desc
	Order string `json:"order,omitempty"`
	// The page number of the results. Only if the result set has more than 100 total matches.
	Page int `json:"page,omitempty"`
	// contains filtered or unexported fields
}

SearchRequest is a bhd search request.

func Search(query ...string) *SearchRequest

Search creates a new search request.

func (*SearchRequest) All added in v0.2.2

func (req *SearchRequest) All(ctx context.Context, cl *Client) ([]Torrent, error)

All returns all results for the search request.

func (*SearchRequest) Cur added in v0.2.1

func (req *SearchRequest) Cur() Torrent

Cur returns the search response cursor's current torrent. Returns the same value until Next is called. Panics if called prior to Next.

See Next for an overview of using this method.

func (*SearchRequest) Do

func (req *SearchRequest) Do(ctx context.Context, cl *Client) (*SearchResponse, error)

Do executes the search request against the client.

func (*SearchRequest) Err added in v0.2.1

func (req *SearchRequest) Err() error

Err returns the last error in the search response.

See Next for an overview of using this method.

func (*SearchRequest) Next added in v0.2.1

func (req *SearchRequest) Next(ctx context.Context, cl *Client) bool

Next returns true if there are search results available for the request.

Example:

req := bhdapi.Search()
for req.Next(ctx, cl) {
	torrent := req.Cur()
	/* ... */
}
if err := req.Err(); err != nil {
	/* ... */
}

func (*SearchRequest) PageIndex added in v0.2.3

func (req *SearchRequest) PageIndex() (int, int)

PageIndex returns the search response cursor page and index.

func (SearchRequest) WithAlive

func (req SearchRequest) WithAlive(alive bool) *SearchRequest

WithAlive sets the search alive.

func (SearchRequest) WithAudios

func (req SearchRequest) WithAudios(audios ...string) *SearchRequest

WithAudios sets the search audios.

func (SearchRequest) WithCategories

func (req SearchRequest) WithCategories(categories ...string) *SearchRequest

WithCategories sets the search categories.

func (SearchRequest) WithCompleted

func (req SearchRequest) WithCompleted(completed bool) *SearchRequest

WithCompleted sets the search completed.

func (SearchRequest) WithCountries

func (req SearchRequest) WithCountries(countries ...string) *SearchRequest

WithCountries sets the search countries.

func (SearchRequest) WithDead

func (req SearchRequest) WithDead(dead bool) *SearchRequest

WithDead sets the search dead.

func (SearchRequest) WithDying

func (req SearchRequest) WithDying(dying bool) *SearchRequest

WithDying sets the search dying.

func (SearchRequest) WithFeatures

func (req SearchRequest) WithFeatures(features ...string) *SearchRequest

WithFeatures sets the search features.

func (SearchRequest) WithFileName

func (req SearchRequest) WithFileName(fileName string) *SearchRequest

WithFileName sets the search file name value.

func (SearchRequest) WithFolderName

func (req SearchRequest) WithFolderName(folderName string) *SearchRequest

WithFolderName sets the search folder name value.

func (SearchRequest) WithFreeleech

func (req SearchRequest) WithFreeleech(freeleech bool) *SearchRequest

WithFreeleech sets the search freeleech.

func (SearchRequest) WithGenres

func (req SearchRequest) WithGenres(genres ...string) *SearchRequest

WithGenres sets the search genres.

func (SearchRequest) WithGroups

func (req SearchRequest) WithGroups(groups ...string) *SearchRequest

WithGroups sets the search groups.

func (SearchRequest) WithH264

func (req SearchRequest) WithH264(h264 bool) *SearchRequest

WithH264 sets the search h264.

func (SearchRequest) WithH265

func (req SearchRequest) WithH265(h265 bool) *SearchRequest

WithH265 sets the search h265.

func (SearchRequest) WithImdbID

func (req SearchRequest) WithImdbID(imdbID string) *SearchRequest

WithImdbID sets the search imdb id value.

func (SearchRequest) WithIncomplete

func (req SearchRequest) WithIncomplete(incomplete bool) *SearchRequest

WithIncomplete sets the search incomplete.

func (SearchRequest) WithInfoHash

func (req SearchRequest) WithInfoHash(infoHash string) *SearchRequest

WithInfoHash sets the search info hash value.

func (SearchRequest) WithLanguages

func (req SearchRequest) WithLanguages(languages ...string) *SearchRequest

WithLanguages sets the search languages.

func (SearchRequest) WithLeeching

func (req SearchRequest) WithLeeching(leeching bool) *SearchRequest

WithLeeching sets the search leeching.

func (SearchRequest) WithLimited

func (req SearchRequest) WithLimited(limited bool) *SearchRequest

WithLimited sets the search limited.

func (SearchRequest) WithMaxYear

func (req SearchRequest) WithMaxYear(maxYear int) *SearchRequest

WithMaxYear sets the search max year.

func (SearchRequest) WithMinBHD

func (req SearchRequest) WithMinBHD(minBHD int) *SearchRequest

WithMinBHD sets the search min BHD value.

func (SearchRequest) WithMinImdb

func (req SearchRequest) WithMinImdb(minImdb int) *SearchRequest

WithMinImdb sets the search min imdb.

func (SearchRequest) WithMinTmbd

func (req SearchRequest) WithMinTmbd(minTmbd int) *SearchRequest

WithMinTmbd sets the search min tmbd.

func (SearchRequest) WithMinYear

func (req SearchRequest) WithMinYear(minYear int) *SearchRequest

WithMinYear sets the search min year.

func (SearchRequest) WithNotDownloaded

func (req SearchRequest) WithNotDownloaded(notDownloaded bool) *SearchRequest

WithNotDownloaded sets the search not downloaded.

func (SearchRequest) WithOrder

func (req SearchRequest) WithOrder(order string) *SearchRequest

WithOrder sets the search order.

func (SearchRequest) WithPack

func (req SearchRequest) WithPack(pack bool) *SearchRequest

WithPack sets the search pack.

func (SearchRequest) WithPage

func (req SearchRequest) WithPage(page int) *SearchRequest

WithPage sets the search page.

func (SearchRequest) WithPromo25

func (req SearchRequest) WithPromo25(promo25 bool) *SearchRequest

WithPromo25 sets the search promo25.

func (SearchRequest) WithPromo50

func (req SearchRequest) WithPromo50(promo50 bool) *SearchRequest

WithPromo50 sets the search promo50.

func (SearchRequest) WithPromo75

func (req SearchRequest) WithPromo75(promo75 bool) *SearchRequest

WithPromo75 sets the search promo75.

func (SearchRequest) WithRefund

func (req SearchRequest) WithRefund(refund bool) *SearchRequest

WithRefund sets the search refund.

func (SearchRequest) WithRescue

func (req SearchRequest) WithRescue(rescue bool) *SearchRequest

WithRescue sets the search rescue.

func (SearchRequest) WithReseed

func (req SearchRequest) WithReseed(reseed bool) *SearchRequest

WithReseed sets the search reseed.

func (SearchRequest) WithRewind

func (req SearchRequest) WithRewind(rewind bool) *SearchRequest

WithRewind sets the search rewind.

func (SearchRequest) WithSD

func (req SearchRequest) WithSD(sd bool) *SearchRequest

WithSd sets the search sd.

func (SearchRequest) WithSeeding

func (req SearchRequest) WithSeeding(seeding bool) *SearchRequest

WithSeeding sets the search seeding.

func (SearchRequest) WithSize

func (req SearchRequest) WithSize(size int64) *SearchRequest

WithSize sets the search size value.

func (SearchRequest) WithSort

func (req SearchRequest) WithSort(sort string) *SearchRequest

WithSort sets the search sort.

func (SearchRequest) WithSources

func (req SearchRequest) WithSources(sources ...string) *SearchRequest

WithSources sets the search sources.

func (SearchRequest) WithStream

func (req SearchRequest) WithStream(stream bool) *SearchRequest

WithStream sets the search stream.

func (SearchRequest) WithSubtitles

func (req SearchRequest) WithSubtitles(subtitles ...string) *SearchRequest

WithSubtitles sets the search subtitles.

func (SearchRequest) WithTmdbID

func (req SearchRequest) WithTmdbID(tmdbID string) *SearchRequest

WithTmdbID sets the search tmdb id value.

func (SearchRequest) WithTypes

func (req SearchRequest) WithTypes(types ...string) *SearchRequest

WithTypes sets the search types.

func (SearchRequest) WithUploadedBy

func (req SearchRequest) WithUploadedBy(uploadedBy string) *SearchRequest

WithUploadedBy sets the search uploaded by value.

func (SearchRequest) WithVoteBHD

func (req SearchRequest) WithVoteBHD(voteBHD int) *SearchRequest

WithVoteBHD sets the search vote BHD value.

func (SearchRequest) WithVoteImdb

func (req SearchRequest) WithVoteImdb(voteImdb int) *SearchRequest

WithVoteImdb sets the search vote imdb.

func (SearchRequest) WithVoteTmbd

func (req SearchRequest) WithVoteTmbd(voteTmbd int) *SearchRequest

WithVoteTmbd sets the search vote tmbd.

type SearchResponse

type SearchResponse struct {
	// The status code of the post request. (0 = Failed and 1 = Success)
	StatusCode int `json:"status_code,omitempty"`
	// The current page of results that you're on.
	Page int `json:"page,omitempty"`
	// The results that match your query.
	Results []Torrent `json:"results,omitempty"`
	// The total number of pages of results matching your query.
	TotalPages int `json:"total_pages,omitempty"`
	// The total number of results matching your query.
	TotalResults int `json:"total_results,omitempty"`
	// The status of the call. (True = Success, False = Error)
	Success bool `json:"success,omitempty"`
	// The status message.
	StatusMessage string `json:"status_message,omitempty"`
}

SearchResponse is a bhd search response.

type Time

type Time struct {
	time.Time
}

Time is a time value.

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON satisfies the json.Marshaler interface.

func (Time) String

func (t Time) String() string

String satisfies the fmt.Stringer interface.

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(buf []byte) error

UnmarshalJSON satisfies the json.Unmarshaler interface.

type Torrent added in v0.1.6

type Torrent struct {
	// The BHD ID.
	ID int `json:"id,omitempty"`
	// The name.
	Name string `json:"name,omitempty"`
	// The torrent folder name.
	FolderName string `json:"folder_name,omitempty"`
	// The torrent info_hash.
	InfoHash string `json:"info_hash,omitempty"`
	// The torrent size.
	Size int64 `json:"size,omitempty"`
	// The uploaders username.
	UploadedBy string `json:"uploaded_by,omitempty"`
	// The category.
	Category string `json:"category,omitempty"`
	// The type.
	Type string `json:"type,omitempty"`
	// The seeders.
	Seeders int `json:"seeders,omitempty"`
	// The leechers.
	Leechers int `json:"leechers,omitempty"`
	// The times completed.
	TimesCompleted int `json:"times_completed,omitempty"`
	// The ID of the matching IMDB page.
	ImdbID string `json:"imdb_id,omitempty"`
	// The ID of the matching TMDB page.
	TmdbID string `json:"tmdb_id,omitempty"`
	// The BHD rating.
	BhdRating float64 `json:"bhd_rating,omitempty"`
	// The TMDb rating.
	TmdbRating float64 `json:"tmdb_rating,omitempty"`
	// The IMDb rating.
	ImdbRating float64 `json:"imdb_rating,omitempty"`
	// The torrent TV pack flag.
	TvPack Bool `json:"tv_pack,omitempty"`
	// The torrent 25% promo.
	Promo25 Bool `json:"promo25,omitempty"`
	// The torrent 50% promo.
	Promo50 Bool `json:"promo50,omitempty"`
	// The torrent 75% promo.
	Promo75 Bool `json:"promo75,omitempty"`
	// The torrent freeleech status.
	Freeleech Bool `json:"freeleech,omitempty"`
	// The torrent rewind promo.
	Rewind Bool `json:"rewind,omitempty"`
	// The torrent refund promo.
	Refund Bool `json:"refund,omitempty"`
	// The torrent limited UL promo.
	Limited Bool `json:"limited,omitempty"`
	// The torrent rescue promo.
	Rescue Bool `json:"rescue,omitempty"`
	// DV is dolby vision feature.
	DV Bool `json:"dv,omitempty"`
	// HDR10 is HDR10 feature.
	HDR10 Bool `json:"hdr10,omitempty"`
	// HDR10P is HDR10+ feature.
	HDR10P Bool `json:"hdr10+,omitempty"`
	// HLG is HLG feature.
	HLG Bool `json:"hlg,omitempty"`
	// Commentary is commentary feature.
	Commentary Bool `json:"commentary,omitempty"`
	// Internal is internal feature.
	Internal Bool `json:"internal,omitempty"`
	// The bumped at time.
	BumpedAt Time `json:"bumped_at,omitempty"`
	// The created at time.
	CreatedAt Time `json:"created_at,omitempty"`
	// The url.
	URL string `json:"url,omitempty"`
	// The download url.
	DownloadURL string `json:"download_url,omitempty"`
}

Torrent is a bhd torrent.

Directories

Path Synopsis
cmd
bhdsearch command
example/example.go
example/example.go

Jump to

Keyboard shortcuts

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