Skip to content

Commit

Permalink
v3.3.0 (#75)
Browse files Browse the repository at this point in the history
* fix: show read in binds help

* build: add `.deb` and `.rpm` packages, update deps

* build: enable upload

* build: bump version

* refactor: move custom sources to providers

* refactor: move custom sources to providers

* refactor(where cmd): show flag suggestion

* refactor: move read/download chapter to a single place

* feat: inline mode added

* feat: add regex for inline mode

* docs: add inline mode docs

* build: bump version

* refactor: remove icons on sources cmd

* feat: option to choose default source added

* fix: flags short names

* docs: small README changes
  • Loading branch information
metafates authored Aug 17, 2022
1 parent 61928e5 commit 5c70bba
Show file tree
Hide file tree
Showing 35 changed files with 885 additions and 570 deletions.
18 changes: 18 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,21 @@ release:
draft: false
name_template: "{{.ProjectName}} v{{.Version}}"

nfpms:
-
file_name_template: "{{ .ConventionalFileName }}"
homepage: https://github.com/metafates/mangal
maintainer: metafates <[email protected]>
description: |-
The most advanced cli manga downloader in the entire universe!
license: MIT
formats:
- deb
- rpm

bindir: /usr/bin

rpm:
group: Unspecified
compression: lzma
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ https://user-images.githubusercontent.com/62389790/183284495-86140f8b-d543-4bc4-
- __LUAAAA SCRAPPEERRRSS!!!__ You can add any source you want by creating your own _(or using someone's else)_ scraper with __Lua 5.1__. See [mangal-scrapers repository](https://github.com/metafates/mangal-scrapers)
- __Download & Read Manga__ - I mean, it would be strange if you couldn't, right?
- __4 Different export formats__ - PDF, CBZ, ZIP and plain images
- __3 Different modes__ - TUI, Mini and Inline
- __Fast__ - yes.
- __Monolith__ - ZERO runtime dependencies. Even Lua is built in.
- __Fancy__ - (ノ>ω<)ノ :。・::・゚’★,。・:・゚’☆
Expand All @@ -52,7 +53,7 @@ Visit this link to install [Go](https://go.dev/doc/install)

Download the latest version from [GitHub release page](https://github.com/metafates/mangal/releases/latest)

### macOS
### macOS / Linux

Install using [Homebrew](https://brew.sh/)

Expand Down Expand Up @@ -84,12 +85,25 @@ Just run `mangal` and you're ready to go.

### Mini

There's also a `mini` mode that tries to mimic [ani-cli](https://github.com/pystardust/ani-cli)
Mini mode tries to mimic [ani-cli](https://github.com/pystardust/ani-cli)

To run: `mangal mini`

<img width="254" alt="Screenshot 2022-08-14 at 09 37 14" src="https://user-images.githubusercontent.com/62389790/184524070-88fd36f7-9875-4a41-904c-04caad110549.png">

### Inline

Inline mode is intended for use with other scripts.

Example of usage:

mangal inline --source Manganelo --query "death note" --manga first --chapters "@Vol.1 @" -d

> This will download the first volume of "Death Note" from Mangalelo.
Type `mangal help inline` for more information


### Other

See `mangal help` for more information
Expand All @@ -112,6 +126,11 @@ Run `mangal config init` to generate a default config file
# mangal.toml

[downloader]
# Default source to use
# Will prompt to choose if empty
# Type `mangal sources` for available sources
default_source = ''

# Name template of the downloaded chapters
# Available variables:
# {index} - index of the chapters
Expand Down Expand Up @@ -199,7 +218,7 @@ Check the [defined modules](luamodules) for more information.

For scraper examples, check the [mangal-scrapers repository](https://github.com/metafates/mangal-scrapers)

_Okay, so, how do I add a custom scraper?_
### Creating a custom scraper

1. Create a new lua file in the `mangal where --sources` folder
2. Filename will be used as a source name
Expand All @@ -209,7 +228,7 @@ _Okay, so, how do I add a custom scraper?_
- `ChapterPages(chapterUrl)` - must return a table of tables each having 2 fields `index` _(for ordering)_ and `url` _(to download image)_
4. __That's it!__ You can test it by running `mangal run ...` where `...` is a filename

New to Lua? [Quick start guide](https://learnxinyminutes.com/docs/lua/)
> New to Lua? [Quick start guide](https://learnxinyminutes.com/docs/lua/)
## Anilist

Expand Down
76 changes: 76 additions & 0 deletions cmd/inline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package cmd

import (
"fmt"
"github.com/metafates/mangal/inline"
"github.com/metafates/mangal/provider"
"github.com/samber/lo"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(inlineCmd)

inlineCmd.Flags().String("source", "", "source to use. see `mangal sources` for available sources")
inlineCmd.Flags().String("query", "", "query to search for")
inlineCmd.Flags().String("manga", "", "manga selector")
inlineCmd.Flags().String("chapters", "", "chapter selector")
inlineCmd.Flags().BoolP("download", "d", false, "download chapters")

lo.Must0(inlineCmd.MarkFlagRequired("source"))
lo.Must0(inlineCmd.MarkFlagRequired("query"))
lo.Must0(inlineCmd.MarkFlagRequired("manga"))
lo.Must0(inlineCmd.MarkFlagRequired("chapters"))
}

var inlineCmd = &cobra.Command{
Use: "inline",
Short: "Launch in the inline mode",
Long: `Launch in the inline mode for scripting
Manga selectors:
first - first manga in the list
last - last manga in the list
[number] - select manga by index
Chapter selectors:
first - first chapter in the list
last - last chapter in the list
all - all chapters in the list
[number] - select chapter by index
[from]-[to] - select chapters by range
@[substring]@ - select chapters by name substring`,
Example: "mangal inline --source Manganelo --query \"death note\" --manga first --chapters \"@Vol.1 @\" -d",
RunE: func(cmd *cobra.Command, args []string) error {
sourceName := lo.Must(cmd.Flags().GetString("source"))
p, ok := provider.Get(sourceName)
if !ok {
return fmt.Errorf("source not found: %s", sourceName)
}

src, err := p.CreateSource()
if err != nil {
return err
}

mangaPicker, err := inline.ParseMangaPicker(lo.Must(cmd.Flags().GetString("manga")))
if err != nil {
return err
}

chapterFilter, err := inline.ParseChaptersFilter(lo.Must(cmd.Flags().GetString("chapters")))
if err != nil {
return err
}

options := &inline.Options{
Source: src,
Download: lo.Must(cmd.Flags().GetBool("download")),
Query: lo.Must(cmd.Flags().GetString("query")),
MangaPicker: mangaPicker,
ChapterFilter: chapterFilter,
}

return inline.Run(options)
},
}
13 changes: 2 additions & 11 deletions cmd/mini.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package cmd

import (
"github.com/metafates/mangal/config"
"github.com/metafates/mangal/converter"
"github.com/metafates/mangal/mini"
"github.com/samber/lo"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func init() {
Expand All @@ -16,18 +13,12 @@ func init() {
miniCmd.Flags().BoolP("continue", "c", false, "continue reading")

miniCmd.MarkFlagsMutuallyExclusive("download", "continue")

miniCmd.Flags().StringP("format", "f", "", "output format")
lo.Must0(miniCmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return converter.Available(), cobra.ShellCompDirectiveDefault
}))
lo.Must0(viper.BindPFlag(config.FormatsUse, miniCmd.Flags().Lookup("format")))
}

var miniCmd = &cobra.Command{
Use: "mini",
Short: "Launch the in mini mode",
Long: `Launch mangal the in mini mode.
Short: "Launch in the mini mode",
Long: `Launch mangal in the mini mode.
Will try to mimic ani-cli.`,
RunE: func(cmd *cobra.Command, args []string) error {
options := mini.Options{
Expand Down
19 changes: 16 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/metafates/mangal/constant"
"github.com/metafates/mangal/converter"
"github.com/metafates/mangal/icon"
"github.com/metafates/mangal/provider"
"github.com/metafates/mangal/style"
"github.com/metafates/mangal/tui"
"github.com/samber/lo"
Expand All @@ -16,13 +17,13 @@ import (
)

func init() {
rootCmd.Flags().StringP("format", "f", "", "output format")
rootCmd.PersistentFlags().StringP("format", "F", "", "output format")
lo.Must0(rootCmd.RegisterFlagCompletionFunc("format", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return converter.Available(), cobra.ShellCompDirectiveDefault
}))
lo.Must0(viper.BindPFlag(config.FormatsUse, rootCmd.Flags().Lookup("format")))
lo.Must0(viper.BindPFlag(config.FormatsUse, rootCmd.PersistentFlags().Lookup("format")))

rootCmd.PersistentFlags().StringP("icons", "i", "", "icons variant")
rootCmd.PersistentFlags().StringP("icons", "I", "", "icons variant")
lo.Must0(rootCmd.RegisterFlagCompletionFunc("icons", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return icon.AvailableVariants(), cobra.ShellCompDirectiveDefault
}))
Expand All @@ -31,6 +32,18 @@ func init() {
rootCmd.PersistentFlags().BoolP("history", "H", true, "write history of the read chapters")
lo.Must0(viper.BindPFlag(config.HistorySaveOnRead, rootCmd.PersistentFlags().Lookup("history")))

rootCmd.PersistentFlags().StringP("source", "S", "", "source")
lo.Must0(rootCmd.RegisterFlagCompletionFunc("source", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
d := lo.Keys(provider.DefaultProviders())

if c, err := provider.CustomProviders(); err == nil {
d = append(d, lo.Keys(c)...)
}

return d, cobra.ShellCompDirectiveDefault
}))
lo.Must0(viper.BindPFlag(config.DownloaderDefaultSource, rootCmd.PersistentFlags().Lookup("source")))

rootCmd.Flags().BoolP("continue", "c", false, "continue reading")

// Clear temporary files on startup
Expand Down
4 changes: 2 additions & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"fmt"
"github.com/metafates/mangal/icon"
"github.com/metafates/mangal/source"
"github.com/metafates/mangal/provider/custom"
"github.com/samber/lo"
"github.com/spf13/cobra"
"os"
Expand All @@ -26,7 +26,7 @@ Or you can use mangal as a standalone lua interpreter.`,
sourcePath := args[0]

// LoadSource runs file when it's loaded
_, err := source.LoadSource(sourcePath, !lo.Must(cmd.Flags().GetBool("lenient")))
_, err := custom.LoadSource(sourcePath, !lo.Must(cmd.Flags().GetBool("lenient")))
if err != nil {
fmt.Println(icon.Get(icon.Fail) + " " + err.Error())
os.Exit(1)
Expand Down
7 changes: 2 additions & 5 deletions cmd/sources.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"github.com/metafates/mangal/icon"
"github.com/metafates/mangal/provider"
"github.com/metafates/mangal/style"
"github.com/spf13/cobra"
Expand All @@ -18,22 +17,20 @@ var sourcesCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
headerStyle := style.Combined(style.Bold, style.HiBlue)

cmd.Println(headerStyle("Builtin sources:"))
cmd.Println(headerStyle("Builtin:"))
for name := range provider.DefaultProviders() {
name = " " + name + " " + icon.Get(icon.Go)
cmd.Println(name)
}

cmd.Println()

cmd.Println(headerStyle("Custom sources:"))
cmd.Println(headerStyle("Custom:"))
custom, err := provider.CustomProviders()
if err != nil {
return err
}

for name := range custom {
name = " " + name + " " + icon.Get(icon.Lua)
cmd.Println(name)
}

Expand Down
19 changes: 8 additions & 11 deletions cmd/where.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,24 @@ var whereCmd = &cobra.Command{
whereSources := lo.Must(cmd.Flags().GetBool("sources"))
wherLogs := lo.Must(cmd.Flags().GetBool("logs"))

printConfigPath := func(header bool) {
if header {
cmd.Println(headerStyle("Configuration path:"))
title := func(do bool, what, arg string) {
if do {
cmd.Printf("%s %s\n", headerStyle(what+"?"), style.Yellow(arg))
}
}

printConfigPath := func(header bool) {
title(header, "Configuration", "--config")
cmd.Println(where.Config())
}

printSourcesPath := func(header bool) {
if header {
cmd.Println(headerStyle("Sources path:"))
}

title(header, "Sources", "--sources")
cmd.Println(where.Sources())
}

printLogsPath := func(header bool) {
if header {
cmd.Println(headerStyle("Logs path:"))
}

title(header, "Logs", "--logs")
cmd.Println(where.Logs())
}

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func setDefaults() {
DownloaderChapterNameTemplate: "[{padded-index}] {chapter}",
DownloaderAsync: true,
DownloaderCreateMangaDir: true,
DownloaderDefaultSource: "",

// Formats
FormatsUse: "pdf",
Expand Down
2 changes: 2 additions & 0 deletions config/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
DownloaderChapterNameTemplate = "downloader.chapter_name_template"
DownloaderAsync = "downloader.async"
DownloaderCreateMangaDir = "downloader.create_manga_dir"
DownloaderDefaultSource = "downloader.default_source"
)

const (
Expand Down Expand Up @@ -52,6 +53,7 @@ var EnvExposed = []string{
DownloaderPath,
DownloaderChapterNameTemplate,
DownloaderCreateMangaDir,
DownloaderDefaultSource,

// formats
FormatsUse,
Expand Down
2 changes: 1 addition & 1 deletion constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package constant

const (
Mangal = "mangal"
Version = "3.2.1"
Version = "3.3.0"
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
)

Expand Down
Loading

0 comments on commit 5c70bba

Please sign in to comment.