Skip to content

Commit

Permalink
fix : now can download multiple source of manga
Browse files Browse the repository at this point in the history
* add config parameter `format`, `name`
* change config parameter type of `start_at` to `int`
* parameter `--source` has priority over `--output`
* remove config parameter `prefix`
  • Loading branch information
LordPax committed Sep 12, 2024
1 parent bc34ad3 commit 87c1055
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 25 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
22 changes: 11 additions & 11 deletions commands/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions service/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
10 changes: 7 additions & 3 deletions service/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -57,15 +59,17 @@ 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)

if imgURL == "" {
break
}

// fileName := fmt.Sprintf("%s.%s", formatPage, ext)
pathName := path.Join(tmpPage, formatPage+"."+ext)
pageFound := Page{Url: imgURL, Path: pathName}

Expand Down
5 changes: 3 additions & 2 deletions service/scan-to-epub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ""
}
Expand Down

0 comments on commit 87c1055

Please sign in to comment.