Skip to content

Commit ab5e2ed

Browse files
committed
accept several urls, fix tests, remove unused book struct
1 parent bf3fc65 commit ab5e2ed

File tree

8 files changed

+73
-114
lines changed

8 files changed

+73
-114
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ go install github.com/lapwat/papeer@latest
141141
```sh
142142
# use platform=darwin for MacOS
143143
platform=linux
144-
release=0.5.6
144+
release=0.6.0
145145

146146
# download and extract
147147
curl -L https://github.com/lapwat/papeer/releases/download/v$release/papeer-v$release-$platform-amd64.tar.gz > papeer.tar.gz
@@ -154,7 +154,7 @@ sudo mv papeer /usr/local/bin
154154

155155
### Windows
156156

157-
Download [latest release](https://github.com/lapwat/papeer/releases/download/v0.5.6/papeer-v0.5.6-windows-amd64.zip).
157+
Download [latest release](https://github.com/lapwat/papeer/releases/download/v0.6.0/papeer-v0.6.0-windows-amd64.zip).
158158

159159
## MOBI support
160160

book/book.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

book/chapter.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ type chapter struct {
99
config *ScrapeConfig
1010
}
1111

12+
func NewEmptyChapter() chapter {
13+
return chapter{"", "", "", "", []chapter{}, NewScrapeConfigNoInclude()}
14+
}
15+
1216
func NewChapter(body, name, author, content string, subChapters []chapter, config *ScrapeConfig) chapter {
1317
return chapter{body, name, author, content, subChapters, config}
1418
}
@@ -21,6 +25,10 @@ func (c chapter) Name() string {
2125
return c.name
2226
}
2327

28+
func (c *chapter) SetName(name string) {
29+
c.name = name
30+
}
31+
2432
func (c chapter) Author() string {
2533
return c.author
2634
}
@@ -32,3 +40,7 @@ func (c chapter) Content() string {
3240
func (c chapter) SubChapters() []chapter {
3341
return c.subChapters
3442
}
43+
44+
func (c *chapter) AddSubChapter(newChapter chapter) {
45+
c.subChapters = append(c.subChapters, newChapter)
46+
}

book/format_test.go

Lines changed: 17 additions & 17 deletions
Large diffs are not rendered by default.

book/scraper.go

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func NewScrapeConfig() *ScrapeConfig {
3636
return &ScrapeConfig{0, "", false, -1, 0, false, -1, -1, true, false, false}
3737
}
3838

39+
func NewScrapeConfigNoInclude() *ScrapeConfig {
40+
return &ScrapeConfig{0, "", false, -1, 0, false, -1, -1, false, false, false}
41+
}
42+
3943
func NewScrapeConfigs(selectors []string) []*ScrapeConfig {
4044
configs := []*ScrapeConfig{}
4145

@@ -93,46 +97,6 @@ func NewScrapeConfigFake() *ScrapeConfig {
9397
return config
9498
}
9599

96-
func NewBookFromURL(url string, selector []string, name, author string, include, ImagesOnly, useLinkName, quiet bool, limit, offset, delay, threads int) book {
97-
config1 := NewScrapeConfig()
98-
config1.ImagesOnly = ImagesOnly
99-
config1.UseLinkName = useLinkName
100-
101-
var chapters []chapter
102-
var home chapter
103-
104-
if len(selector) > 0 {
105-
config2 := NewScrapeConfig()
106-
config2.Selector = selector[0]
107-
config2.Limit = limit
108-
config2.Offset = offset
109-
config2.Delay = delay
110-
config2.Threads = threads
111-
config2.Include = include
112-
config2.ImagesOnly = ImagesOnly
113-
config2.UseLinkName = useLinkName
114-
chapters, home = tableOfContent(url, config2, config1, quiet)
115-
} else {
116-
chapters = []chapter{NewChapterFromURL(url, "", []*ScrapeConfig{config1}, 0, func(index int, name string) {})}
117-
home = chapters[0]
118-
}
119-
120-
if len(name) == 0 {
121-
name = home.Name()
122-
}
123-
124-
if len(author) == 0 {
125-
author = home.Author()
126-
}
127-
128-
b := New(name, author)
129-
for _, c := range chapters {
130-
b.AddChapter(c)
131-
}
132-
133-
return b
134-
}
135-
136100
func NewChapterFromURL(url, linkName string, configs []*ScrapeConfig, index int, updateProgressBarName func(index int, name string)) chapter {
137101
config := configs[0]
138102

@@ -397,6 +361,8 @@ func GetLinks(url *urllib.URL, selector string, limit, offset int, reverse, incl
397361
parser := gofeed.NewParser()
398362
feed, err := parser.ParseURL(url.String())
399363

364+
fmt.Println(feed, url.String(), err)
365+
400366
if err == nil {
401367
// RSS feed
402368

book/scraper_test.go

Lines changed: 28 additions & 25 deletions
Large diffs are not rendered by default.

cmd/get.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ var getCmd = &cobra.Command{
132132
return nil
133133
},
134134
Run: func(cmd *cobra.Command, args []string) {
135-
url := args[0]
136135

137136
// generate config for each level
138137
configs := make([]*book.ScrapeConfig, len(getOpts.Selector))
@@ -162,7 +161,13 @@ var getCmd = &cobra.Command{
162161
configs[index] = config
163162
}
164163

165-
c := book.NewChapterFromURL(url, "", configs, 0, func(index int, name string) {})
164+
// dummy root chapter to contain all subchapters
165+
c := book.NewEmptyChapter()
166+
for _, u := range args {
167+
newChapter := book.NewChapterFromURL(u, "", configs, 0, func(index int, name string) {})
168+
c.AddSubChapter(newChapter)
169+
}
170+
c.SetName(c.SubChapters()[0].Name())
166171

167172
if getOpts.Format == "md" {
168173
filename := book.ToMarkdown(c, getOpts.output)

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ var versionCmd = &cobra.Command{
1414
Use: "version",
1515
Short: "Print the version number of papeer",
1616
Run: func(cmd *cobra.Command, args []string) {
17-
fmt.Println("papeer v0.5.6")
17+
fmt.Println("papeer v0.6.0")
1818
},
1919
}

0 commit comments

Comments
 (0)