Skip to content

Commit 540675f

Browse files
committed
reformat code
1 parent 5f2ea0d commit 540675f

File tree

10 files changed

+227
-234
lines changed

10 files changed

+227
-234
lines changed

internal/console/console.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ func Success(format string, a ...any) string {
2929
}
3030

3131
func Normal(format string, a ...any) string {
32-
white := color.New(color.FgWhite).SprintFunc()
33-
return white(fmt.Sprintf(format, a...))
32+
white := color.New(color.FgWhite).SprintFunc()
33+
return white(fmt.Sprintf(format, a...))
3434
}

internal/document_parser/current_document.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ func NewCurrentDocumentParserFromReader(r io.Reader) *CurrentDocumentParser {
2424
}
2525

2626
func findTitle(selection *goquery.Selection) string {
27-
var title string
28-
selection.Find("a").EachWithBreak(func(v int, s *goquery.Selection) bool {
29-
if s.Text() != "" && len(s.Text()) > 1 {
30-
title = s.Text()
31-
// Break out of the loop
32-
return false
33-
}
34-
return true
35-
})
36-
37-
return title
27+
var title string
28+
selection.Find("a").EachWithBreak(func(v int, s *goquery.Selection) bool {
29+
if s.Text() != "" && len(s.Text()) > 1 {
30+
title = s.Text()
31+
// Break out of the loop
32+
return false
33+
}
34+
return true
35+
})
36+
37+
return title
3838
}
3939

4040
func (cdp *CurrentDocumentParser) GetBookDataFromDocument() []book.Book {
@@ -82,7 +82,7 @@ func (cdp *CurrentDocumentParser) GetBookDataFromDocument() []book.Book {
8282
}
8383

8484
func (cdp *CurrentDocumentParser) getDownloadLinkFromDocument() (string, bool) {
85-
return cdp.doc.Find("#main a").First().Attr("href")
85+
return cdp.doc.Find("#main a").First().Attr("href")
8686
}
8787

8888
func (cdp *CurrentDocumentParser) getBookTitleFromSelection(selection *goquery.Selection) string {
@@ -103,8 +103,8 @@ func (cdp *CurrentDocumentParser) getBookTitleFromSelection(selection *goquery.S
103103
func (cdp *CurrentDocumentParser) GetDirectDownloadLink(selectedBook book.Book) string {
104104
fmt.Println("Obtaining direct download link")
105105

106-
// TODO Implement retry?
107-
link := selectedBook.Mirrors[0]
106+
// TODO Implement retry?
107+
link := selectedBook.Mirrors[0]
108108

109109
resp, err := http.Get(link)
110110
defer func(Body io.ReadCloser) {

internal/document_parser/document_parser.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
// }
1010

1111
type DocumentParser interface {
12-
GetBookDataFromDocument() []book.Book
13-
GetDownloadLinkFromDocument() (string, bool)
12+
GetBookDataFromDocument() []book.Book
13+
GetDownloadLinkFromDocument() (string, bool)
1414
}
15-

internal/document_parser/legacy_document.go

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import (
1111
)
1212

1313
type LegacyDocumentParser struct {
14-
doc *goquery.Document
14+
doc *goquery.Document
1515
}
1616

1717
func NewLegacyDocumentParser(document *goquery.Document) *LegacyDocumentParser {
1818
return &LegacyDocumentParser{doc: document}
1919
}
2020

2121
func NewLegacyDocumentParserFromReader(r io.Reader) *LegacyDocumentParser {
22-
document, _ := goquery.NewDocumentFromReader(r)
23-
return &LegacyDocumentParser{doc: document}
22+
document, _ := goquery.NewDocumentFromReader(r)
23+
return &LegacyDocumentParser{doc: document}
2424
}
2525

2626
func (ldp *LegacyDocumentParser) GetBookDataFromDocument() []book.Book {
@@ -48,7 +48,7 @@ func (ldp *LegacyDocumentParser) GetBookDataFromDocument() []book.Book {
4848
case 9, 10, 11:
4949
href, hrefExists := columnSelection.Find("a").Attr("href")
5050
if hrefExists {
51-
mirrors = append(mirrors, href)
51+
mirrors = append(mirrors, href)
5252
}
5353
}
5454
})
@@ -68,12 +68,10 @@ func (ldp *LegacyDocumentParser) GetBookDataFromDocument() []book.Book {
6868
return books
6969
}
7070

71-
72-
func (ldp *LegacyDocumentParser) getDownloadLinkFromDocument() (string, bool){
73-
return ldp.doc.Find("#download > ul > li > a").First().Attr("href")
71+
func (ldp *LegacyDocumentParser) getDownloadLinkFromDocument() (string, bool) {
72+
return ldp.doc.Find("#download > ul > li > a").First().Attr("href")
7473
}
7574

76-
7775
func getBookTitleFromSelection(selection *goquery.Selection) string {
7876
var title string
7977
selection.Find("a").Each(func(v int, s *goquery.Selection) {
@@ -89,7 +87,6 @@ func getBookTitleFromSelection(selection *goquery.Selection) string {
8987
return title
9088
}
9189

92-
9390
func GetDirectDownloadLinkFromLegacy(link string) string {
9491
fmt.Println("Obtaining direct download link")
9592
resp, err := http.Get(link)
@@ -105,17 +102,17 @@ func GetDirectDownloadLinkFromLegacy(link string) string {
105102
fmt.Println("Error getting response:", err)
106103
}
107104

108-
page := NewLegacyDocumentParserFromReader(resp.Body)
109-
// TODO: I think this can be improved
110-
directDownloadLink, exists := page.getDownloadLinkFromDocument()
105+
page := NewLegacyDocumentParserFromReader(resp.Body)
106+
// TODO: I think this can be improved
107+
directDownloadLink, exists := page.getDownloadLinkFromDocument()
108+
109+
fmt.Println("Direct download link:", directDownloadLink)
111110

112-
fmt.Println("Direct download link:", directDownloadLink)
111+
if exists {
112+
return directDownloadLink
113+
}
113114

114-
if exists {
115-
return directDownloadLink
116-
}
117-
118-
return ""
115+
return ""
119116
}
120117

121118
func GetDirectDownloadLinkFromCurrent(link string) string {
@@ -133,17 +130,15 @@ func GetDirectDownloadLinkFromCurrent(link string) string {
133130
fmt.Println("Error getting response:", err)
134131
}
135132

136-
page := NewCurrentDocumentParserFromReader(resp.Body)
137-
// TODO: I think this can be improved
138-
directDownloadLink, exists := page.getDownloadLinkFromDocument()
139-
140-
fmt.Println("Direct download link:", directDownloadLink)
133+
page := NewCurrentDocumentParserFromReader(resp.Body)
134+
// TODO: I think this can be improved
135+
directDownloadLink, exists := page.getDownloadLinkFromDocument()
141136

142-
if exists {
143-
return directDownloadLink
144-
}
145-
146-
return ""
147-
}
137+
fmt.Println("Direct download link:", directDownloadLink)
148138

139+
if exists {
140+
return directDownloadLink
141+
}
149142

143+
return ""
144+
}

internal/downloader/downloader.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,23 @@ import (
1515
)
1616

1717
type Downloader struct {
18-
selectedBook book.Book
19-
directLink string
20-
outputFileDir string
18+
selectedBook book.Book
19+
directLink string
20+
outputFileDir string
2121
}
2222

2323
func NewDownloader(selectedBook book.Book, directLink string, outputFileDir string) *Downloader {
24-
return &Downloader{
25-
selectedBook: selectedBook,
26-
directLink: directLink,
27-
outputFileDir: outputFileDir,
28-
}
24+
return &Downloader{
25+
selectedBook: selectedBook,
26+
directLink: directLink,
27+
outputFileDir: outputFileDir,
28+
}
2929
}
3030

3131
func (d *Downloader) Download() error {
3232
fmt.Println(console.Info("Initializing download "))
3333

34-
// TODO: implement retry
34+
// TODO: implement retry
3535
req, _ := http.NewRequest("GET", d.directLink, nil)
3636
resp, error := http.DefaultClient.Do(req)
3737

@@ -41,9 +41,9 @@ func (d *Downloader) Download() error {
4141

4242
defer resp.Body.Close()
4343
filename := sanitize.Path(strings.Trim(d.selectedBook.Title, " ") + "." + d.selectedBook.Extension)
44-
filename = filepath.Clean(d.outputFileDir + "/" + filename)
44+
filename = filepath.Clean(d.outputFileDir + "/" + filename)
4545

46-
fmt.Println("Downloading to: ", filename)
46+
fmt.Println("Downloading to: ", filename)
4747

4848
f, _ := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0666)
4949
defer f.Close()
@@ -61,5 +61,5 @@ func (d *Downloader) Download() error {
6161
fmt.Println(console.Success("File successfully downloaded: %s", f.Name()))
6262
}
6363

64-
return err
64+
return err
6565
}

internal/libgen/libgen.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
package libgen
22

33
type Domain string
4+
45
const (
5-
RS = "rs"
6-
IS = "is"
7-
ST = "st"
6+
RS = "rs"
7+
IS = "is"
8+
ST = "st"
89

9-
LI = "li"
10-
LC = "lc"
11-
GS = "gs"
12-
TOP = "top"
13-
CLICK = "click"
10+
LI = "li"
11+
LC = "lc"
12+
GS = "gs"
13+
TOP = "top"
14+
CLICK = "click"
1415
)
1516

1617
type Filter string
18+
1719
const (
18-
TITLE = "title"
19-
AUTHOR = "author"
20-
SERIES = "series"
21-
PUBLISHER = "publisher"
22-
YEAR = "year"
23-
ISBN = "isbn"
24-
MD5 = "md5"
25-
TAGS = "tags"
26-
EXTENSION = "extension"
20+
TITLE = "title"
21+
AUTHOR = "author"
22+
SERIES = "series"
23+
PUBLISHER = "publisher"
24+
YEAR = "year"
25+
ISBN = "isbn"
26+
MD5 = "md5"
27+
TAGS = "tags"
28+
EXTENSION = "extension"
2729
)
28-

0 commit comments

Comments
 (0)