Skip to content

Commit

Permalink
commit sa bqrq
Browse files Browse the repository at this point in the history
  • Loading branch information
laureanray committed Jun 29, 2023
1 parent 9ff5698 commit 0ff9bc9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func getExtension(s string) string {

var (
selectedSite string
selectedFilter string
numberOfResults = 10

searchCmd = &cobra.Command{
Expand Down Expand Up @@ -100,6 +101,15 @@ func init() {
"new"
`)

searchCmd.
PersistentFlags().
StringVarP(&selectedFilter, "filter", "f", "title", `select which filter to use
options:
"title"
"author"
"isbn"
`)

searchCmd.
PersistentFlags().
IntVarP(&numberOfResults, "number of results", "n", 10, `number of result(s) to be displayed maximum: 25`)
Expand Down
4 changes: 4 additions & 0 deletions internal/mirror/current_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (m *CurrentMirror) SearchByTitle(query string) ([]book.Book, error) {
return bookResults, err
}

func (m *CurrentMirror) SearchByAuthor(query string) ([]book.Book, error) {
return nil, nil
}


// Search the libgen site returns the document
// of the search results page
Expand Down
20 changes: 20 additions & 0 deletions internal/mirror/legacy_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ func (m *LegacyMirror) SearchByTitle(query string) ([]book.Book, error) {
return bookResults, err
}

func (m *LegacyMirror) SearchByAuthor(query string) ([]book.Book, error) {
fmt.Println("Searching by author: %s", console.Higlight(query))

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

if err != nil {
fmt.Println(console.Error("Error searching for book: %s", query))
}

bookResults :=
documentparser.NewLegacyDocumentParser(document).GetBookDataFromDocument()

if len(bookResults) >= m.config.numberOfResults {
bookResults = bookResults[:m.config.numberOfResults]
}

return bookResults, err
}

// Search the libgen site returns the document
// of the search results page
func (m *LegacyMirror) searchSite(query string) (*goquery.Document, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/mirror/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type Mirror interface {
SearchByTitle(query string) ([]book.Book, error)
// SearchByAuthor(author string) []book.Book
SearchByAuthor(author string) ([]book.Book, error)
// SearchByISBN(isbn string) []book.Book
// 1GetDownloadLink(book book.Book) string
DownloadSelection(book book.Book)
Expand Down

0 comments on commit 0ff9bc9

Please sign in to comment.