mirror of
https://github.com/NohamR/papeer.git
synced 2026-05-25 04:17:19 +00:00
feat: quiet option
This commit is contained in:
@@ -29,6 +29,7 @@ Flags:
|
|||||||
-n, --name string book name (default: page title)
|
-n, --name string book name (default: page title)
|
||||||
-o, --offset int skip first chapters, in recursive mode
|
-o, --offset int skip first chapters, in recursive mode
|
||||||
--output string file name (default: book name)
|
--output string file name (default: book name)
|
||||||
|
-q, --quiet hide progress bar
|
||||||
-r, --recursive create one chapter per natigation item
|
-r, --recursive create one chapter per natigation item
|
||||||
-s, --selector string table of content CSS selector, in resursive mode
|
-s, --selector string table of content CSS selector, in resursive mode
|
||||||
-t, --threads int download concurrency, in recursive mode (default -1)
|
-t, --threads int download concurrency, in recursive mode (default -1)
|
||||||
@@ -111,7 +112,7 @@ go get -u github.com/lapwat/papeer
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
platform=linux # use platform=darwin for MacOS
|
platform=linux # use platform=darwin for MacOS
|
||||||
release=0.3.2
|
release=0.3.3
|
||||||
curl -L https://github.com/lapwat/papeer/releases/download/v$release/papeer-v$release-$platform-amd64 > papeer
|
curl -L https://github.com/lapwat/papeer/releases/download/v$release/papeer-v$release-$platform-amd64 > papeer
|
||||||
chmod +x papeer
|
chmod +x papeer
|
||||||
sudo mv papeer /usr/local/bin
|
sudo mv papeer /usr/local/bin
|
||||||
@@ -119,7 +120,7 @@ sudo mv papeer /usr/local/bin
|
|||||||
|
|
||||||
### On Windows
|
### On Windows
|
||||||
|
|
||||||
Download [latest release](https://github.com/lapwat/papeer/releases/download/v0.3.2/papeer-v0.3.2-windows-amd64.exe).
|
Download [latest release](https://github.com/lapwat/papeer/releases/download/3/papeer-v0.3.3-windows-amd64.exe).
|
||||||
|
|
||||||
## Install kindlegen to export websites to MOBI (optional)
|
## Install kindlegen to export websites to MOBI (optional)
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func NewScrapeConfigFake() *ScrapeConfig {
|
|||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBookFromURL(url, selector, name, author string, recursive, include, imagesOnly bool, limit, offset, delay, threads int) book {
|
func NewBookFromURL(url, selector, name, author string, recursive, include, imagesOnly, quiet bool, limit, offset, delay, threads int) book {
|
||||||
config1 := NewScrapeConfig()
|
config1 := NewScrapeConfig()
|
||||||
config1.imagesOnly = imagesOnly
|
config1.imagesOnly = imagesOnly
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ func NewBookFromURL(url, selector, name, author string, recursive, include, imag
|
|||||||
config2.threads = threads
|
config2.threads = threads
|
||||||
config2.include = include
|
config2.include = include
|
||||||
config2.imagesOnly = imagesOnly
|
config2.imagesOnly = imagesOnly
|
||||||
chapters, home = tableOfContent(url, config2, config1)
|
chapters, home = tableOfContent(url, config2, config1, quiet)
|
||||||
} else {
|
} else {
|
||||||
chapters = []chapter{NewChapterFromURL(url, []*ScrapeConfig{config1}, 0, func(index int, name string) {})}
|
chapters = []chapter{NewChapterFromURL(url, []*ScrapeConfig{config1}, 0, func(index int, name string) {})}
|
||||||
home = chapters[0]
|
home = chapters[0]
|
||||||
@@ -240,7 +240,7 @@ func NewChapterFromURL(url string, configs []*ScrapeConfig, index int, updatePro
|
|||||||
return chapter{string(body), name, article.Byline, content, subchapters, config}
|
return chapter{string(body), name, article.Byline, content, subchapters, config}
|
||||||
}
|
}
|
||||||
|
|
||||||
func tableOfContent(url string, config *ScrapeConfig, subConfig *ScrapeConfig) ([]chapter, chapter) {
|
func tableOfContent(url string, config *ScrapeConfig, subConfig *ScrapeConfig, quiet bool) ([]chapter, chapter) {
|
||||||
base, err := urllib.Parse(url)
|
base, err := urllib.Parse(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@@ -252,9 +252,13 @@ func tableOfContent(url string, config *ScrapeConfig, subConfig *ScrapeConfig) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
chapters := make([]chapter, len(links))
|
chapters := make([]chapter, len(links))
|
||||||
// progress := NewProgress(links, "", 0)
|
|
||||||
delay := config.delay
|
delay := config.delay
|
||||||
|
|
||||||
|
var p progress
|
||||||
|
if quiet == false {
|
||||||
|
p = NewProgress(links, "", 0)
|
||||||
|
}
|
||||||
|
|
||||||
if delay >= 0 {
|
if delay >= 0 {
|
||||||
// synchronous mode
|
// synchronous mode
|
||||||
|
|
||||||
@@ -265,9 +269,11 @@ func tableOfContent(url string, config *ScrapeConfig, subConfig *ScrapeConfig) (
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sc := NewChapterFromURL(u.String(), []*ScrapeConfig{subConfig}, 0, func(index int, name string) {})
|
chapters[index] = NewChapterFromURL(u.String(), []*ScrapeConfig{subConfig}, 0, func(index int, name string) {})
|
||||||
chapters[index] = sc
|
|
||||||
// progress.Increment(index)
|
if quiet == false {
|
||||||
|
p.Increment(index)
|
||||||
|
}
|
||||||
|
|
||||||
// short sleep for last chapter to let the progress bar update
|
// short sleep for last chapter to let the progress bar update
|
||||||
if index == len(links)-1 {
|
if index == len(links)-1 {
|
||||||
@@ -301,9 +307,11 @@ func tableOfContent(url string, config *ScrapeConfig, subConfig *ScrapeConfig) (
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sc := NewChapterFromURL(u.String(), []*ScrapeConfig{subConfig}, 0, func(index int, name string) {})
|
chapters[index] = NewChapterFromURL(u.String(), []*ScrapeConfig{subConfig}, 0, func(index int, name string) {})
|
||||||
chapters[index] = sc
|
|
||||||
// progress.Increment(index)
|
if quiet == false {
|
||||||
|
p.Increment(index)
|
||||||
|
}
|
||||||
|
|
||||||
<-semaphore
|
<-semaphore
|
||||||
}(index, l)
|
}(index, l)
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ var getCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
url := args[0]
|
url := args[0]
|
||||||
b := book.NewBookFromURL(url, selector, name, author, recursive, include, images, limit, offset, delay, threads)
|
b := book.NewBookFromURL(url, selector, name, author, recursive, include, images, quiet, limit, offset, delay, threads)
|
||||||
|
|
||||||
fakeConfig := book.NewScrapeConfigFake()
|
fakeConfig := book.NewScrapeConfigFake()
|
||||||
fakeChapter := book.NewChapter("", b.Name(), b.Author(), "", b.Chapters(), fakeConfig)
|
fakeChapter := book.NewChapter("", b.Name(), b.Author(), "", b.Chapters(), fakeConfig)
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().BoolVarP(&recursive, "recursive", "r", false, "create one chapter per natigation item")
|
rootCmd.PersistentFlags().BoolVarP(&recursive, "recursive", "r", false, "create one chapter per natigation item")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&include, "include", "i", false, "include URL as first chapter, in resursive mode")
|
rootCmd.PersistentFlags().BoolVarP(&include, "include", "i", false, "include URL as first chapter, in resursive mode")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&images, "images", "", false, "retrieve images only")
|
rootCmd.PersistentFlags().BoolVarP(&images, "images", "", false, "retrieve images only")
|
||||||
|
rootCmd.PersistentFlags().BoolVarP(&quiet, "quiet", "q", false, "hide progress bar")
|
||||||
rootCmd.PersistentFlags().IntVarP(&limit, "limit", "l", -1, "limit number of chapters, in recursive mode")
|
rootCmd.PersistentFlags().IntVarP(&limit, "limit", "l", -1, "limit number of chapters, in recursive mode")
|
||||||
rootCmd.PersistentFlags().IntVarP(&offset, "offset", "o", 0, "skip first chapters, in recursive mode")
|
rootCmd.PersistentFlags().IntVarP(&offset, "offset", "o", 0, "skip first chapters, in recursive mode")
|
||||||
rootCmd.PersistentFlags().IntVarP(&delay, "delay", "d", -1, "time to wait before downloading next chapter, in milliseconds")
|
rootCmd.PersistentFlags().IntVarP(&delay, "delay", "d", -1, "time to wait before downloading next chapter, in milliseconds")
|
||||||
|
|||||||
@@ -14,6 +14,6 @@ var versionCmd = &cobra.Command{
|
|||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the version number of papeer",
|
Short: "Print the version number of papeer",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
fmt.Println("papeer v0.3.2")
|
fmt.Println("papeer v0.3.3")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user