From ba3d89a3922980c979e122e0fa9620159a3bd8c3 Mon Sep 17 00:00:00 2001 From: Alessandro De Angelis Date: Thu, 28 Mar 2019 21:18:44 +0100 Subject: [PATCH] Support multiple urls --- README.md | 6 ++++++ main.go | 35 +++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7b241da0..27d2c80e 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,12 @@ Put the script under a folder. +### Multiple URLs + +```bash +./comics-downloader -url=url,url2,url3 +``` + ### Specify the format output available formats: diff --git a/main.go b/main.go index b73dab6f..9282b748 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "os" + "strings" "github.com/Girbons/comics-downloader/pkg/detector" "github.com/Girbons/comics-downloader/pkg/loader" @@ -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() @@ -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() + } + } }