nhentai

package module
v0.0.0-...-7996917 Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: MIT Imports: 10 Imported by: 0

README

go-nhentai

Documentation

Overview

Package nhentai provides Go bindings for nhentai.net's API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// EndpointNH is the main endpoint of nhentai.net.
	EndpointNH = "https://nhentai.net"
	// EndpointGallery is the main endpoint where galleries are located.
	EndpointGallery = EndpointNH + "/g"
	// EndpointAPI is nhentai's API endpoint.
	EndpointAPI = EndpointNH + "/api"
	// EndpointAPIGallery is nhentai's API endpoint for individual galleries.
	EndpointAPIGallery = EndpointAPI + "/gallery"
	// EndpointAPIGalleries is nhentai's API endpoint for multiple galleries. This
	// is primarily used for the search API, which has not been implemented in
	// this package as of yet.
	EndpointAPIGalleries = EndpointAPI + "/galleries"
	// EndpointAPISearch is nhentai's search API endpoint.
	EndpointAPISearch = EndpointAPIGalleries + "/search"
	// EndpointAPITagged is nhentai's endpoint for multiple galleries with
	// specified tags.
	EndpointAPITagged = EndpointAPIGalleries + "/tagged"
	// EndpointAPIAll is nhentai's endpoint for muliple galleries. Honestly I'm
	// not sure what this even does, I'll remove it later if it turns out I don't
	// need it.
	EndpointAPIAll = EndpointAPIGalleries + "/all"

	// EndpointThumbs is the main endpoint of t.nhentai.net, which is primarily
	// used to store thumbnails and covers of doujins.
	EndpointThumbs = "https://t.nhentai.net"
	// EndpointThumbsGalleries is nhentai's API endpoint for gallery thumbnails
	// and covers.
	EndpointThumbsGalleries = EndpointThumbs + "/galleries"

	// EndpointImages is the main endpoint of i.nhentai.net, which is primarily
	// used to store the pages of doujins.
	EndpointImages = "https://i.nhentai.net"
	// EndpointImageGalleries is nhentai's API endpoint for gallery images, such
	// as pages.
	EndpointImagesGalleries = EndpointImages + "/galleries"
)

Functions

This section is empty.

Types

type Client

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

func New

func New() *Client

func (*Client) GalleryFromID

func (client *Client) GalleryFromID(galleryID int) (*Gallery, error)

GalleryFromID takes an ID for a gallery and requests the nhentai API for information about that gallery, then makes and returns a pointer to a struct. If any error occurs, it returns a blank struct and the error.

func (*Client) GalleryFromURL

func (client *Client) GalleryFromURL(galleryURL string) (*Gallery, error)

GalleryFromURL parses a gallery ID from an nhentai URL, then runs GalleryFromID using that ID.

type Gallery struct {
	ID              int    `json:"id"`
	MediaID         string `json:"media_id"`
	Characters      []*Tag
	Parodies        []*Tag
	Tags            []*Tag
	Artists         []*Tag
	Groups          []*Tag
	Languages       []*Tag
	Categories      []*Tag
	PagesCount      int       `json:"num_pages"`
	FavouritesCount int       `json:"favourites"`
	Timestamp       Timestamp `json:"upload_date"`
	Title           struct {
		Japanese string `json:"japanese"`
		Pretty   string `json:"pretty"`
		English  string `json:"english"`
	} `json:"title"`
	Images struct {
		Cover     *Image   `json:"cover"`
		Thumbnail *Image   `json:"thumbnail"`
		Pages     []*Image `json:"pages"`
	} `json:"images"`
	Scanlator string `json:"scanlator"`

	AllTags []*Tag `json:"tags"`
}

Gallery represents an nhentai gallery.

func (*Gallery) GetRelated

func (gallery *Gallery) GetRelated() ([]*Gallery, error)

func (*Gallery) HasArtist

func (gallery *Gallery) HasArtist(name string) bool

func (*Gallery) HasCategory

func (gallery *Gallery) HasCategory(name string) bool

func (*Gallery) HasCharacter

func (gallery *Gallery) HasCharacter(name string) bool

func (*Gallery) HasGroup

func (gallery *Gallery) HasGroup(name string) bool

func (*Gallery) HasLanguage

func (gallery *Gallery) HasLanguage(name string) bool

func (*Gallery) HasParody

func (gallery *Gallery) HasParody(name string) bool

func (*Gallery) HasTag

func (gallery *Gallery) HasTag(name string) bool

func (*Gallery) URL

func (gallery *Gallery) URL() string

type Image

type Image struct {
	Width  int    `json:"w"`
	Height int    `json:"h"`
	Type   string `json:"t"`
	URL    string
	Ext    string
}

Image represents a gallery image.

type Query

type Query struct {
	Terms       []string `json:"terms"`
	Page        int      `json:"page"`
	SortPopular bool     `json:"sort_popular"`
}

Query is a search query used by search functions.

type Response

type Response struct {
	Result   []*Gallery `json:"result"`
	PerPage  int        `json:"per_page"`
	NumPages int        `json:"num_pages"`
}

Response is the response from a search query.

func Search(query Query) (*Response, error)

type Tag

type Tag struct {
	ID    int    `json:"id"`
	Type  string `json:"type"`
	Name  string `json:"name"`
	URL   string `json:"url"`
	Count int    `json:"count"`
}

Tag represents a gallery tag.

type Timestamp

type Timestamp int64

Timestamp is an alias for int64, used to store the time a gallery was uploaded to nhentai

func (Timestamp) Parse

func (timestamp Timestamp) Parse() time.Time

Parse parses the timestamp into a time.Time struct.

Jump to

Keyboard shortcuts

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