mangadex

package module
v0.0.0-...-5ec8c2f Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2020 License: MIT Imports: 6 Imported by: 0

README

MangaDex

GoDoc Go Report Card codecov

A Go client for the MangaDex API.

func main() {
  md := mangadex.New()
  m, _, err := md.Manga("23279")
  if err != nil {
    log.Fatal(err)
  }
  fmt.Println(m.Title)
  // Wonder Cat Kyuu-chan
}
func main() {
  md := mangadex.New()
  c, err := md.Chapter("517244")
  if err != nil {
      log.Fatal(err)
  }
  fmt.Printf("%s (Volume %s, Chapter %s)", c, c.Volume, c.Chapter)
  // Cool Day (Volume 3, Chapter 253)
}

Documentation

Overview

Package mangadex is a client for the MangaDex API.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chapter

type Chapter struct {
	ID         MaybeNumber `json:"id,omitempty"`
	Volume     MaybeNumber `json:"volume,omitempty"`
	Chapter    MaybeNumber `json:"chapter,omitempty"`
	Title      string      `json:"title"`
	LangCode   string      `json:"lang_code"`
	MangaID    MaybeNumber `json:"manga_id,omitempty"`
	GroupID    int         `json:"group_id"`
	GroupName  string      `json:"group_name"`
	GroupID2   int         `json:"group_id_2"`
	GroupName2 string      `json:"group_name_2"`
	GroupID3   int         `json:"group_id_3"`
	GroupName3 string      `json:"group_name_3"`
	Timestamp  int64       `json:"timestamp"`

	// The following fields are only filled when the chapter is requested
	// through the Client.Chapter function.
	LangName  string   `json:"lang_name"`
	Hash      string   `json:"hash"`
	Server    string   `json:"server"`
	Pages     []string `json:"page_array"`
	LongStrip bool     `json:"long_strip"`
	Status    string   `json:"status"`
}

Chapter contains information about a chapter. Some fields may be left empty when returned by the Manga function.

Example
package main

import (
	"fmt"
	"log"

	"github.com/bake/mangadex"
)

var md *mangadex.Client

func main() {
	c, err := md.Chapter("517244")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s (Volume %s, Chapter %s)", c, c.Volume, c.Chapter)
}
Output:
Cool Day (Volume 3, Chapter 253)

func (Chapter) Images

func (ch Chapter) Images() []string

Images returns a slice of URLs to the chapters pages.

func (Chapter) String

func (ch Chapter) String() string

type Client

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

Client implements a way to talk to MangaDex' API.

func New

func New(options ...OptionFunc) *Client

New returns a new MangaDex Client.

func (*Client) Chapter

func (c *Client) Chapter(id string) (Chapter, error)

Chapter fetches a mangas chapter.

func (*Client) Manga

func (c *Client) Manga(id string) (Manga, []Chapter, error)

Manga fetches a manga. The returned chapter slice is a sorted representation of the mangas Chapters map.

type Manga

type Manga struct {
	ID          MaybeNumber        `json:"id,omitempty"`
	CoverURL    string             `json:"cover_url"`
	Description string             `json:"description"`
	Title       string             `json:"title"`
	Artist      string             `json:"artist"`
	Author      string             `json:"author"`
	Status      int                `json:"status"`
	Genres      []int              `json:"genres"`
	LastChapter string             `json:"last_chapter"`
	LangName    string             `json:"lang_name"`
	LangFlag    string             `json:"lang_flag"`
	Hentai      int                `json:"hentai"`
	Links       map[string]string  `json:"links"`
	Chapters    map[string]Chapter `json:"chapters"`
}

Manga contains information about a given manga.

Example
package main

import (
	"fmt"
	"log"

	"github.com/bake/mangadex"
)

var md *mangadex.Client

func main() {
	m, _, err := md.Manga("23279")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s by %s", m, m.Author)
}
Output:
Wonder Cat Kyuu-chan by Nitori Sasami

func (Manga) String

func (m Manga) String() string

type MaybeNumber

type MaybeNumber struct{ json.Number }

MaybeNumber unmarshals numbers that may be numeric, numeric strings or empty strings.

func (*MaybeNumber) UnmarshalJSON

func (n *MaybeNumber) UnmarshalJSON(d []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type OptionFunc

type OptionFunc func(*Client)

An OptionFunc can be used to modify the Tapas client.

func WithBase

func WithBase(base string) OptionFunc

WithBase sets the MangaDex base.

func WithHTTPClient

func WithHTTPClient(c *http.Client) OptionFunc

WithHTTPClient makes the manga client use a given http.Client to make requests.

func WithPath

func WithPath(path string) OptionFunc

WithPath replaces the default path. Might be used on a new API version.

Jump to

Keyboard shortcuts

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