luaprovider

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: Unlicense Imports: 16 Imported by: 1

README

a logo depicting a moon

Lua Provider

Warning

This is a beta software. The API is not stable and may change at any time.

This is a generic provider for libmangal that uses Lua scripts to create subproviders.

It uses native go implementation of the Lua interpreter and provides a set of libraries that can be used in the scripts.

Take a look at the official lua scripts repository

Features

  • Built-in Lua VM without CGO with gopher-lua
  • Batteries-included library
  • Ships with CLI helper tools for generating templates & probing.
  • Luadoc generation which enables autocompletion for you IDE
  • Script template generation

Note

It is recommended to use lua-language-server to get nice completions for your IDE

VSCode extension

Scripts

Overview

See examples of scripts

Scripts must look like this:

---> name: Script name
---> description: Script description
---> version: v0.1.0
---> website: https://example.com

function SearchMangas(query)
  return {}
end

function MangaVolumes(manga)
 return {} 
end

function VolumeChapters(volume)
 return {} 
end

function ChapterPages(chapter)
  return {}
end

Notice the four required global functions

  • SearchMangas - searches for mangas based on the given query.
  • MangaVolumes - gets manga volumes. Each manga must have at least 1 volume.
  • VolumeChapters - gets chapters of the given volume.
  • ChapterPages - gets pages of the given chapter.

Also, each script must contain the following lines:

---> name: Script name
---> description: Script description
---> version: v0.1.0
---> website: https://example.com

Basically, ---> indicates that this line contains script information field in YAML format.

  • name - Name of the script
  • description - Description of the script
  • version - Script version. It must be a valid semver

The scripts can load sdk with

local sdk = require("sdk")

Which provides these packages:

Packages

Headless browser coming soon...

Developing

Install lua-provider-gen helper tool

Then use it to generate a new workflow

lua-provider-gen -sdk -provider

This command will create the following files:

  • sdk.lua - gives IDE autocompletion
  • provider.lua - a provider script template

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LuaDoc

func LuaDoc() string

LuaDoc will generate library documentation so that language servers can benefit from it.

It's optimized for the https://github.com/LuaLS/lua-language-server

func LuaTemplate

func LuaTemplate() string

LuaTemplate will generate template for the valid lua script used by this provider.

func NewLoader

func NewLoader(script []byte, options Options) (libmangal.ProviderLoader[Manga, Volume, Chapter, Page], error)

NewLoader creates new lua provider loader for the given script.

It won't run the script itself.

Types

type Chapter

type Chapter struct {
	Title  string  `gluamapper:"title"`
	URL    string  `gluamapper:"url"`
	Number float32 `gluamapper:"number"`
	// contains filtered or unexported fields
}

func (Chapter) ComicInfoXml

func (c Chapter) ComicInfoXml() (comicInfo libmangal.ComicInfoXml, ok bool)

func (Chapter) Info

func (c Chapter) Info() libmangal.ChapterInfo

func (Chapter) IntoLValue

func (c Chapter) IntoLValue() lua.LValue

func (Chapter) Volume

func (c Chapter) Volume() libmangal.Volume

type IntoLValue

type IntoLValue interface {
	IntoLValue() lua.LValue
}

type Loader

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

func (Loader) Info

func (l Loader) Info() libmangal.ProviderInfo

func (Loader) Load

type Manga

type Manga struct {
	Title         string `gluamapper:"title"`
	AnilistSearch string `gluamapper:"anilist_search"`
	URL           string `gluamapper:"url"`
	ID            string `gluamapper:"id"`
	Cover         string `gluamapper:"cover"`
	Banner        string `gluamapper:"banner"`
	// contains filtered or unexported fields
}

func (Manga) Info

func (m Manga) Info() libmangal.MangaInfo

func (Manga) IntoLValue

func (m Manga) IntoLValue() lua.LValue

func (Manga) SeriesJson

func (m Manga) SeriesJson() (seriesJson libmangal.SeriesJson, ok bool)

type Options

type Options struct {
	HTTPClient *http.Client
	HTTPStore  gokv.Store
}

func DefaultOptions

func DefaultOptions() Options

type Page

type Page struct {
	Extension string `gluamapper:"extension"`

	// URL is the url of the page image
	URL string `gluamapper:"url"`

	Headers map[string]string `gluamapper:"headers"`
	Cookies map[string]string `gluamapper:"cookies"`
	// contains filtered or unexported fields
}

func (Page) Chapter

func (p Page) Chapter() libmangal.Chapter

func (Page) GetExtension

func (p Page) GetExtension() string

type Provider

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

func (Provider) ChapterPages

func (p Provider) ChapterPages(
	ctx context.Context,
	log libmangal.LogFunc,
	chapter Chapter,
) ([]Page, error)

func (Provider) GetPageImage

func (p Provider) GetPageImage(
	ctx context.Context,
	log libmangal.LogFunc,
	page Page,
) ([]byte, error)

func (Provider) Info

func (p Provider) Info() libmangal.ProviderInfo

func (Provider) MangaVolumes

func (p Provider) MangaVolumes(
	ctx context.Context,
	log libmangal.LogFunc,
	manga Manga,
) ([]Volume, error)

func (Provider) SearchMangas

func (p Provider) SearchMangas(
	ctx context.Context,
	log libmangal.LogFunc,
	query string,
) ([]Manga, error)

func (Provider) VolumeChapters

func (p Provider) VolumeChapters(
	ctx context.Context,
	log libmangal.LogFunc,
	volume Volume,
) ([]Chapter, error)

type Volume

type Volume struct {
	Number int `gluamapper:"number"`
	// contains filtered or unexported fields
}

func (Volume) Info

func (v Volume) Info() libmangal.VolumeInfo

func (Volume) IntoLValue

func (v Volume) IntoLValue() lua.LValue

func (Volume) Manga

func (v Volume) Manga() libmangal.Manga

Jump to

Keyboard shortcuts

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