fetcher

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOverrideRedirectHandler = errors.New("couldn't override the existed redirect handler")
	ErrFileNotExist            = errors.New("current file does not exist")
)
View Source
var (
	ErrTalebookNeedSignin = errors.New("need user account to download books")
	ErrEmptyTalebook      = errors.New("couldn't find available books in talebook")
)

Functions

func IsValidFormat

func IsValidFormat(format file.Format) bool

IsValidFormat judge if this format was supported.

func ParseFormat

func ParseFormat(format string) (file.Format, error)

ParseFormat will create the format from the string.

func ParseFormats

func ParseFormats(formats []string) ([]file.Format, error)

ParseFormats will create the format array from the string slice.

Types

type Category

type Category string // The fetcher service identity.
const (
	Talebook Category = "talebook"
	SoBooks  Category = "sobooks"
	Telegram Category = "telegram"
	K12      Category = "k12"
	Hsu      Category = "hsu"
)

type Config

type Config struct {
	Category      Category      // The identity of the fetcher service.
	Formats       []file.Format // The formats that the user wants.
	Keywords      []string      // The keywords that the user wants.
	Extract       bool          // Extract the archives after download.
	DownloadPath  string        // The path for storing the file.
	InitialBookID int64         // The book id start to download.
	Rename        bool          // Rename the file by using book ID.
	Thread        int           // The number of download threads.
	RateLimit     int           // Request per minute for a thread.
	Retry         int           // The retry times for a failed download.
	SkipError     bool          // Continue to download the next book if the current book download failed.

	// The extra configuration for a custom fetcher services.
	Properties map[string]string

	*client.Config
	// contains filtered or unexported fields
}

Config is used to define a common config for a specified fetcher service.

func (*Config) Property

func (c *Config) Property(name string) string

Property will require an existed property from the config.

func (*Config) SetRedirect

func (c *Config) SetRedirect(redirect func(*http.Request, []*http.Request) error) error

type Fetcher

type Fetcher interface {
	// Download the books from the given service.
	Download() error
}

Fetcher exposes the download method to the command line.

func New

func New(c *Config) (Fetcher, error)

New create a fetcher service for downloading books.

type HsuBookMeta added in v0.14.0

type HsuBookMeta struct {
	ID                  int    `json:"id"`
	Name                string `json:"name"`
	OriginalName        string `json:"originalName"`
	LocalizedName       string `json:"localizedName"`
	SortName            string `json:"sortName"`
	Pages               int    `json:"pages"`
	CoverImageLocked    bool   `json:"coverImageLocked"`
	PagesRead           int    `json:"pagesRead"`
	LatestReadDate      string `json:"latestReadDate"`
	LastChapterAdded    string `json:"lastChapterAdded"`
	UserRating          int    `json:"userRating"`
	HasUserRated        bool   `json:"hasUserRated"`
	Format              int    `json:"format"`
	Created             string `json:"created"`
	NameLocked          bool   `json:"nameLocked"`
	SortNameLocked      bool   `json:"sortNameLocked"`
	LocalizedNameLocked bool   `json:"localizedNameLocked"`
	WordCount           int    `json:"wordCount"`
	LibraryID           int    `json:"libraryId"`
	LibraryName         string `json:"libraryName"`
	MinHoursToRead      int    `json:"minHoursToRead"`
	MaxHoursToRead      int    `json:"maxHoursToRead"`
	AvgHoursToRead      int    `json:"avgHoursToRead"`
	FolderPath          string `json:"folderPath"`
	LastFolderScanned   string `json:"lastFolderScanned"`
}

HsuBookMeta is used for representing book information. https://book.hsu.life/api/series/all-v2

type HsuBookMetaReq added in v0.14.0

type HsuBookMetaReq struct {
	Statements []struct {
		Comparison int    `json:"comparison"`
		Value      string `json:"value"`
		Field      int    `json:"field"`
	} `json:"statements"`
	Combination int `json:"combination"`
	LimitTo     int `json:"limitTo"`
	SortOptions struct {
		IsAscending bool `json:"isAscending"`
		SortField   int  `json:"sortField"`
	} `json:"sortOptions"`
}

type HsuLoginReq added in v0.14.0

type HsuLoginReq struct {
	Username string `json:"username"`
	Password string `json:"password"`
	APIKey   string `json:"apiKey"`
}

HsuLoginReq is used in POST https://book.hsu.life/api/account/login

type HsuLoginResp added in v0.14.0

type HsuLoginResp struct {
	Username     string `json:"username"`
	Email        string `json:"email"`
	Token        string `json:"token"`
	RefreshToken string `json:"refreshToken"`
	APIKey       string `json:"apiKey"`
	Preferences  struct {
		ReadingDirection           int    `json:"readingDirection"`
		ScalingOption              int    `json:"scalingOption"`
		PageSplitOption            int    `json:"pageSplitOption"`
		ReaderMode                 int    `json:"readerMode"`
		LayoutMode                 int    `json:"layoutMode"`
		EmulateBook                bool   `json:"emulateBook"`
		BackgroundColor            string `json:"backgroundColor"`
		SwipeToPaginate            bool   `json:"swipeToPaginate"`
		AutoCloseMenu              bool   `json:"autoCloseMenu"`
		ShowScreenHints            bool   `json:"showScreenHints"`
		BookReaderMargin           int    `json:"bookReaderMargin"`
		BookReaderLineSpacing      int    `json:"bookReaderLineSpacing"`
		BookReaderFontSize         int    `json:"bookReaderFontSize"`
		BookReaderFontFamily       string `json:"bookReaderFontFamily"`
		BookReaderTapToPaginate    bool   `json:"bookReaderTapToPaginate"`
		BookReaderReadingDirection int    `json:"bookReaderReadingDirection"`
		BookReaderWritingStyle     int    `json:"bookReaderWritingStyle"`
		Theme                      struct {
			ID              int    `json:"id"`
			Name            string `json:"name"`
			NormalizedName  string `json:"normalizedName"`
			FileName        string `json:"fileName"`
			IsDefault       bool   `json:"isDefault"`
			Provider        int    `json:"provider"`
			Created         string `json:"created"`
			LastModified    string `json:"lastModified"`
			CreatedUtc      string `json:"createdUtc"`
			LastModifiedUtc string `json:"lastModifiedUtc"`
		} `json:"theme"`
		BookReaderThemeName         string `json:"bookReaderThemeName"`
		BookReaderLayoutMode        int    `json:"bookReaderLayoutMode"`
		BookReaderImmersiveMode     bool   `json:"bookReaderImmersiveMode"`
		GlobalPageLayoutMode        int    `json:"globalPageLayoutMode"`
		BlurUnreadSummaries         bool   `json:"blurUnreadSummaries"`
		PromptForDownloadSize       bool   `json:"promptForDownloadSize"`
		NoTransitions               bool   `json:"noTransitions"`
		CollapseSeriesRelationships bool   `json:"collapseSeriesRelationships"`
		ShareReviews                bool   `json:"shareReviews"`
		Locale                      string `json:"locale"`
	} `json:"preferences"`
	AgeRestriction struct {
		AgeRating       int  `json:"ageRating"`
		IncludeUnknowns bool `json:"includeUnknowns"`
	} `json:"ageRestriction"`
	KavitaVersion string `json:"kavitaVersion"`
}

HsuLoginResp is used in https://book.hsu.life/api/account/login response

type MetadataSource added in v0.11.0

type MetadataSource struct {
	URLs string `json:"urls"`
}

type TextBook added in v0.11.0

type TextBook struct {
	ID               string `json:"id"`
	CustomProperties struct {
		AutoFillThumb bool `json:"auto_fill_thumb"`
		ExtProperties struct {
			CatalogType string `json:"catalog_type"`
			LibraryID   string `json:"library_id"`
			SubCatalog  string `json:"sub_catalog"`
		} `json:"ext_properties"`
		Format         string   `json:"format"`
		Height         string   `json:"height"`
		IsTop          int      `json:"is_top"`
		Providers      []string `json:"providers"`
		ResSort        int64    `json:"res_sort"`
		Resolution     string   `json:"resolution"`
		Size           int64    `json:"size"`
		SysTransStatus string   `json:"sys_trans_status"`
		Thumbnails     []string `json:"thumbnails"`
		Width          string   `json:"width"`
	} `json:"custom_properties"`
	ResourceTypeCode string `json:"resource_type_code"`
	Language         string `json:"language"`
	Provider         string `json:"provider"`
	CreateTime       string `json:"create_time"`
	UpdateTime       string `json:"update_time"`
	TagList          []struct {
		TagID          string `json:"tag_id"`
		TagName        string `json:"tag_name"`
		TagDimensionID string `json:"tag_dimension_id"`
		OrderNum       int    `json:"order_num"`
	} `json:"tag_list"`
	Status               string   `json:"status"`
	CreateContainerID    string   `json:"create_container_id"`
	ResourceTypeCodeName string   `json:"resource_type_code_name"`
	OnlineTime           string   `json:"online_time"`
	TagPaths             []string `json:"tag_paths"`
	ContainerID          string   `json:"container_id"`
	TenantID             string   `json:"tenant_id"`
	Title                string   `json:"title"`
	Label                []string `json:"label"`
	Description          string   `json:"description"`
	ProviderList         []struct {
		Name string `json:"name"`
		ID   string `json:"id"`
		Type string `json:"type"`
	} `json:"provider_list"`
}

Jump to

Keyboard shortcuts

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