Skip to content

Commit

Permalink
implement search by author for current and legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
laureanray committed Jun 29, 2023
1 parent 0ff9bc9 commit 611cae0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
11 changes: 9 additions & 2 deletions cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/fatih/color"
"github.com/laureanray/clibgen/internal/book"
"github.com/laureanray/clibgen/internal/libgen"
"github.com/laureanray/clibgen/internal/mirror"
"github.com/manifoldco/promptui"
Expand Down Expand Up @@ -61,8 +62,14 @@ var (
return
}


books, _ := m.SearchByTitle(args[0])
var books []book.Book

switch (selectedFilter) {
case libgen.AUTHOR:
books, _ = m.SearchByAuthor(args[0])
default:
books, _ = m.SearchByTitle(args[0])
}

var titles []string

Expand Down
29 changes: 26 additions & 3 deletions internal/mirror/current_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,28 @@ func (m *CurrentMirror) SearchByTitle(query string) ([]book.Book, error) {
}

func (m *CurrentMirror) SearchByAuthor(query string) ([]book.Book, error) {
return nil, nil
fmt.Println("Searching for: ", console.Higlight(query))
var document *goquery.Document

m.filter = libgen.AUTHOR
document, err := m.searchSite(query)

if err != nil {
fmt.Println(console.Error("Error searching for book: %s", query))
// TODO: Implement retrying
// fmt.Println(infoColor("Retrying with other site"))
// document, e = searchLibgen(query, siteToUse) // If this also fails then we have a problem
}
fmt.Println(console.Success("Search complete, parsing the document..."))

page := documentparser.NewCurrentDocumentParser(document)
bookResults := page.GetBookDataFromDocument()

// if len(bookResults) >= limit {
// bookResults = bookResults[:limit]
// }

return bookResults, err
}


Expand All @@ -67,12 +88,14 @@ func (m *CurrentMirror) searchSite(query string) (*goquery.Document, error) {
baseUrl := fmt.Sprintf("https://libgen.%s/index.php", m.domain)

queryString := fmt.Sprintf(
"%s?req=%s",
"%s?req=\"%s\"",
baseUrl,
url.QueryEscape(query),
)

reqString:= queryString + "&columns%5B%5D=t&columns%5B%5D=a&columns%5B%5D=s&columns%5B%5D=y&columns%5B%5D=p&columns%5B%5D=i&objects%5B%5D=f&objects%5B%5D=e&objects%5B%5D=s&objects%5B%5D=a&objects%5B%5D=p&objects%5B%5D=w&topics%5B%5D=l&topics%5B%5D=f&topics%5B%5D=r&res=25&filesuns=all"
filter := string(string(m.filter)[0])

reqString:= queryString + "&columns%5B%5D=" + filter + "&objects%5B%5D=f&objects%5B%5D=e&objects%5B%5D=s&objects%5B%5D=a&objects%5B%5D=p&objects%5B%5D=w&topics%5B%5D=l&topics%5B%5D=c&topics%5B%5D=f&res=25&gmode=on&filesuns=all"

fmt.Println(reqString)

Expand Down

0 comments on commit 611cae0

Please sign in to comment.