From 87c1055ea10d7b1e9d542e8e74456cc6088c30af Mon Sep 17 00:00:00 2001 From: teddy Date: Thu, 12 Sep 2024 16:37:07 +0200 Subject: [PATCH] fix : now can download multiple source of manga * add config parameter `format`, `name` * change config parameter type of `start_at` to `int` * parameter `--source` has priority over `--output` * remove config parameter `prefix` --- CHANGELOG.md | 19 +++++++++++++++++++ README.md | 20 +++++++++++++++----- commands/base.go | 22 +++++++++++----------- config/config.go | 5 +++-- service/convert.go | 5 +++-- service/page.go | 10 +++++++--- service/scan-to-epub.go | 5 +++-- 7 files changed, 61 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index baeec16..35aee7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## [Unreleased] + +### Added + +* Add config parameter `format`, `name` + +### Changed + +* Change config parameter type of `start_at` to `int` + +### Fixed + +* Parameter `--source` has priority over `--output` +* Now can download multiple source of manga + +### Removed + +* Remove config parameter `prefix` + ## [1.5.0] - 2024-09-09 ### Changed diff --git a/README.md b/README.md index 9fd979d..f612c7d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Description -Golang adaptation of [scan-to-epub](https://github.com/LordPax/scan-to-epub.git) project, which aims to download Scan chapters and convert them into EPUB for my e-reader. +Golang project, which aims to download Scan chapters and convert them into EPUB for e-reader. ## Source @@ -43,18 +43,28 @@ Will generate a config file at `~/.config/scan2epub/config.ini` create directory ./scan2epub ``` -4. Modify your config at `~/.config/scan2epub/config.ini`: +4. Modify your config at `~/.config/scan2epub/config.ini` -**Example** +## Config example ```ini default="onepiece" [onepiece] +name="OnePiece" url="https://lelscans.net/mangas/one-piece/{chap}/{page}.{ext}" epub_dir="/home/lordpax/Perso/epub/onepiece/" author="LordPax" description="Scan of One Piece generated by scan2epub" -prefix="00" -start_at="0" +start_at=0 +format=true ``` + +* `default`: Default manga to download +* `name`: Name of the manga +* `url`: URL format of the manga +* `epub_dir`: Directory to save the generated epub +* `author`: Author of the manga +* `description`: Description of the manga +* `start_at`: Chapter to start downloading +* `format`: Add "0" to page number if less than 10 diff --git a/commands/base.go b/commands/base.go index cc5698b..4be2363 100644 --- a/commands/base.go +++ b/commands/base.go @@ -13,30 +13,30 @@ func MainFlags() []cli.Flag { l := lang.GetLocalize() return []cli.Flag{ &cli.StringFlag{ - Name: "output", - Aliases: []string{"o"}, - Usage: l.Get("output-desc"), + Name: "source", + Aliases: []string{"S"}, + Usage: l.Get("source-desc"), Action: func(c *cli.Context, value string) error { if value == "" { - return fmt.Errorf(l.Get("output-dir-empty")) + return fmt.Errorf(l.Get("source-empty")) } - defaultSource := config.CONFIG_INI.Section("").Key("default").String() - config.CONFIG_INI.Section(defaultSource).Key("epub_dir").SetValue(value) + config.CONFIG_INI.Section("").Key("default").SetValue(value) return nil }, }, &cli.StringFlag{ - Name: "source", - Aliases: []string{"S"}, - Usage: l.Get("source-desc"), + Name: "output", + Aliases: []string{"o"}, + Usage: l.Get("output-desc"), Action: func(c *cli.Context, value string) error { if value == "" { - return fmt.Errorf(l.Get("source-empty")) + return fmt.Errorf(l.Get("output-dir-empty")) } - config.CONFIG_INI.Section("").Key("default").SetValue(value) + defaultSource := config.CONFIG_INI.Section("").Key("default").String() + config.CONFIG_INI.Section(defaultSource).Key("epub_dir").SetValue(value) return nil }, diff --git a/config/config.go b/config/config.go index 61a48e0..d7218c0 100644 --- a/config/config.go +++ b/config/config.go @@ -22,12 +22,13 @@ var ( CONFIG_EXEMPLE = `default="onepiece" [onepiece] +name="OnePiece" url="https://lelscans.net/mangas/one-piece/{chap}/{page}.{ext}" epub_dir="` + path.Join(home, "scan2epub") + `" author="Echiro Oda" description="Scan of One Piece generated by scan2epub" -prefix="00" -start_at="0"` +start_at=0 +format=true` ) func InitConfig() error { diff --git a/service/convert.go b/service/convert.go index 37053d9..9a6cb28 100644 --- a/service/convert.go +++ b/service/convert.go @@ -58,8 +58,9 @@ func createEpub(pages []string, epubDir string, chap string) error { defaultSource := config.CONFIG_INI.Section("").Key("default").String() author := config.CONFIG_INI.Section(defaultSource).Key("author").String() description := config.CONFIG_INI.Section(defaultSource).Key("description").String() + name := config.CONFIG_INI.Section(defaultSource).Key("name").String() - epubFile, err := epub.NewEpub("Chapter " + chap) + epubFile, err := epub.NewEpub(name + " chapter " + chap) if err != nil { return err } @@ -77,7 +78,7 @@ func createEpub(pages []string, epubDir string, chap string) error { } } - epubFileName := fmt.Sprintf("chap-%s.epub", chap) + epubFileName := fmt.Sprintf("%s-%s.epub", name, chap) epubPath := path.Join(epubDir, epubFileName) if err := epubFile.Write(epubPath); err != nil { return err diff --git a/service/page.go b/service/page.go index 2f85970..fde0bfd 100644 --- a/service/page.go +++ b/service/page.go @@ -46,8 +46,10 @@ func replaceValue(url string, data map[string]string) string { func formatPageName(page string) string { pageInt, _ := strconv.Atoi(page) + defaultSource := config.CONFIG_INI.Section("").Key("default").String() + format, _ := config.CONFIG_INI.Section(defaultSource).Key("format").Bool() - if pageInt < 10 { + if format && pageInt < 10 { return "0" + page } @@ -57,7 +59,10 @@ func formatPageName(page string) string { func getListOfPages(url, chap, tmpPage string) []Page { var page []Page - for i := 0; ; i++ { + defaultSource := config.CONFIG_INI.Section("").Key("default").String() + startAt, _ := config.CONFIG_INI.Section(defaultSource).Key("start_at").Int() + + for i := startAt; ; i++ { formatPage := formatPageName(strconv.Itoa(i)) imgURL, ext := getWorkingUrl(url, chap, formatPage) @@ -65,7 +70,6 @@ func getListOfPages(url, chap, tmpPage string) []Page { break } - // fileName := fmt.Sprintf("%s.%s", formatPage, ext) pathName := path.Join(tmpPage, formatPage+"."+ext) pageFound := Page{Url: imgURL, Path: pathName} diff --git a/service/scan-to-epub.go b/service/scan-to-epub.go index 4fa7d00..2d8251c 100644 --- a/service/scan-to-epub.go +++ b/service/scan-to-epub.go @@ -31,9 +31,10 @@ func Scan2Epub(chaps []string) error { func CheckChapExist(chap string) bool { defaultSource := config.CONFIG_INI.Section("").Key("default").String() url := config.CONFIG_INI.Section(defaultSource).Key("url").String() - prefix := config.CONFIG_INI.Section(defaultSource).Key("prefix").String() + startAt, _ := config.CONFIG_INI.Section(defaultSource).Key("start_at").Int() - workingUrl, _ := getWorkingUrl(url, chap, prefix) + formatPage := formatPageName(strconv.Itoa(startAt)) + workingUrl, _ := getWorkingUrl(url, chap, formatPage) return workingUrl != "" }