diff --git a/README.md b/README.md index 4652fa9..f93fb3f 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/go.mod b/go.mod index 0454652..5c0883e 100644 --- a/go.mod +++ b/go.mod @@ -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 ( @@ -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 ) diff --git a/grabber/mangadex.go b/grabber/mangadex.go index 7270a2e..bc198ab 100644 --- a/grabber/mangadex.go +++ b/grabber/mangadex.go @@ -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") diff --git a/grabber/manganelo.go b/grabber/manganelo.go index 7ee5a30..05f4210 100644 --- a/grabber/manganelo.go +++ b/grabber/manganelo.go @@ -1,6 +1,7 @@ package grabber import ( + "fmt" "regexp" "strconv" "strings" @@ -8,6 +9,7 @@ import ( "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 @@ -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 @@ -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 @@ -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 diff --git a/makefile b/makefile index ba23af9..7747633 100644 --- a/makefile +++ b/makefile @@ -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