Skip to content

Commit

Permalink
Merge pull request #11 from Girbons/multiple-urls
Browse files Browse the repository at this point in the history
Support multiple urls
  • Loading branch information
Girbons authored Mar 28, 2019
2 parents 1aac3b9 + ba3d89a commit f24f9c1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Put the script under a folder.

<img src="img/usage.gif?raw=true" />

### Multiple URLs

```bash
./comics-downloader -url=url,url2,url3
```

### Specify the format output

available formats:
Expand Down
35 changes: 21 additions & 14 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"strings"

"github.com/Girbons/comics-downloader/pkg/detector"
"github.com/Girbons/comics-downloader/pkg/loader"
Expand All @@ -14,7 +15,7 @@ func main() {
// use log INFO Level
log.SetLevel(log.InfoLevel)
// arguments setup
url := flag.String("url", "", "Comic URL")
url := flag.String("url", "", "Comic URL or Comic URLS by separating each site with a comma without the use of spaces")
format := flag.String("format", "pdf", "Comic format output, supported formats are pdf,epub,cbr,cbz")
country := flag.String("country", "", "Set the country to retrieve a manga, Used by MangaRock")
flag.Parse()
Expand All @@ -25,25 +26,31 @@ func main() {
os.Exit(1)
}

// check if the url is supported
source, check := detector.DetectComic(*url)
if !check {
log.WithFields(log.Fields{
"site": *url,
}).Error("This site is not supported :(")
os.Exit(1)
if !strings.HasSuffix(*url, ",") {
*url = *url + ","
}

// check if the format is supported
if !detector.DetectFormatOutput(*format) {
log.WithFields(log.Fields{
"format": *format,
}).Info("Format not supported pdf will be used instead")
}).Error("Format not supported pdf will be used instead")
}

// in case the url is supported
// setup the right strategy to parse a comic
comic := loader.LoadComicFromSource(source, *url, *country)
comic.SetFormat(*format)
comic.MakeComic()
for _, u := range strings.Split(*url, ",") {
if u != "" {
// check if the url is supported
source, check := detector.DetectComic(u)
if !check {
log.WithFields(log.Fields{"site": u}).Error("This site is not supported :(")
continue
}
log.WithFields(log.Fields{"url": u}).Info("Downloading...")
// in case the url is supported
// setup the right strategy to parse a comic
comic := loader.LoadComicFromSource(source, u, *country)
comic.SetFormat(*format)
comic.MakeComic()
}
}
}

0 comments on commit f24f9c1

Please sign in to comment.