utils

package
v0.0.0-...-55e8476 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const MAXLENGTH = 80

MAXLENGTH Maximum length of file name

View Source
const TimeFormat = "2006-01-02 15:04:05"

TimeFormat format

Variables

View Source
var (
	ConsoleColors = consoleColors{
		NormalBlack:   "\033[38;5;0m  \033[0m",
		NormalRed:     "\033[38;5;1m  \033[0m",
		NormalGreen:   "\033[38;5;2m  \033[0m",
		NormalYellow:  "\033[38;5;3m  \033[0m",
		NormalBlue:    "\033[38;5;4m  \033[0m",
		NormalMagenta: "\033[38;5;5m  \033[0m",
		NormalCyan:    "\033[38;5;6m  \033[0m",
		NormalWhite:   "\033[38;5;7m  \033[0m",
		BrightBlack:   "\033[48;5;0m  \033[0m",
		BrightRed:     "\033[48;5;1m  \033[0m",
		BrightGreen:   "\033[48;5;2m  \033[0m",
		BrightYellow:  "\033[48;5;3m  \033[0m",
		BrightBlue:    "\033[48;5;4m  \033[0m",
		BrightMagenta: "\033[48;5;5m  \033[0m",
		BrightCyan:    "\033[48;5;6m  \033[0m",
		BrightWhite:   "\033[48;5;7m  \033[0m"}
	QRCodeRecoveryLevels = qrcodeRecoveryLevels{
		Low:     qrcodeRecoveryLevel(qrcode.Low),
		Medium:  qrcodeRecoveryLevel(qrcode.Medium),
		High:    qrcodeRecoveryLevel(qrcode.High),
		Highest: qrcodeRecoveryLevel(qrcode.Highest)}
)
View Source
var FfmpegDir = ""
View Source
var WkToPdfDir = ""

Functions

func AES128Decrypt

func AES128Decrypt(crypted, key, iv []byte) ([]byte, error)

AES128Decrypt AES-128 decrypt

func AES128Encrypt

func AES128Encrypt(origData, key, iv []byte) ([]byte, error)

AES128Encrypt AES-128 encrypt

func AllInOneHtml

func AllInOneHtml(svgContents []*SvgContent, toc []EbookToc) (result string, err error)

AllInOneHtml generate ebook content all in one html file

func BytesToString

func BytesToString(b []byte) string

func CheckFileExist

func CheckFileExist(filename string) bool

func ColumnPrintToPDF

func ColumnPrintToPDF(aid string, filename string, cookies map[string]string) error

ColumnPrintToPDF print pdf

func Contains

func Contains(s []int, n int) bool

Contains int in array

func CurrentDir

func CurrentDir(joinPath ...string) (string, error)

CurrentDir CurrentDir

func DrawProgressBar

func DrawProgressBar(prefix string, proportion float32, width int, suffix ...string)

DrawProgressBar Draw ProgressBar

func FileName

func FileName(name, ext string) string

FileName filter invalid string

func FilePath

func FilePath(name, ext string, escape bool) (string, error)

FilePath gen valid file path

func FileSize

func FileSize(filePath string) (int, bool, error)

FileSize return the file size of the specified path file

func GenHeadHtml

func GenHeadHtml() (result string)

func GenLineContentByElement

func GenLineContentByElement(chapterID string, element *svgparser.Element) (lineContent map[float64][]HtmlEle)

func GenTocHtml

func GenTocHtml(toc []EbookToc) (result string)

GenTocHtml generate toc html anchor

func GenTocLevelHtml

func GenTocLevelHtml(level int, startTag bool) (result string)

func LimitLength

func LimitLength(s string, length int) string

LimitLength cut string

func M3u8URLs

func M3u8URLs(uri string) (urls []string, err error)

M3u8URLs get all ts urls from m3u8 url

func MD5str

func MD5str(s string) string

func Md2Pdf

func Md2Pdf(path, title string, md []byte) (err error)

func MergeAudio

func MergeAudio(paths []string, mergedFilePath string) error

MergeAudio merge audio

func MergeAudioAndVideo

func MergeAudioAndVideo(paths []string, mergedFilePath string) error

MergeAudioAndVideo merge audio and video

func MergeToMP4

func MergeToMP4(paths []string, mergedFilePath string, filename string) error

MergeToMP4 merges video parts to an MP4 file.

func Mkdir

func Mkdir(elem ...string) (string, error)

Mkdir mkdir path

func NewQrCodeTerminal

func NewQrCodeTerminal() *qrcodeTerminal

func NewQrCodeTerminal2

func NewQrCodeTerminal2(front, back consoleColor, level qrcodeRecoveryLevel) *qrcodeTerminal

func OneByOneHtml

func OneByOneHtml(eType string, index int, svgContent *SvgContent, toc []EbookToc) (result, cover string, err error)

OneByOneHtml one by one generate chapter html eType: html/pdf/epub, index: []*SvgContent index, svgContent: one chapter content

func ParseBookFnDelimiter

func ParseBookFnDelimiter(svgContents []*SvgContent) (fnA, fnB string)

func ResolveURL

func ResolveURL(u *url.URL, p string) string

ResolveURL parse url

func SaveFile

func SaveFile(outputDir, title, ext, content string) (err error)

func StringToBytes

func StringToBytes(s string) []byte

func Svg2Epub

func Svg2Epub(outputDir, title string, svgContents []*SvgContent, opt EpubOptions) (err error)

func Svg2Html

func Svg2Html(outputDir, title string, svgContents []*SvgContent, toc []EbookToc) (err error)

func Svg2Pdf

func Svg2Pdf(outputDir, title string, svgContents []*SvgContent, toc []EbookToc) (err error)

func TimeCost

func TimeCost(start time.Time)

func Unix2String

func Unix2String(stamp int64) string

Unix2String 时间戳[转换为]字符串 eg:(2019-09-09 09:09:09)

func UnmarshalJSON

func UnmarshalJSON(data []byte, v interface{}) error

UnmarshalJSON 将 data 中的 json 格式的数据, 解析到 v

func UnmarshalReader

func UnmarshalReader(r io.Reader, v interface{}) error

UnmarshalReader 将 r 中的 json 格式的数据, 解析到 v

func WriteFileWithTrunc

func WriteFileWithTrunc(filename, content string) (err error)

Types

type EbookToc

type EbookToc struct {
	Href      string `json:"href"`
	Level     int    `json:"level"`
	PlayOrder int    `json:"playOrder"`
	Offset    int    `json:"offset"`
	Text      string `json:"text"`
}

type EpubOptions

type EpubOptions struct {
	Cover       string
	Title       string
	Author      string
	Description string
	Output      string
	ImagesDir   string
	FontsDir    string
	HTML        []HtmlContent
	Verbose     bool
	PTitle      map[int]string
	Toc         []EbookToc
}

type HtmlContent

type HtmlContent struct {
	Content   string
	ChapterID string
	Toc       []EbookToc
}

type HtmlEle

type HtmlEle struct {
	X        string `json:"x"`
	Y        string `json:"y"`
	ID       string `json:"id"`
	Width    string `json:"width"`
	Height   string `json:"height"`
	Offset   string `json:"offset"`
	Href     string `json:"href"`
	Name     string `json:"name"`
	Style    string `json:"style"`
	Content  string `json:"content"`
	Class    string `json:"class"`
	Alt      string `json:"alt"`
	Len      string `json:"len"`
	Newline  bool   `json:"newline"`
	IsBold   bool   `json:"is_bold"`
	IsItalic bool   `json:"is_italic"`
	IsFn     bool   `json:"is_fn"`  // footnote: sup tag
	IsSub    bool   `json:"is_sub"` // sub tag
	Fn       struct {
		Href  string `json:"href"`
		Style string `json:"style"`
	} `json:"fn"`
	TextAlign string `json:"text_align"` // left; center; right
}

type HtmlToEpub

type HtmlToEpub struct {
	EpubOptions
	DefaultCover []byte
	// contains filtered or unexported fields
}

func (*HtmlToEpub) Run

func (h *HtmlToEpub) Run() (err error)

type PdfOption

type PdfOption struct {
	FileName  string
	CoverPath string
	PageSize  string
	Toc       bool
}

func (*PdfOption) GenPdf

func (p *PdfOption) GenPdf(buf *bytes.Buffer) (err error)

type QRCodeString

type QRCodeString string

func (*QRCodeString) Print

func (v *QRCodeString) Print()

type SvgContent

type SvgContent struct {
	Contents   []string
	ChapterID  string
	PathInEpub string
	OrderIndex int
}

type SvgContents

type SvgContents []*SvgContent

func (SvgContents) Len

func (a SvgContents) Len() int

func (SvgContents) Less

func (a SvgContents) Less(i, j int) bool

func (SvgContents) Swap

func (a SvgContents) Swap(i, j int)

type ValidUTF8Reader

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

ValidUTF8Reader implements a Reader which reads only bytes that constitute valid UTF-8

func NewValidUTF8Reader

func NewValidUTF8Reader(rd io.Reader) ValidUTF8Reader

NewValidUTF8Reader constructs a new ValidUTF8Reader that wraps an existing io.Reader

func (ValidUTF8Reader) Read

func (rd ValidUTF8Reader) Read(b []byte) (n int, err error)

Function Read reads bytes in the byte array b. n is the number of bytes read.

type WaitGroupPool

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

WaitGroupPool pool of WaitGroup

func NewWaitGroupPool

func NewWaitGroupPool(size int) *WaitGroupPool

NewWaitGroupPool creates a sized pool for WaitGroup

func (*WaitGroupPool) Add

func (p *WaitGroupPool) Add()

Add increments the WaitGroup counter by one. See sync.WaitGroup documentation for more information.

func (*WaitGroupPool) Done

func (p *WaitGroupPool) Done()

Done decrements the WaitGroup counter by one. See sync.WaitGroup documentation for more information.

func (*WaitGroupPool) Wait

func (p *WaitGroupPool) Wait()

Wait blocks until the WaitGroup counter is zero. See sync.WaitGroup documentation for more information.

Jump to

Keyboard shortcuts

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