mangodex

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

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

Go to latest
Published: Dec 31, 2021 License: MIT Imports: 11 Imported by: 4

README

mangodex

Go Reference

Golang API wrapper for MangaDex v5's MVP API.

Full API documentation is found here.

This branch contains only essential services, such as Manga searching and image downloading.

Installation

To install, do go get -u github.com/darylhjd/mangodex@essential.

Usage

package main

import (
	"fmt"
	
	m "github.com/darylhjd/mangodex@simple"
)

func main() {
	// Create new client.
	// Without logging in, you may not be able to access 
	// all API functionality.
	c := m.NewDexClient()

	// Login using your username and password.
	err := c.Auth.Login("user", "password")
	if err != nil {
		fmt.Println("Could not login!")
	}
}

Contributing

Any contributions are welcome.

Documentation

Index

Constants

View Source
const (
	GetMDHomeURLPath = "at-home/server/%s"
	MDHomeReportURL  = "https://api.mangadex.network/report"
)
View Source
const (
	LoginPath        = "auth/login"
	LogoutPath       = "auth/logout"
	RefreshTokenPath = "auth/refresh"
)
View Source
const (
	MangaChaptersPath    = "manga/%s/feed"
	MangaReadMarkersPath = "manga/%s/read"
)
View Source
const (
	MangaListPath            = "manga"
	CheckIfMangaFollowedPath = "user/follows/manga/%s"
	ToggleMangaFollowPath    = "manga/%s/follow"
)
View Source
const (
	ShonenDemographic string = "shounen"
	ShoujoDemographic string = "shoujo"
	JoseiDemographic  string = "josei"
	SeinenDemograpic  string = "seinen"
)

Publication demographic

View Source
const (
	OngoingStatus   string = "ongoing"
	CompletedStatus string = "completed"
	HiatusStatus    string = "hiatus"
	CancelledStatus string = "cancelled"
)

Manga publication status

View Source
const (
	Reading    string = "reading"
	OnHold     string = "on_hold"
	PlanToRead string = "plan_to_read"
	Dropped    string = "dropped"
	ReReading  string = "re_reading"
	Completed  string = "completed"
)

Manga reading status

View Source
const (
	Safe       string = "safe"
	Suggestive string = "suggestive"
	Erotica    string = "erotica"
	Porn       string = "pornographic"
)

Manga content rating

View Source
const (
	MangaRel           string = "manga"
	ChapterRel         string = "chapter"
	CoverArtRel        string = "cover_art"
	AuthorRel          string = "author"
	ArtistRel          string = "artist"
	ScanlationGroupRel string = "scanlation_group"
	TagRel             string = "tag"
	UserRel            string = "user"
	CustomListRel      string = "custom_list"
)

Relationship types. Useful for reference expansions

View Source
const (
	GetUserFollowedMangaListPath = "user/follows/manga"
	GetLoggedUserPath            = "user/me"
)
View Source
const (
	BaseAPI = "https://api.mangadex.org"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AtHomeService

type AtHomeService service

AtHomeService : Provides MangaDex@Home services provided by the API.

func (*AtHomeService) NewMDHomeClient

func (s *AtHomeService) NewMDHomeClient(chapterID string, quality string, forcePort443 bool) (*MDHomeClient, error)

NewMDHomeClient : Get MangaDex@Home client for a chapter. https://api.mangadex.org/docs.html#operation/get-at-home-server-chapterId

func (*AtHomeService) NewMDHomeClientContext

func (s *AtHomeService) NewMDHomeClientContext(ctx context.Context, chapterID string, quality string, forcePort443 bool) (*MDHomeClient, error)

NewMDHomeClientContext : NewMDHomeClient with custom context.

type AuthResponse

type AuthResponse struct {
	Result  string  `json:"result"`
	Token   token   `json:"token"`
	Message *string `json:"message,omitempty"`
}

AuthResponse : Typical AuthService response.

func (AuthResponse) GetResult

func (ar AuthResponse) GetResult() string

type AuthService

type AuthService service

AuthService : Provides Auth services provided by the API.

func (*AuthService) GetRefreshToken

func (s *AuthService) GetRefreshToken() string

GetRefreshToken : Get the current refresh token of the client.

func (*AuthService) IsLoggedIn

func (s *AuthService) IsLoggedIn() bool

IsLoggedIn : Return true when client logged in and false otherwise.

func (*AuthService) Login

func (s *AuthService) Login(user, pwd string) error

Login : Login to MangaDex. https://api.mangadex.org/docs.html#operation/post-auth-login

func (*AuthService) LoginContext

func (s *AuthService) LoginContext(ctx context.Context, user, pwd string) error

LoginContext : Login with custom context.

func (*AuthService) Logout

func (s *AuthService) Logout() error

Logout : Logout of MangaDex and invalidates all tokens. https://api.mangadex.org/docs.html#operation/post-auth-logout

func (*AuthService) LogoutContext

func (s *AuthService) LogoutContext(ctx context.Context) error

LogoutContext : Logout with custom context.

func (*AuthService) RefreshSessionToken

func (s *AuthService) RefreshSessionToken() error

RefreshSessionToken : Refresh session token using refresh token. https://api.mangadex.org/docs.html#operation/post-auth-refresh

func (*AuthService) RefreshSessionTokenContext

func (s *AuthService) RefreshSessionTokenContext(ctx context.Context) error

RefreshSessionTokenContext : refreshToken with custom context.

func (*AuthService) SetRefreshToken

func (s *AuthService) SetRefreshToken(refreshToken string)

SetRefreshToken : Set the refresh token for the client.

type AuthorAttributes

type AuthorAttributes struct {
	Name      string           `json:"name"`
	ImageURL  string           `json:"imageUrl"`
	Biography LocalisedStrings `json:"biography"`
	Version   int              `json:"version"`
	CreatedAt string           `json:"createdAt"`
	UpdatedAt string           `json:"updatedAt"`
}

AuthorAttributes : Attributes for an Author.

type Chapter

type Chapter struct {
	ID            string            `json:"id"`
	Type          string            `json:"type"`
	Attributes    ChapterAttributes `json:"attributes"`
	Relationships []Relationship    `json:"relationships"`
}

Chapter : Struct containing information on a manga.

func (*Chapter) GetChapterNum

func (c *Chapter) GetChapterNum() string

GetChapterNum : Get the chapter's chapter number.

func (*Chapter) GetTitle

func (c *Chapter) GetTitle() string

GetTitle : Get a title for the chapter.

type ChapterAttributes

type ChapterAttributes struct {
	Title              string  `json:"title"`
	Volume             *string `json:"volume"`
	Chapter            *string `json:"chapter"`
	TranslatedLanguage string  `json:"translatedLanguage"`
	Uploader           string  `json:"uploader"`
	ExternalURL        *string `json:"externalUrl"`
	Version            int     `json:"version"`
	CreatedAt          string  `json:"createdAt"`
	UpdatedAt          string  `json:"updatedAt"`
	PublishAt          string  `json:"publishAt"`
}

ChapterAttributes : Attributes for a Chapter.

type ChapterList

type ChapterList struct {
	Result   string    `json:"result"`
	Response string    `json:"response"`
	Data     []Chapter `json:"data"`
	Limit    int       `json:"limit"`
	Offset   int       `json:"offset"`
	Total    int       `json:"total"`
}

ChapterList : A response for getting a list of chapters.

func (*ChapterList) GetResult

func (cl *ChapterList) GetResult() string

type ChapterReadMarkers

type ChapterReadMarkers struct {
	Result string   `json:"result"`
	Data   []string `json:"data"`
}

ChapterReadMarkers : A response for getting a list of read chapters.

func (*ChapterReadMarkers) GetResult

func (rmr *ChapterReadMarkers) GetResult() string

type ChapterService

type ChapterService service

ChapterService : Provides Chapter services provided by the API.

func (*ChapterService) GetMangaChapters

func (s *ChapterService) GetMangaChapters(id string, params url.Values) (*ChapterList, error)

GetMangaChapters : Get a list of chapters for a manga. https://api.mangadex.org/docs.html#operation/get-manga-id-feed

func (*ChapterService) GetMangaChaptersContext

func (s *ChapterService) GetMangaChaptersContext(ctx context.Context, id string, params url.Values) (*ChapterList, error)

GetMangaChaptersContext : GetMangaChapters with custom context.

func (*ChapterService) GetReadMangaChapters

func (s *ChapterService) GetReadMangaChapters(id string) (*ChapterReadMarkers, error)

GetReadMangaChapters : Get list of Chapter IDs that are marked as read for a specified manga ID. https://api.mangadex.org/docs.html#operation/get-manga-chapter-readmarkers

func (*ChapterService) GetReadMangaChaptersContext

func (s *ChapterService) GetReadMangaChaptersContext(ctx context.Context, id string) (*ChapterReadMarkers, error)

GetReadMangaChaptersContext : GetReadMangaChapters with custom context.

func (*ChapterService) SetReadUnreadMangaChapters

func (s *ChapterService) SetReadUnreadMangaChapters(id string, read, unRead []string) (*Response, error)

SetReadUnreadMangaChapters : Set read/unread manga chapters.

func (*ChapterService) SetReadUnreadMangaChaptersContext

func (s *ChapterService) SetReadUnreadMangaChaptersContext(ctx context.Context, id string, read, unRead []string) (*Response, error)

SetReadUnreadMangaChaptersContext : SetReadUnreadMangaChapters with custom context.

type ChaptersData

type ChaptersData struct {
	Hash      string   `json:"hash"`
	Data      []string `json:"data"`
	DataSaver []string `json:"dataSaver"`
}

ChaptersData : Struct containing data for the chapter's pages.

type DexClient

type DexClient struct {

	// Services for MangaDex API
	Auth    *AuthService
	Manga   *MangaService
	Chapter *ChapterService
	User    *UserService
	AtHome  *AtHomeService
	// contains filtered or unexported fields
}

DexClient : The MangaDex client.

func NewDexClient

func NewDexClient() *DexClient

NewDexClient : New anonymous client. To login as an authenticated user, use DexClient.Login.

func (*DexClient) Request

func (c *DexClient) Request(ctx context.Context, method, url string, body io.Reader) (*http.Response, error)

Request : Sends a request to the MangaDex API.

func (*DexClient) RequestAndDecode

func (c *DexClient) RequestAndDecode(ctx context.Context, method, url string, body io.Reader, rt ResponseType) error

RequestAndDecode : Convenience wrapper to also decode response to required data type

type Error

type Error struct {
	ID     string `json:"id"`
	Status int    `json:"status"`
	Title  string `json:"title"`
	Detail string `json:"detail"`
}

Error : Struct containing details of an error.

type ErrorResponse

type ErrorResponse struct {
	Result string  `json:"result"`
	Errors []Error `json:"errors"`
}

ErrorResponse : Typical response for errored requests.

func (*ErrorResponse) GetErrors

func (er *ErrorResponse) GetErrors() string

GetErrors : Get the errors for this particular request.

func (*ErrorResponse) GetResult

func (er *ErrorResponse) GetResult() string

type LocalisedStrings

type LocalisedStrings struct {
	Values map[string]string
}

LocalisedStrings : A struct wrapping around a map containing each localised string.

func (*LocalisedStrings) GetLocalString

func (l *LocalisedStrings) GetLocalString(langCode string) string

GetLocalString : Get the localised string for a particular language code. If the required string is not found, it will return the first entry, or an empty string otherwise.

func (*LocalisedStrings) UnmarshalJSON

func (l *LocalisedStrings) UnmarshalJSON(data []byte) error

type MDHomeClient

type MDHomeClient struct {
	Pages []string
	// contains filtered or unexported fields
}

MDHomeClient : Client for interfacing with MangaDex@Home.

func (*MDHomeClient) GetChapterPage

func (c *MDHomeClient) GetChapterPage(filename string) ([]byte, error)

GetChapterPage : Return page data for a chapter with the filename of that page.

func (*MDHomeClient) GetChapterPageWithContext

func (c *MDHomeClient) GetChapterPageWithContext(ctx context.Context, filename string) ([]byte, error)

GetChapterPageWithContext : GetChapterPage with custom context.

type MDHomeServerResponse

type MDHomeServerResponse struct {
	Result  string       `json:"result"`
	BaseURL string       `json:"baseUrl"`
	Chapter ChaptersData `json:"chapter"`
}

MDHomeServerResponse : A response for getting a server URL to get chapters.

func (*MDHomeServerResponse) GetResult

func (r *MDHomeServerResponse) GetResult() string

type Manga

type Manga struct {
	ID            string          `json:"id"`
	Type          string          `json:"type"`
	Attributes    MangaAttributes `json:"attributes"`
	Relationships []Relationship  `json:"relationships"`
}

Manga : Struct containing information on a Manga.

func (*Manga) GetDescription

func (m *Manga) GetDescription(langCode string) string

GetDescription : Get description of the Manga.

func (*Manga) GetTitle

func (m *Manga) GetTitle(langCode string) string

GetTitle : Get title of the Manga.

type MangaAttributes

type MangaAttributes struct {
	Title                  LocalisedStrings `json:"title"`
	AltTitles              LocalisedStrings `json:"altTitles"`
	Description            LocalisedStrings `json:"description"`
	IsLocked               bool             `json:"isLocked"`
	Links                  LocalisedStrings `json:"links"`
	OriginalLanguage       string           `json:"originalLanguage"`
	LastVolume             *string          `json:"lastVolume"`
	LastChapter            *string          `json:"lastChapter"`
	PublicationDemographic *string          `json:"publicationDemographic"`
	Status                 *string          `json:"status"`
	Year                   *int             `json:"year"`
	ContentRating          *string          `json:"contentRating"`
	Tags                   []Tag            `json:"tags"`
	State                  string           `json:"state"`
	Version                int              `json:"version"`
	CreatedAt              string           `json:"createdAt"`
	UpdatedAt              string           `json:"updatedAt"`
}

MangaAttributes : Attributes for a Manga.

type MangaList

type MangaList struct {
	Result   string  `json:"result"`
	Response string  `json:"response"`
	Data     []Manga `json:"data"`
	Limit    int     `json:"limit"`
	Offset   int     `json:"offset"`
	Total    int     `json:"total"`
}

MangaList : A response for getting a list of manga.

func (*MangaList) GetResult

func (ml *MangaList) GetResult() string

type MangaService

type MangaService service

MangaService : Provides Manga services provided by the API.

func (*MangaService) CheckIfMangaFollowed

func (s *MangaService) CheckIfMangaFollowed(id string) (bool, error)

CheckIfMangaFollowed : Check if a user follows a manga.

func (*MangaService) CheckIfMangaFollowedContext

func (s *MangaService) CheckIfMangaFollowedContext(ctx context.Context, id string) (bool, error)

CheckIfMangaFollowedContext : CheckIfMangaFollowed with custom context.

func (*MangaService) GetMangaList

func (s *MangaService) GetMangaList(params url.Values) (*MangaList, error)

GetMangaList : Get a list of Manga. https://api.mangadex.org/docs.html#operation/get-search-manga

func (*MangaService) GetMangaListContext

func (s *MangaService) GetMangaListContext(ctx context.Context, params url.Values) (*MangaList, error)

GetMangaListContext : GetMangaList with custom context.

func (*MangaService) ToggleMangaFollowStatus

func (s *MangaService) ToggleMangaFollowStatus(id string, toFollow bool) (*Response, error)

ToggleMangaFollowStatus :Toggle follow status for a manga.

func (*MangaService) ToggleMangaFollowStatusContext

func (s *MangaService) ToggleMangaFollowStatusContext(ctx context.Context, id string, toFollow bool) (*Response, error)

ToggleMangaFollowStatusContext ToggleMangaFollowStatus with custom context.

type Relationship

type Relationship struct {
	ID         string      `json:"id"`
	Type       string      `json:"type"`
	Attributes interface{} `json:"attributes"`
}

Relationship : Struct containing relationships, with optional attributes for the relation.

func (*Relationship) UnmarshalJSON

func (a *Relationship) UnmarshalJSON(data []byte) error

type Response

type Response struct {
	Result string `json:"result"`
}

Response : Plain response struct containing only Result field.

func (*Response) GetResult

func (r *Response) GetResult() string

type ResponseType

type ResponseType interface {
	GetResult() string
}

ResponseType : Interface for API responses.

type ScanlationGroupAttributes

type ScanlationGroupAttributes struct {
	Name            string           `json:"name"`
	AltNames        LocalisedStrings `json:"altNames"`
	Website         *string          `json:"website"`
	IRCServer       *string          `json:"ircServer"`
	Discord         *string          `json:"discord"`
	ContactEmail    *string          `json:"contactEmail"`
	Description     *string          `json:"description"`
	Twitter         *string          `json:"twitter"`
	FocusedLanguage []string         `json:"focusedLanguage"`
	Locked          bool             `json:"locked"`
	Official        bool             `json:"official"`
	Inactive        bool             `json:"inactive"`
	PublishDelay    string           `json:"publishDelay"`
	Version         int              `json:"version"`
	CreatedAt       string           `json:"createdAt"`
	UpdatedAt       string           `json:"updatedAt"`
}

ScanlationGroupAttributes : Attributes for a scanlation group

type Tag

type Tag struct {
	ID            string         `json:"id"`
	Type          string         `json:"type"`
	Attributes    TagAttributes  `json:"attributes"`
	Relationships []Relationship `json:"relationships"`
}

Tag : Struct containing information on a tag.

func (*Tag) GetName

func (t *Tag) GetName(langCode string) string

GetName : Get name of the tag.

type TagAttributes

type TagAttributes struct {
	Name        LocalisedStrings `json:"name"`
	Description LocalisedStrings `json:"description"`
	Group       string           `json:"group"`
	Version     int              `json:"version"`
}

TagAttributes : Attributes for a Tag.

type User

type User struct {
	ID            string         `json:"id"`
	Type          string         `json:"type"`
	Attributes    UserAttributes `json:"attributes"`
	Relationships []Relationship `json:"relationships"`
}

User : Info on a MangaDex user.

type UserAttributes

type UserAttributes struct {
	Username string   `json:"username"`
	Roles    []string `json:"roles"`
	Version  int      `json:"version"`
}

UserAttributes : Attributes of a User.

type UserResponse

type UserResponse struct {
	Result   string `json:"result"`
	Response string `json:"response"`
	Data     User   `json:"data"`
}

UserResponse : Typical User response.

func (*UserResponse) GetResult

func (ur *UserResponse) GetResult() string

type UserService

type UserService service

UserService : Provides User services provided by the API.

func (*UserService) GetLoggedUser

func (s *UserService) GetLoggedUser() (*UserResponse, error)

GetLoggedUser : Return logged UserResponse. https://api.mangadex.org/docs.html#operation/get-user-follows-group

func (*UserService) GetLoggedUserContext

func (s *UserService) GetLoggedUserContext(ctx context.Context) (*UserResponse, error)

GetLoggedUserContext : GetLoggedUser with custom context.

func (*UserService) GetUserFollowedMangaList

func (s *UserService) GetUserFollowedMangaList(limit, offset int, includes []string) (*MangaList, error)

GetUserFollowedMangaList : Return list of followed Manga. https://api.mangadex.org/docs.html#operation/get-user-follows-manga

func (*UserService) GetUserFollowedMangaListContext

func (s *UserService) GetUserFollowedMangaListContext(ctx context.Context, limit, offset int, includes []string) (*MangaList, error)

GetUserFollowedMangaListContext : GetUserFollowedMangaListPath with custom context.

Jump to

Keyboard shortcuts

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