Skip to content

Commit

Permalink
Added mangajar.com support (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
elboletaire authored Jan 18, 2023
1 parent 56da83a commit 3534df4
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Supported sites

- [Inmanga](https://inmanga.com)
- [LeviatanScans](https://leviatanscans.com)
- [MangaBat](https://readmangabat.com)
- [Mangadex](https://mangadex.org)
- [MangaJar](https://mangajar.com)
- [Manganato](https://manganato.com) (aka manganelo.com)
- [Mangakakalot](https://mangakakalot.com)
- [Manganelo.tv](https://ww5.manganelo.tv)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/manifoldco/promptui v0.9.0
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
golang.org/x/net v0.4.0
)

require (
Expand All @@ -17,6 +18,5 @@ require (
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
)
6 changes: 1 addition & 5 deletions grabber/mangadex.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ func (m Mangadex) FetchChapters() (chapters Filterables, errs []error) {
var fetchChaps func(int)

fetchChaps = func(offset int) {
uri, err := url.JoinPath("https://api.mangadex.org", "manga", id, "feed")
if err != nil {
errs = append(errs, err)
return
}
uri := fmt.Sprintf("https://api.mangadex.org/manga/%s/feed", id)
params := url.Values{}
params.Add("limit", fmt.Sprint(baseOffset))
params.Add("order[volume]", "asc")
Expand Down
60 changes: 57 additions & 3 deletions grabber/manganelo.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package grabber

import (
"fmt"
"regexp"
"strconv"
"strings"

"github.com/PuerkitoBio/goquery"
"github.com/elboletaire/manga-downloader/http"
"github.com/fatih/color"
"golang.org/x/net/html"
)

// Manganelo is a grabber for manganelo and similar pages
Expand Down Expand Up @@ -44,6 +46,47 @@ func (m *Manganelo) Test() (bool, error) {
"#examples div.chapter-list .row",
// mangakakalot style
"div.chapter-list .row",
// mangajar style (required when there are no more pages)
"article.chaptersList li.chapter-item",
}

// mangajar has ajax pagination
if m.doc.Find(".chapters-infinite-pagination .pagination .page-item").Length() > 0 {
var err error
var fetchChaps func(page int)
rows := &goquery.Selection{
Nodes: []*html.Node{},
}

fetchChaps = func(page int) {
rbody, err := http.Get(http.RequestParams{
URL: fmt.Sprintf("%s/chaptersList?page=%d", m.URL, page),
})
if err != nil {
return
}
defer rbody.Close()

doc, err := goquery.NewDocumentFromReader(rbody)
if err != nil {
return
}

rows = rows.AddNodes(doc.Find(".chapter-list-container .chapter-item").Nodes...)

if doc.Find("ul.pagination .page-item:not(.disabled):last-child").Length() > 0 {
fetchChaps(page + 1)
}
}

fetchChaps(1)
if err != nil {
return false, err
}

m.rows = rows

return m.rows.Length() > 0, nil
}

// for the same priority reasons, we need to iterate over the selectors
Expand All @@ -65,7 +108,14 @@ func (m *Manganelo) Test() (bool, error) {

// Ttitle returns the manga title
func (m Manganelo) FetchTitle() (string, error) {
return m.doc.Find("h1").Text(), nil
title := m.doc.Find("h1")

// mangajar has the name inside span.post-name
if title.Children().HasClass("post-name") {
title = title.Find(".post-name")
}

return title.Text(), nil
}

// FetchChapters returns a slice of chapters
Expand Down Expand Up @@ -147,10 +197,14 @@ func getImageUrls(doc *goquery.Document) []string {
}

// others just have the images
pimages = doc.Find("div.container-chapter-reader img")
pimages = doc.Find("div.container-chapter-reader img, .chapter-images img")
imgs := []string{}
pimages.Each(func(i int, s *goquery.Selection) {
imgs = append(imgs, s.AttrOr("src", s.AttrOr("data-src", "")))
src := s.AttrOr("src", "")
if src == "" || strings.HasPrefix(src, "data:image") {
src = s.AttrOr("data-src", "")
}
imgs = append(imgs, src)
})

return imgs
Expand Down
2 changes: 2 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ grabber/manganelo:
go run . https://ww5.manganelo.tv/manga/manga-aa951409 3
go run . http://manganelos.com/manga/dont-pick-up-what-youve-thrown-away 10-12 --bundle
go run . https://chapmanganato.com/manga-aa951409 50
go run . https://h.mangabat.com/read-tc397521 5
go run . https://mangajar.com/manga/chainsaw-man-absTop-abs3bof 23

grabber/inmanga:
go run . https://inmanga.com/ver/manga/One-Piece/dfc7ecb5-e9b3-4aa5-a61b-a498993cd935 1
Expand Down

0 comments on commit 3534df4

Please sign in to comment.