gonhentai

package module
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: MIT Imports: 17 Imported by: 0

README

Contributors Forks Stargazers Issues MIT License

GoDoc Go Report Card Sourcegraph


Logo

GOnhentai

A simple GoLang library for nHentai
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact

About The Project

GOnhentai is a simple generic library that tries to create a base for all programs written in GO that use data from the nhentai site.

This library introduces new features, including the management of comments and some user features (WIP).

Getting Started

To download and start using the library follow these simple:

Prerequisites

  • go >=1.16

Installation

go get github.com/KiritoNya/gonhentai

Usage

Let's now see how the library is used with some small examples of common use.

Doujinshi info

// Create Doujinshi object and get some information
doujin, err := gonhentai.NewDoujinshiId(354862)
if err != nil {
	panic(err)
}

fmt.Println("Doujinshi:", doujin)

Doujinshi Page Image

// Create Object
doujin, err := gonhentai.NewDoujinshiId(354862)
if err != nil {
panic(err)
}

page := doujin.Pages[35]

// Generate the url of page
err := page.GetUrl()
if err != nil {
	panic(err)
}

// Get the data of page image
err := page.GetData()
if err != nil {
	panic(err)
}

fmt.Println("DATA:", page.Data)

Comments

// Create Doujinshi object and get some information
doujin, err := gonhentai.NewDoujinshiId(354862)
if err != nil {
	panic(err)
}

// Get comments
err := doujin.GetComments()
if err != nil {
	panic(err)
}

fmt.Println("Comments:", doujin.Comments)

Download Page Image

The library already provides you a method to download the image and save it on your PC. Set the UseProgressBar variable to true if you decide to use the progress bar. Set ProgressBarTemplate variable If you want to use your progress bar defined by pb template.

// Create Doujinshi object
doujin, err := gonhentai.NewDoujinshiId(354862)
if err != nil {
	panic(err)
}

page := doujin.Pages[36]

// Generate url of page
err := page.GetUrl()
if err != nil {
	panic(err)
}

// Default is false
// Set it to true if you want a progress bar
gonhentai.UseProgressBar = true

// Use this code for set your progress bar template.
// gonhentai.ProgressBarTemplate = `{{ red "With funcs:" }} {{ bar . "<" "-" (cycle . "↖" "↗" "↘" "↙" ) "." ">"}} {{speed . | rndcolor }} {{percent .}} {{string . "my_green_string" | green}} {{string . "my_blue_string" | blue}}`

// Download image
err := page.Save("./img.jpg", 0644)
if err != nil {
	panic(err)
}

Download Doujinshi

To download a doujinshi a path is required which must be provided via a template. To form your path you can use all the fields of the Doujinshi object and all the fields of the page object, adding respectively .Doujinshi, .Page.

EX: /home/<username>/{{.Doujinshi.Id}} - {{.Doujinshi.Title.Pretty}}/{{.Page.Num}}.{{.Page.Ext}}

// Create Doujinshi object
doujin, err := gonhentai.NewDoujinshiId(354862)
if err != nil {
panic(err)
}

// You can use also
pathTemplate := gonhentai.DefaultDoujinNameTemplate + "/" + nehentai.DefaultPageNameTemplate

// Save doujinshi
err = d.Save("/home/<username/" + pathTemplate, 0644)
if err != nil {
t.Fatal(err)
}

fmt.Println("Doujinshi saved!")
// Simple search
qr, err := nhentai.Search("Blend s", nhentai.QueryOptions{Page: "1"})
if err != nil {
	panic(err)
}
fmt.Println(qr)

// Tagged search
qr, err = nhentai.SearchTag(29859, nhentai.QueryOptions{Page: "1"})
if err != nil {
    panic(err)
}
fmt.Println(qr)

// Custom search
qr, err := nhentai.SearchCustom("Blend s", nhentai.QueryFilter {
    ToDelete: []nhentai.Filter{
        {
            Id:   0,
            Name: "yaoi",
            Type: nhentai.Tag,
        },
	},
    ToFilter: []nhentai.Filter{
        {
            Id:   0,
            Name: "maika sakuranomiya",
            Type: nhentai.Character,
        },
    },
})

// Check error
if err != nil {
    panic(err)
}
fmt.Println(qr)

For more examples, please refer to the Documentation


TODO

  • Random sauce
  • User Info
  • Authenticate
  • Favourites
  • Generate PDF
  • Generate CBR/CBZ
  • Tags list

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

KiritoNya - @YuriLov95141178 - watashiwayuridaisuki@gmail.com

Anilist: KiritnoNya

Documentation

Index

Constants

View Source
const (

	// BaseUrl is the url base of site
	BaseUrl string = "https://nhentai.net"

	// DoujinBaseUrl is the prefix that comes before the id in the doujinshi url
	DoujinBaseUrl string = "https://nhentai.net/g/"

	// ImageBaseUrl is base url for the image link
	ImageBaseUrl string = "https://i.nhentai.net"

	// ThumbnailBaseUrl is the base url for the thumbnail link
	ThumbnailBaseUrl string = "https://t.nhentai.net"

	// DefaultPageNameTemplate is the default template for generate the image name in the Doujinshi.Save method
	DefaultPageNameTemplate string = "{{.Page.Num}}.{{.Page.Ext}}"

	// DefaultDoujinNameTemplate is the default template for generate the doujin name folder in the Doujinshi.Save method
	DefaultDoujinNameTemplate string = "{{.Doujinshi.Id}} - {{.Doujinshi.Title.Pretty}}"
)
View Source
const (
	// Recent order
	Recent = ""

	// PopularAllTime order
	PopularAllTime = "popular"

	// PopularThisWeek order
	PopularThisWeek = "popular-week"

	// PopularToday order
	PopularToday = "popular-today"
)

Variables

View Source
var ClientHttp *http.Client

ClientHttp is the client used for http requests. The default value is http.DefaultClient.

View Source
var ProgressBarTemplate string

ProgressBarTemplate is template for the progress bar

View Source
var UseProgressBar bool

UseProgressBar used for some methods. By default it is false and the progress bar not used, but it can be set to true and the progress bar will be used automatically where necessary.

Functions

This section is empty.

Types

type Avatar added in v0.0.3

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

Avatar is a struct that contains all the information of a user avatar

func (*Avatar) GenerateName added in v0.0.3

func (i *Avatar) GenerateName(name, suffix string) error

GenerateName is a function that generates the image name from the object data and assign it to the field object Name

func (*Avatar) GetData added in v0.0.3

func (i *Avatar) GetData() error

GetData is a function that gets the data of image and assign it to the field object Data

func (*Avatar) GetSize added in v0.0.3

func (i *Avatar) GetSize() error

GetSize is a function that gets the size of the image and assign it to the object

func (*Avatar) Save added in v0.0.3

func (i *Avatar) Save(path string, perm os.FileMode) error

Save is a function that save the image on disk.

type Comment

type Comment struct {
	Id        int `validate:"min=0"`
	GalleryId int `validate:"min=0"`
	Poster    *User
	PostDate  time.Time
	Body      string
}

Comment is a struct that contains all the information of a comment

func (*Comment) UnmarshalJSON added in v0.1.2

func (c *Comment) UnmarshalJSON(b []byte) error

UnmarshalJSON is a json parse for the comment object

type Cover added in v0.0.3

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

Cover is a struct that contains all the information of the doujinshi cover

func (*Cover) GenerateName added in v0.0.3

func (i *Cover) GenerateName(name, suffix string) error

GenerateName is a function that generates the image name from the object data and assign it to the field object Name

func (*Cover) GetData added in v0.0.3

func (i *Cover) GetData() error

GetData is a function that gets the data of image and assign it to the field object Data

func (*Cover) GetSize added in v0.0.3

func (i *Cover) GetSize() error

GetSize is a function that gets the size of the image and assign it to the object

func (*Cover) GetUrl added in v0.0.3

func (c *Cover) GetUrl(mediaId int) error

GetUrl is a function that get the url of cover image and assign it to the Cover object

func (*Cover) Save added in v0.0.3

func (i *Cover) Save(path string, perm os.FileMode) error

Save is a function that save the image on disk.

type Doujinshi

type Doujinshi struct {
	Id           int
	Url          string
	MediaId      int
	Title        *Title
	CoverImage   *Cover
	Thumbnail    *Thumbnail
	Pages        []*Page
	Scanlator    string
	UploadDate   time.Time
	Parodies     []*TagInfo
	Characters   []*TagInfo
	Tags         []*TagInfo
	Artists      []*TagInfo
	Groups       []*TagInfo
	Languages    []*TagInfo
	Categories   []*TagInfo
	NumPages     int
	NumFavorites int
	Related      []*Doujinshi
	Comments     []*Comment
	// contains filtered or unexported fields
}

Doujinshi is the data struct that describes a manga or a doujinshi

func NewDoujinshiId

func NewDoujinshiId(id int) (*Doujinshi, error)

NewDoujinshiId is a constructor of the doujinshi object

func NewDoujinshiUrl

func NewDoujinshiUrl(url string) (*Doujinshi, error)

NewDoujinshiUrl is a constructor of the doujinshi object

func RandomDoujin added in v0.5.3

func RandomDoujin() (doujin *Doujinshi, err error)

RandomDoujin is a function that generate a random doujinshi

func (*Doujinshi) GetComments added in v0.1.2

func (d *Doujinshi) GetComments() error

GetComments is a function that gets the related comments of doujinshi and assign them to the doujinshi object

func (*Doujinshi) GetRelated added in v0.1.0

func (d *Doujinshi) GetRelated() error

GetRelated is a function that gets the related doujinshi and assign it to the doujinshi object

func (*Doujinshi) GetUrl added in v0.4.0

func (d *Doujinshi) GetUrl() error

GetUrl is a function that gets the url of the doujinshi and assign them to the doujinshi object

func (*Doujinshi) Save added in v0.1.3

func (d *Doujinshi) Save(dirPathTmpl string, perm os.FileMode) error

Save is a function that download all pages of doujinshi in the specified directory. The name of image can be described by template.

func (*Doujinshi) UnmarshalJSON

func (d *Doujinshi) UnmarshalJSON(b []byte) error

UnmarshalJSON is a json parser of doujinshi object

type Filter added in v0.5.0

type Filter struct {
	Id   int
	Name string
	Type TagsType
}

Filter is the data struct that describes a filter

type Page

type Page struct {
	Num int
	// contains filtered or unexported fields
}

Page is a struct that contains all the information of a doujinshi page

func (*Page) GenerateName added in v0.0.3

func (i *Page) GenerateName(name, suffix string) error

GenerateName is a function that generates the image name from the object data and assign it to the field object Name

func (*Page) GetData added in v0.0.3

func (i *Page) GetData() error

GetData is a function that gets the data of image and assign it to the field object Data

func (*Page) GetSize added in v0.0.3

func (i *Page) GetSize() error

GetSize is a function that gets the size of the image and assign it to the object

func (*Page) GetUrl added in v0.0.2

func (pi *Page) GetUrl(mediaId, numPage int) error

GetUrl is a function that get the url of page image and assign it to the Page object

func (*Page) Save added in v0.0.3

func (i *Page) Save(path string, perm os.FileMode) error

Save is a function that save the image on disk.

type QueryFilter added in v0.5.0

type QueryFilter struct {
	ToDelete []Filter
	ToFilter []Filter
}

QueryFilter is a type for the result of a Query

type QueryOptions added in v0.4.0

type QueryOptions struct {
	Page string
	Sort Sort
}

QueryOptions is a type for the option of a query

type QueryResult added in v0.4.0

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

QueryResult is a type for the result of a Query

func RecentDoujinshi added in v0.4.0

func RecentDoujinshi(opts QueryOptions) (qr QueryResult, err error)

RecentDoujinshi is a function that returns the recent doujinshi

func Search(query string, opt QueryOptions) (qr QueryResult, err error)

Search is a function that returns the doujinshi searched

func SearchCustom added in v0.5.0

func SearchCustom(query string, filters QueryFilter) (qr QueryResult, err error)

SearchCustom is a function that search doujinshi with query and filter them by tag.

func SearchTag added in v0.4.0

func SearchTag(tagId int, opt QueryOptions) (qr QueryResult, err error)

SearchTag is a function that returns the doujinshi related to searched tags

type Sort added in v0.4.0

type Sort string

Sort is the data struct that describes sort method

type TagInfo added in v0.5.0

type TagInfo struct {
	Id    int
	Name  string
	Url   string
	Count int
	Type  TagsType
}

TagInfo is a struct that contains all the information related to the tags of a doujinshi

type TagsType added in v0.5.0

type TagsType string

TagsType is the data struct that describes the type of tag

const (
	// Tag is the tag of doujinshi
	Tag TagsType = "tag"

	// Group is the group of doujinshi
	Group TagsType = "group"

	// Artist is the artist of doujinshi
	Artist TagsType = "artist"

	// Language is the language of doujinshi
	Language TagsType = "language"

	// Category is the category of doujinshi
	Category TagsType = "category"

	// Parody is the parody of doujinshi
	Parody TagsType = "parody"

	// Character is the character of doujinshi
	Character TagsType = "character"
)

type Thumbnail added in v0.0.3

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

Thumbnail is a struct that contains all the information of a thumbnail

func (*Thumbnail) GenerateName added in v0.0.3

func (i *Thumbnail) GenerateName(name, suffix string) error

GenerateName is a function that generates the image name from the object data and assign it to the field object Name

func (*Thumbnail) GetData added in v0.0.3

func (i *Thumbnail) GetData() error

GetData is a function that gets the data of image and assign it to the field object Data

func (*Thumbnail) GetSize added in v0.0.3

func (i *Thumbnail) GetSize() error

GetSize is a function that gets the size of the image and assign it to the object

func (*Thumbnail) GetUrl added in v0.0.3

func (t *Thumbnail) GetUrl(mediaId, numPage int) error

GetUrl is a function that get the url of thumbnail image and assign it to the Thumbnail object

func (*Thumbnail) Save added in v0.0.3

func (i *Thumbnail) Save(path string, perm os.FileMode) error

Save is a function that save the image on disk.

type Title

type Title struct {
	English  string
	Japanese string
	Pretty   string
}

Title is the data struct that describes the doujinshi title

type User

type User struct {
	Id           int `validate:"min=0"`
	Username     string
	Url          string
	ProfileImage *Avatar
	IsSuperUser  bool
	IsStaff      bool
	// contains filtered or unexported fields
}

User is a struct that contains all of the user's information

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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