book

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Stores = Bookstores{

		SortBy: "name",
		// contains filtered or unexported fields
	}
)

Functions

func AddBook

func AddBook(b *Book, basePath string, minPageNum int) error

AddBook 添加一本书

func AddBooks

func AddBooks(list []*Book, basePath string, minPageNum int) (err error)

AddBooks 添加一组书

func ClearTempFilesALL

func ClearTempFilesALL(debug bool, cacheFilePath string)

ClearTempFilesALL web加载时保存的临时图片,在在退出后清理

func DeleteBookByID

func DeleteBookByID(bookID string)

DeleteBookByID 删除一本书

func GetBooksNumber

func GetBooksNumber() int

GetBooksNumber 获取书籍总数,当然不包括BookGroup

Types

type AllPageInfo

type AllPageInfo struct {
	Images []ImageInfo `json:"images"`
	SortBy string      `json:"sort_by"`
}

func (AllPageInfo) Len

func (s AllPageInfo) Len() int

func (AllPageInfo) Less

func (s AllPageInfo) Less(i, j int) (less bool)

Less 按时间或URL,将图片排序

func (AllPageInfo) Swap

func (s AllPageInfo) Swap(i, j int)

type Book

type Book struct {
	//Name            string           `json:"name"`               //书名
	//BookID          string           `json:"id"`                 //根据FilePath+BookType+修改时间+filesize等等计算,bookID应该唯一
	//FilePath        string           `json:"-" storm:"filepath"` //文件路径
	//BookStorePath   string           `json:"-"   `               //在哪个子书库
	//Type            SupportFileType  `json:"book_type"`          //可以是书籍组(book_group)、文件夹(dir)、文件后缀( .zip .rar .pdf .mp4)等
	//ChildBookNum    int              `json:"child_book_num"`     //子书籍的数量
	//Depth           int              `json:"depth"`              //文件深度
	//ParentFolder    string           `json:"parent_folder"`      //所在父文件夹
	//AllPageNum      int              `json:"all_page_num"`       //storm:"index" 索引字段
	//FileSize        int64            `json:"file_size"`          //storm:"index" 索引字段
	//Author          string           `json:"author"`             //作者
	//Modified        time.Time        `json:"modified_time"`      //最后修改时间
	//ReadPercent     float64          `json:"read_percent"`       //阅读进度
	//ISBN            string           `json:"-"`                  //json不解析,启用可改为`json:"isbn"`
	//Press           string           `json:"-"`                  //json不解析,启用可改为`json:"press"`        //出版社
	//PublishedAt     string           `json:"-"`                  //json不解析,启用可改为`json:"published_at"` //出版日期
	//ExtractPath     string           `json:"-"`                  //json不解析
	//ExtractNum      int              `json:"-"`                  //json不解析,启用可改为`json:"extract_num"`
	//InitComplete    bool             `json:"-"`                  //json不解析,启用可改为`json:"extract_complete"`
	//NonUTF8Zip      bool             `json:"-"`                  //json不解析,启用可改为`json:"non_utf8_zip"`
	//ZipTextEncoding string           `json:"-"`                  //json不解析,启用可改为`json:"zip_text_encoding"`
	//Cover           ImageInfo        `json:"cover"`              //storm:"inline" 内联字段,结构体嵌套时使用
	BookInfo
	Pages     AllPageInfo      `json:"pages"`       //storm:"inline" 内联字段,结构体嵌套时使用
	ChildBook map[string]*Book `json:"child_book" ` //key:BookID
}

Book 定义书籍,BooID不应该重复,根据文件路径生成

func GetAllBookList

func GetAllBookList() []*Book

func GetBookByAuthor

func GetBookByAuthor(author string, sortBy string) ([]*Book, error)

GetBookByAuthor 获取同一作者的书籍。

func GetBookByID

func GetBookByID(id string, sortBy string) (*Book, error)

GetBookByID 获取特定书籍,复制一份数据

func GetRandomBook

func GetRandomBook() *Book

GetRandomBook 随机选取一本书

func New

func New(filePath string, modified time.Time, fileSize int64, storePath string, depth int, bookType SupportFileType) (*Book, error)

New 初始化Book,设置文件路径、书名、BookID等等

func (*Book) GetAllPageNum

func (b *Book) GetAllPageNum() int

func (*Book) GetAuthor

func (b *Book) GetAuthor() string

GetAuthor 获取作者信息

func (*Book) GetBookID

func (b *Book) GetBookID() string

GetBookID 根据路径的MD5,生成书籍ID

func (*Book) GetFilePath

func (b *Book) GetFilePath() string

func (*Book) GetName

func (b *Book) GetName() string

func (*Book) ScanAllImage

func (b *Book) ScanAllImage()

ScanAllImage 服务器端分析分辨率、漫画单双页,只适合已解压文件

func (*Book) ScanAllImageGo

func (b *Book) ScanAllImageGo()

ScanAllImageGo 并发分析

func (*Book) SortPages

func (b *Book) SortPages(s string)

SortPages 上面三个函数定义好了,终于可以使用sort包排序了

func (*Book) SortPagesByImageList added in v0.9.0

func (b *Book) SortPagesByImageList(imageList []string)

SortPagesByImageList 根据一个既定的文件列表,重新对页面排序。用于epub文件。

type BookInfo

type BookInfo struct {
	Name            string          `json:"name"`           //书名
	BookID          string          `json:"id"`             //根据FilePath生成的唯一ID
	BookStorePath   string          `json:"-"   `           //在哪个子书库
	Type            SupportFileType `json:"book_type"`      //书籍类型
	Depth           int             `json:"depth"`          //书籍深度
	ChildBookNum    int             `json:"child_book_num"` //子书籍数量
	AllPageNum      int             `json:"all_page_num"`   //总页数
	Cover           ImageInfo       `json:"cover"`          //封面图
	ParentFolder    string          `json:"parent_folder"`  //父文件夹
	Author          string          `json:"author"`         //作者
	ISBN            string          `json:"isbn"`           //ISBN
	Press           string          `json:"press"`          //出版社
	PublishedAt     string          `json:"published_at"`   //出版日期
	FilePath        string          `json:"-"`              //文件绝对路径,json不解析
	FileSize        int64           `json:"file_size"`      //文件大小
	Modified        time.Time       `json:"modified_time"`  //修改时间
	ExtractPath     string          `json:"-"`              //解压路径,7z用,json不解析
	ExtractNum      int             `json:"-"`              //文件解压数    extract_num
	InitComplete    bool            `json:"-"`              //是否解压完成  extract_complete
	ReadPercent     float64         `json:"read_percent"`   //阅读进度
	NonUTF8Zip      bool            `json:"-"`              //是否为特殊编码zip
	ZipTextEncoding string          `json:"-"`              //zip文件编码
}

BookInfo 与Book唯一的区别是没有AllPageInfo,而是封面图URL 减小 json文件的大小

func NewBookInfo

func NewBookInfo(b *Book) *BookInfo

NewBookInfo BookInfo的模拟构造函数

type BookInfoList

type BookInfoList struct {
	BookInfos []BookInfo
	// contains filtered or unexported fields
}

BookInfoList Slice

func GetAllBookInfoList

func GetAllBookInfoList(sortBy string) (*BookInfoList, error)

func GetBookInfoListByBookGroupBookID

func GetBookInfoListByBookGroupBookID(BookID string, sortBy string) (*BookInfoList, error)

func GetBookInfoListByDepth

func GetBookInfoListByDepth(depth int, sortBy string) (*BookInfoList, error)

func GetBookInfoListByMaxDepth

func GetBookInfoListByMaxDepth(depth int, sortBy string) (*BookInfoList, error)

func (BookInfoList) Len

func (s BookInfoList) Len() int

func (BookInfoList) Less

func (s BookInfoList) Less(i, j int) (less bool)

Less 按时间或URL,将图片排序

func (*BookInfoList) SortBooks

func (s *BookInfoList) SortBooks(by string)

SortBooks 上面三个函数定义好了,终于可以使用sort包排序了

func (BookInfoList) Swap

func (s BookInfoList) Swap(i, j int)

type Bookstores

type Bookstores struct {
	SortBy string
	// contains filtered or unexported fields
}

Bookstores 本地总书库,扫描后生成。可以有多个子书库。

func (*Bookstores) AddBookToStores

func (bs *Bookstores) AddBookToStores(searchPath string, b *Book) error

AddBookToStores 将某一本书,放到basePath做key的某子书库中

func (*Bookstores) GenerateBookGroup

func (bs *Bookstores) GenerateBookGroup() error

GenerateBookGroup 生成书籍组

func (*Bookstores) NewSingleBookstore

func (bs *Bookstores) NewSingleBookstore(basePath string) error

NewSingleBookstore 创建一个新书库

type ImageInfo

type ImageInfo struct {
	PageNum           int       `json:"-"`        //这个字段不解析
	NameInArchive     string    `json:"filename"` //用于解压的压缩文件内文件路径,或图片名,为了适应特殊字符,经过一次转义
	Url               string    `json:"url"`      //远程用户读取图片的URL,为了适应特殊字符,经过一次转义
	Blurhash          string    `json:"-"`        //`json:"blurhash"` //blurhash占位符。需要扫描图片生成(tools.GetImageDataBlurHash)
	Height            int       `json:"-"`        //暂时用不着 这个字段不解析`json:"height"`   //blurhash用,图片高
	Width             int       `json:"-"`        //暂时用不着 这个字段不解析`json:"width"`    //blurhash用,图片宽
	ModeTime          time.Time `json:"-"`        //这个字段不解析
	FileSize          int64     `json:"-"`        //这个字段不解析
	RealImageFilePATH string    `json:"-"`        //这个字段不解析  书籍为文件夹的时候,实际图片的路径
	ImgType           string    `json:"-"`        //这个字段不解析
}

ImageInfo 单张书页

func NewImageInfo

func NewImageInfo(pageNum int, nameInArchive string, url string, fileSize int64) *ImageInfo

type SupportFileType

type SupportFileType string
const (
	TypeDir         SupportFileType = "dir"
	TypeZip         SupportFileType = ".zip"
	TypeRar         SupportFileType = ".rar"
	TypeBooksGroup  SupportFileType = "book_group"
	TypeCbz         SupportFileType = ".cbz"
	TypeCbr         SupportFileType = ".cbr"
	TypeTar         SupportFileType = ".tar"
	TypeEpub        SupportFileType = ".epub"
	TypePDF         SupportFileType = ".pdf"
	TypeVideo       SupportFileType = "video"
	TypeAudio       SupportFileType = "audio"
	TypeUnknownFile SupportFileType = "unknown"
)

书籍类型

func GetBookTypeByFilename

func GetBookTypeByFilename(filename string) SupportFileType

GetBookTypeByFilename 初始化Book时,取得BookType

Jump to

Keyboard shortcuts

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