Skip to content

Commit

Permalink
Merge pull request #47 from metafates/dev
Browse files Browse the repository at this point in the history
Mangal 2.1.0
  • Loading branch information
metafates authored Jun 29, 2022
2 parents 5deea50 + 264d3b1 commit ca888e5
Show file tree
Hide file tree
Showing 13 changed files with 479 additions and 1,393 deletions.
42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ https://user-images.githubusercontent.com/62389790/174501320-119474c3-c745-4f95-
__Mangal__ is a feature rich, configurable manga browser & downloader
written in Go with support for different formats

⚙️ One of the most important features of Mangal is that it supports user defined scrapers
that can be added with just a few lines of config file (see [config](#config) & [limitations](#limitations))
⚙️ User defined scrapers support
(see [config](#config) & [limitations](#limitations))

🦎 Works in both modes - TUI & Inline. Use it as a standalone app or integrate with scripts
🦎 TUI & Inline modes. Use it as a standalone app or integrate with scripts

🚀 It's fast. Parallel downloader is capable of downloading ~1GB per minute

🍥 Integration with Anilist! __BETA__

Expand Down Expand Up @@ -101,9 +103,8 @@ Config is located at the OS default config directory.
</details>


You can load config from custom path by using `--config` flag
You can load config from custom path by using `--config` flag or by setting `MANGAL_CONFIG_PATH` environment variable.

`mangal --config /user/configs/config.toml`

By default, Mangal uses [manganelo](https://m.manganelo.com/www) as a source

Expand All @@ -114,15 +115,28 @@ By default, Mangal uses [manganelo](https://m.manganelo.com/www) as a source
# Which sources to use. You can use several sources, it won't affect perfomance
use = ['manganelo']

# Type "mangal formats" to show more information about formats
format = "pdf"

# If false, then OS default reader will be used
use_custom_reader = false
custom_reader = "zathura"




[formats]
# Type "mangal formats" to show more information about formats
default = "pdf"

# Add ComicInfo.xml to CBZ files
comicinfo = true




[downloader]
# Custom download path, can be either relative (to the current directory) or absolute
download_path = '.'
# You can use environment variable $HOME to refer to user's home directory
# If environment variable "MANGAL_DOWNLOAD_PATH" is set, then it will be used instead
path = '.'

# How chapters should be named when downloaded
# Use %d to specify chapter number and %s to specify chapter title
Expand All @@ -134,6 +148,9 @@ chapter_name_template = "[%0d] %s"
# Usually happens on slow machines
cache_images = false




[anilist]
# Enable Anilist integration (BETA)
# See https://github.com/metafates/mangal/wiki/Anilist-Integration for more information
Expand All @@ -148,6 +165,9 @@ secret = ""
# Will mark downloaded chapters as read on Anilist
mark_downloaded = false




[ui]
# How to display chapters in TUI mode
# Use %d to specify chapter number and %s to specify chapter title
Expand All @@ -168,6 +188,9 @@ mark = "▼"
# Search window title
title = "Mangal"




[sources]
[sources.manganelo]
# Base url
Expand Down Expand Up @@ -228,6 +251,7 @@ Flags:
-c, --config string use config from path
-f, --format string use custom format
-h, --help help for mangal
-i, --incognito will not sync with anilist even if enabled
Use "mangal [command] --help" for more information about a command.
```
Expand Down
57 changes: 53 additions & 4 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os/exec"
"path"
"path/filepath"
"regexp"
"strings"
)

Expand All @@ -34,7 +35,7 @@ The ultimate CLI manga downloader`,
}

if format, _ := cmd.Flags().GetString("format"); format != "" {
UserConfig.Format = FormatType(format)
UserConfig.Formats.Default = FormatType(format)
}

err := ValidateConfig(UserConfig)
Expand Down Expand Up @@ -363,6 +364,7 @@ var configInitCmd = &cobra.Command{
Long: "Init default config at the default location.\nIf the config already exists, it will not be overwritten",
Run: func(cmd *cobra.Command, args []string) {
force, _ := cmd.Flags().GetBool("force")
clean, _ := cmd.Flags().GetBool("clean")

configPath, err := GetConfigPath()

Expand All @@ -373,11 +375,26 @@ var configInitCmd = &cobra.Command{
exists, err := Afero.Exists(configPath)

var createConfig = func() {
var configToWrite string

if clean {
// remove all lines with comments from toml string
configToWrite = regexp.MustCompile("\n[^\n]*#.*").ReplaceAllString(DefaultConfigString, "")

// remove all empty lines from toml string
configToWrite = regexp.MustCompile("\n\n+").ReplaceAllString(configToWrite, "\n")

// insert newline before each section
configToWrite = regexp.MustCompile("(?m)^(\\[.*])").ReplaceAllString(configToWrite, "\n$1")
} else {
configToWrite = DefaultConfigString
}

if err := Afero.MkdirAll(filepath.Dir(configPath), 0700); err != nil {
log.Fatal("Error while creating file")
} else if file, err := Afero.Create(configPath); err != nil {
log.Fatal("Error while creating file")
} else if _, err = file.Write(DefaultConfigBytes); err != nil {
} else if _, err = file.Write([]byte(configToWrite)); err != nil {
log.Fatal("Error while writing to file")
} else {
fmt.Printf("Config created at\n%s\n", successStyle.Render(configPath))
Expand All @@ -401,6 +418,35 @@ var configInitCmd = &cobra.Command{
},
}

var configRemoveCmd = &cobra.Command{
Use: "remove",
Short: "Remove config",
Long: "Remove config.\nIf config doesn't exist, it will not be removed",
Run: func(cmd *cobra.Command, args []string) {
configPath, err := GetConfigPath()

if err != nil {
log.Fatal("Can't get config location, permission denied, probably")
}

exists, err := Afero.Exists(configPath)

if err != nil {
log.Fatalf("Can't understand if config exists or not. It is expected at\n%s\n", configPath)
}

if exists {
if err := Afero.Remove(configPath); err != nil {
log.Fatal("Error while removing file")
} else {
fmt.Println("Config removed")
}
} else {
fmt.Println("Config doesn't exist, nothing to remove")
}
},
}

var formatsCmd = &cobra.Command{
Use: "formats",
Short: "Information about available formats",
Expand Down Expand Up @@ -559,7 +605,7 @@ It checks if config file is valid and used sources are available`,
}

// check if images is not empty
if len(*image) == 0 {
if image.Len() == 0 {
sourceNotAvailable(source)
}

Expand All @@ -580,9 +626,12 @@ func init() {
configCmd.AddCommand(configWhereCmd)
configCmd.AddCommand(configPreviewCmd)
configCmd.AddCommand(configEditCmd)
configInitCmd.Flags().BoolP("force", "f", false, "overwrite existing config")
configCmd.AddCommand(configInitCmd)

configInitCmd.Flags().BoolP("force", "f", false, "overwrite existing config")
configInitCmd.Flags().BoolP("clean", "c", false, "do not add comments and empty lines")

configCmd.AddCommand(configRemoveCmd)
rootCmd.AddCommand(configCmd)

inlineCmd.Flags().Int("manga", -1, "choose manga by index")
Expand Down
Loading

0 comments on commit ca888e5

Please sign in to comment.