mangadex

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2020 License: MIT Imports: 9 Imported by: 1

README

MangaDex

GoDoc Go Report Card codecov

A Go client for the MangaDex API v2.

func main() {
  md := mangadex.New()
  ctx := context.TODO()
  m, err := md.Manga(ctx, 23279, nil)
  if err != nil {
    log.Fatal(err)
  }
  fmt.Printf("%s by %s", m, m.Author[0])
  // Output: Wonder Cat Kyuu-chan by Nitori Sasami
}
func main() {
  md := mangadex.New()
  ctx := context.TODO()
  c, err := md.Chapter(ctx, 517244, nil)
  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)
}

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 {
	PreviewChapter
	Status         string   `json:"status"`
	Pages          []string `json:"pages"`
	Server         string   `json:"server"`
	ServerFallback string   `json:"serverFallback"`
}

Chapter contains a chapter.

Example
ctx := context.TODO()
opts := mangadex.ChapterOptions{
	Saver: true, // Use low quality images.
}
c, err := md.Chapter(ctx, 517244, &opts)
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 (c Chapter) Images() []string

Images returns a slice of URLs to the chapters pages.

type ChapterOptions

type ChapterOptions struct {
	Server   string `url:"server,omitempty"`    // Override location-based server assignment. Possible values: na, na2.
	Saver    bool   `url:"saver,omitempty"`     // Use low quality images (data saver).
	MarkRead bool   `url:"mark_read,omitempty"` // Mark the chapter as read.
}

ChapterOptions contains options that can be passed to the endpoint.

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(ctx context.Context, id int, opts *ChapterOptions) (Chapter, error)

Chapter returns a chapter.

func (*Client) Follows

func (c *Client) Follows(ctx context.Context, opts *FollowsOptions) ([]Follow, error)

Follows returns all follow types.

func (*Client) Group

func (c *Client) Group(ctx context.Context, id int, opts *GroupOptions) (Group, error)

Group returns a group.

func (*Client) GroupChapters

func (c *Client) GroupChapters(ctx context.Context, id int, opts *GroupChaptersOptions) ([]PreviewChapter, error)

GroupChapters returns partial information about the chapters belonging to the group.

func (*Client) Manga

func (c *Client) Manga(ctx context.Context, id int, opts *MangaOptions) (Manga, error)

Manga returns a manga.

func (*Client) MangaChapters

func (c *Client) MangaChapters(ctx context.Context, id int, opts *MangaChaptersOptions) ([]PreviewChapter, error)

MangaChapters returns partial information about the chapters belonging to a manga.

func (*Client) MangaCovers

func (c *Client) MangaCovers(ctx context.Context, id int, opts *MangaCoversOptions) ([]Cover, error)

MangaCovers returns a list of covers belonging to a manga.

func (*Client) Relations

func (c *Client) Relations(ctx context.Context, opts *RelationsOptions) ([]Relation, error)

Relations returns all manga relation types.

func (*Client) Tag

func (c *Client) Tag(ctx context.Context, id int, opts *TagOptions) (Tag, error)

Tag returns a tag.

func (*Client) Tags

func (c *Client) Tags(ctx context.Context, opts *TagsOptions) ([]Tag, error)

Tags all tags.

func (*Client) User

func (c *Client) User(ctx context.Context, id int, opts *UserOptions) (User, error)

User returns a user.

func (*Client) UserChapters

func (c *Client) UserChapters(ctx context.Context, id int, opts *UserChaptersOptions) ([]PreviewChapter, error)

UserChapters partial information about the chapters uploaded by the user.

type Cover

type Cover struct {
	Volume string `json:"volume"`
	URL    string `json:"url"`
}

Cover contains a URL to a volumes cover image.

type Follow

type Follow struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Follow contains information about a follow.

type FollowsOptions

type FollowsOptions struct{}

FollowsOptions contains options that can be passed to the endpoint.

type Group

type Group struct {
	PreviewGroup
	AltNames    string    `json:"altNames"`
	Language    string    `json:"language"`
	Leader      Member    `json:"leader"`
	Members     []Member  `json:"members"`
	Description string    `json:"description"`
	Website     string    `json:"website"`
	Discord     string    `json:"discord"`
	IRCServer   string    `json:"ircServer"`
	IRCChannel  string    `json:"ircChannel"`
	Email       string    `json:"email"`
	Founded     string    `json:"founded"`
	Likes       int       `json:"likes"`
	Follows     int       `json:"follows"`
	Views       int       `json:"views"`
	Chapters    int       `json:"chapters"`
	ThreadID    int       `json:"threadId"`
	ThreadPosts int       `json:"threadPosts"`
	IsLocked    bool      `json:"isLocked"`
	IsInactive  bool      `json:"isInactive"`
	Delay       int       `json:"delay"`
	LastUpdated Timestamp `json:"lastUpdated"`
	Banner      string    `json:"banner"`
}

Group contains information about a given group.

type GroupChaptersOptions

type GroupChaptersOptions struct {
	Page  int `url:"p,omitempty"`
	Limit int `url:"limit,omitempty"`
}

GroupChaptersOptions contains options that can be passed to the endpoint.

type GroupOptions

type GroupOptions struct{}

GroupOptions contains options that can be passed to the endpoint.

type Manga

type Manga struct {
	ID          int      `json:"id"`
	Title       string   `json:"title"`
	AltTitles   []string `json:"altTitles"`
	Description string   `json:"description"`
	Artist      []string `json:"artist"`
	Author      []string `json:"author"`
	Publication struct {
		Language    string `json:"language"`
		Status      int    `json:"status"`
		Demographic int    `json:"demographic"`
	} `json:"publication"`
	Tags        []int             `json:"tags"`
	LastChapter string            `json:"lastChapter"`
	LastVolume  string            `json:"lastVolume"`
	IsHentai    bool              `json:"isHentai"`
	Links       map[string]string `json:"links"`
	Relations   []struct {
		ID       int    `json:"id"`
		Title    string `json:"title"`
		Type     int    `json:"type"`
		IsHentai bool   `json:"isHentai"`
	} `json:"relations"`
	Rating struct {
		Bayesian float64 `json:"bayesian"`
		Mean     float64 `json:"mean"`
		Users    int     `json:"users"`
	} `json:"rating"`
	Views        int       `json:"views"`
	Follows      int       `json:"follows"`
	Comments     int       `json:"comments"`
	LastUploaded Timestamp `json:"lastUploaded"`
	MainCover    string    `json:"mainCover"`
}

Manga contains information about a given manga.

Example
ctx := context.TODO()
m, err := md.Manga(ctx, 23279, nil)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%s by %s", m, m.Author[0])
Output:

Wonder Cat Kyuu-chan by Nitori Sasami

func (Manga) String

func (m Manga) String() string

type MangaChaptersOptions

type MangaChaptersOptions struct {
	Page  int `url:"p,omitempty"`
	Limit int `url:"limit,omitempty"`
}

MangaChaptersOptions contains options that can be passed to the endpoint.

type MangaCoversOptions

type MangaCoversOptions struct{}

MangaCoversOptions contains options that can be passed to the endpoint.

type MangaOptions

type MangaOptions struct{}

MangaOptions contains options that can be passed to the endpoint.

type Member

type Member struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

Member belogs to a group.

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.

type PreviewChapter

type PreviewChapter struct {
	ID         int            `json:"id"`
	Hash       string         `json:"hash"`
	MangaID    int            `json:"mangaId"`
	MangaTitle string         `json:"mangaTitle"`
	Volume     string         `json:"volume"`
	Chapter    string         `json:"chapter"`
	Title      string         `json:"title"`
	Language   string         `json:"language"`
	Groups     []PreviewGroup `json:"groups"`
	Uploader   int            `json:"uploader"`
	Timestamp  Timestamp      `json:"timestamp"`
	Comments   int            `json:"comments"`
	Views      int            `json:"views"`
}

PreviewChapter contains a chapter without images.

func (PreviewChapter) String

func (c PreviewChapter) String() string

type PreviewGroup

type PreviewGroup struct {
	ID   int    `json:"id"`
	Name string `json:"name"`
}

PreviewGroup contains limited information about a group.

func (PreviewGroup) String

func (g PreviewGroup) String() string

func (*PreviewGroup) UnmarshalJSON

func (g *PreviewGroup) UnmarshalJSON(d []byte) error

UnmarshalJSON implements the json.Unmarshaler interface allowing for interpreting []int as []Group while ignoring names. This is necessary since groups in /manga/{id}/chapters only contain IDs.

type Relation

type Relation struct {
	ID     int    `json:"id"`
	Name   string `json:"name"`
	PairID int    `json:"pairId"`
}

Relation contains information about a relation.

type RelationsOptions

type RelationsOptions struct{}

RelationsOptions contains options that can be passed to the endpoint.

type Tag

type Tag struct {
	ID          int    `json:"id"`
	Name        string `json:"name"`
	Group       string `json:"group"`
	Description string `json:"description"`
}

Tag contains information about a tag.

func (Tag) String

func (t Tag) String() string

type TagOptions

type TagOptions struct{}

TagOptions contains options that can be passed to the endpoint.

type TagsOptions

type TagsOptions struct{}

TagsOptions contains options that can be passed to the endpoint.

type Timestamp

type Timestamp struct{ time.Time }

Timestamp contains a time.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(d []byte) error

UnmarshalJSON interprets int64 as a Unix timestamp and unmarshals it into time.Time.

type User

type User struct {
	ID        int       `json:"id"`
	Username  string    `json:"username"`
	LevelID   int       `json:"levelId"`
	Joined    Timestamp `json:"joined"`
	LastSeen  Timestamp `json:"lastSeen"`
	Website   string    `json:"website"`
	Biography string    `json:"biography"`
	Views     int       `json:"views"`
	Uploads   int       `json:"uploads"`
	Premium   bool      `json:"premium"`
	MdAtHome  int       `json:"mdAtHome"`
	Avatar    string    `json:"avatar"`
}

User contains information about a given user.

func (User) String

func (u User) String() string

type UserChaptersOptions

type UserChaptersOptions struct {
	Page  int `url:"p,omitempty"`
	Limit int `url:"limit,omitempty"`
}

UserChaptersOptions contains options that can be passed to the endpoint.

type UserOptions

type UserOptions struct{}

UserOptions contains options that can be passed to the endpoint.

Jump to

Keyboard shortcuts

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