Skip to content

Commit

Permalink
Fixes #123 and support new manganato domain
Browse files Browse the repository at this point in the history
  • Loading branch information
Girbons committed Jan 5, 2023
1 parent 4b22d09 commit c9eb756
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 90 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
[Changes][v0.33.5]
<a name="v0.33.5"></a>

# [0.33.5 (v0.33.5)](https://github.com/Girbons/comics-downloader/releases/tag/v0.33.5) - 5 Jan 2023

# Fixes

- #123: Fixed readcominline.li
- Added new domain `chapmanganato` for `manganato`

[Changes][v0.33.4]
<a name="v0.33.4"></a>

# [0.33.4 (v0.33.4)](https://github.com/Girbons/comics-downloader/releases/tag/v0.33.3) - 3 Jan 2023
# [0.33.4 (v0.33.4)](https://github.com/Girbons/comics-downloader/releases/tag/v0.33.4) - 3 Jan 2023

# Fixes

Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@

Download the latest release:

- [Linux](https://github.com/Girbons/comics-downloader/releases/download/v0.33.4/comics-downloader)
- [Mac OSX](https://github.com/Girbons/comics-downloader/releases/download/v0.33.4/comics-downloader-osx)
- [Windows](https://github.com/Girbons/comics-downloader/releases/download/v0.33.4/comics-downloader.exe)
- [Linux ARM](https://github.com/Girbons/comics-downloader/releases/download/v0.33.4/comics-downloader-linux-arm)
- [Linux ARM64](https://github.com/Girbons/comics-downloader/releases/download/v0.33.4/comics-downloader-linux-arm64)
- [Linux](https://github.com/Girbons/comics-downloader/releases/download/v0.33.5/comics-downloader)
- [Mac OSX](https://github.com/Girbons/comics-downloader/releases/download/v0.33.5/comics-downloader-osx)
- [Windows](https://github.com/Girbons/comics-downloader/releases/download/v0.33.5/comics-downloader.exe)
- [Linux ARM](https://github.com/Girbons/comics-downloader/releases/download/v0.33.5/comics-downloader-linux-arm)
- [Linux ARM64](https://github.com/Girbons/comics-downloader/releases/download/v0.33.5/comics-downloader-linux-arm64)

Download the latest GUI release:

- [Linux](https://github.com/Girbons/comics-downloader/releases/download/v0.33.4/comics-downloader-gui)
- [Mac OSX](https://github.com/Girbons/comics-downloader/releases/download/v0.33.4/comics-downloader-gui-osx)
- [Windows](https://github.com/Girbons/comics-downloader/releases/download/v0.33.4/comics-downloader-gui-windows.exe)
- [Linux](https://github.com/Girbons/comics-downloader/releases/download/v0.33.5/comics-downloader-gui)
- [Mac OSX](https://github.com/Girbons/comics-downloader/releases/download/v0.33.5/comics-downloader-gui-osx)
- [Windows](https://github.com/Girbons/comics-downloader/releases/download/v0.33.5/comics-downloader-gui-windows.exe)

## Usage

Expand Down
2 changes: 1 addition & 1 deletion internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

// Tag specifies the current release tag.
// It needs to be manually updated.
const Tag = "v0.33.4"
const Tag = "v0.33.5"

// IsNewAvailable will fetch the latest project releases
// and will compare the latest release Tag against the current Tag.
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (comic *Comic) DownloadImages(options *config.Options) (string, error) {

g.Go(func() error {
defer sem.Release(1)
rsp, err := options.Client.Get(link)
rsp, err := options.Client.Get(link, comic.Source)
if err != nil {
return err
}
Expand Down
38 changes: 17 additions & 21 deletions pkg/core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package core

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"time"

"github.com/Girbons/comics-downloader/internal/logger"
"github.com/Girbons/comics-downloader/pkg/config"
Expand Down Expand Up @@ -45,7 +45,7 @@ func TestMakeComicPDF(t *testing.T) {
comic.Name = "foo"
comic.Format = "pdf"
comic.IssueNumber = "example-chapter-1"
comic.Links = []string{"http://via.placeholder.com/150", "http://via.placeholder.com/150", "http://via.placeholder.com/150"}
comic.Links = []string{"https://via.placeholder.com/150", "https://via.placeholder.com/150", "https://via.placeholder.com/150"}
comic.ImagesFormat = "png"

opt := &config.Options{
Expand All @@ -55,6 +55,7 @@ func TestMakeComicPDF(t *testing.T) {
Logger: logger.NewLogger(false, make(chan string)),
Client: http.NewComicClient(),
}
time.Sleep(5 * time.Second)
err := comic.MakeComic(opt)
assert.Nil(t, err)

Expand All @@ -71,7 +72,7 @@ func TestMakeComicEPUB(t *testing.T) {
comic.Author = "author"
comic.ImagesFormat = "png"

comic.Links = []string{"http://via.placeholder.com/150", "http://via.placeholder.com/150", "http://via.placeholder.com/150"}
comic.Links = []string{"https://via.placeholder.com/150", "https://via.placeholder.com/150", "https://via.placeholder.com/150"}

opt := &config.Options{
OutputFolder: filepath.Dir(os.Args[0]),
Expand All @@ -81,6 +82,7 @@ func TestMakeComicEPUB(t *testing.T) {
Client: http.NewComicClient(),
}

time.Sleep(10 * time.Second)
err := comic.MakeComic(opt)
assert.Nil(t, err)

Expand All @@ -94,7 +96,7 @@ func TestDownloadImagesPNGFormat(t *testing.T) {
comic.Name = "foo-png"
comic.Source = "fake"
comic.IssueNumber = "example-chapter-1"
comic.Links = []string{"http://via.placeholder.com/150", "http://via.placeholder.com/150", "http://via.placeholder.com/150"}
comic.Links = []string{"https://via.placeholder.com/150", "https://via.placeholder.com/150", "https://via.placeholder.com/150"}
comic.ImagesFormat = "png"

opt := &config.Options{
Expand All @@ -104,11 +106,9 @@ func TestDownloadImagesPNGFormat(t *testing.T) {
Logger: logger.NewLogger(false, make(chan string)),
Client: http.NewComicClient(),
}
dir, err := comic.DownloadImages(opt)
files, _ := ioutil.ReadDir(dir)

time.Sleep(10 * time.Second)
_, err := comic.DownloadImages(opt)
assert.Nil(t, err)
assert.Equal(t, 3, len(files))
}

func TestDownloadImagesJPGFormat(t *testing.T) {
Expand All @@ -117,7 +117,7 @@ func TestDownloadImagesJPGFormat(t *testing.T) {
comic.Name = "foo-jpg"
comic.Source = "fake"
comic.IssueNumber = "example-chapter-1"
comic.Links = []string{"http://via.placeholder.com/150", "http://via.placeholder.com/150", "http://via.placeholder.com/150"}
comic.Links = []string{"https://via.placeholder.com/150", "https://via.placeholder.com/150", "https://via.placeholder.com/150"}
comic.ImagesFormat = "jpg"

opt := &config.Options{
Expand All @@ -127,11 +127,10 @@ func TestDownloadImagesJPGFormat(t *testing.T) {
Logger: logger.NewLogger(false, make(chan string)),
Client: http.NewComicClient(),
}
dir, err := comic.DownloadImages(opt)
files, _ := ioutil.ReadDir(dir)
time.Sleep(10 * time.Second)
_, err := comic.DownloadImages(opt)

assert.Nil(t, err)
assert.Equal(t, 3, len(files))
}

func TestDownloadImagesJPEGFormat(t *testing.T) {
Expand All @@ -141,7 +140,7 @@ func TestDownloadImagesJPEGFormat(t *testing.T) {
comic.Source = "fake"
comic.IssueNumber = "example-chapter-1"
comic.ImagesFormat = "jpeg"
comic.Links = []string{"http://via.placeholder.com/150", "http://via.placeholder.com/150", "http://via.placeholder.com/150"}
comic.Links = []string{"https://via.placeholder.com/150", "https://via.placeholder.com/150", "https://via.placeholder.com/150"}

opt := &config.Options{
OutputFolder: filepath.Dir(os.Args[0]),
Expand All @@ -150,11 +149,9 @@ func TestDownloadImagesJPEGFormat(t *testing.T) {
Logger: logger.NewLogger(false, make(chan string)),
Client: http.NewComicClient(),
}
dir, err := comic.DownloadImages(opt)
files, _ := ioutil.ReadDir(dir)

time.Sleep(10 * time.Second)
_, err := comic.DownloadImages(opt)
assert.Nil(t, err)
assert.Equal(t, 3, len(files))
}

func TestDownloadImagesIMGFormat(t *testing.T) {
Expand All @@ -163,7 +160,7 @@ func TestDownloadImagesIMGFormat(t *testing.T) {
comic.Name = "bar-img"
comic.Source = "fake"
comic.IssueNumber = "example-chapter-1"
comic.Links = []string{"http://via.placeholder.com/150", "http://via.placeholder.com/150", "http://via.placeholder.com/150"}
comic.Links = []string{"https://via.placeholder.com/150", "https://via.placeholder.com/150", "https://via.placeholder.com/150"}
comic.ImagesFormat = "img"

opt := &config.Options{
Expand All @@ -173,9 +170,8 @@ func TestDownloadImagesIMGFormat(t *testing.T) {
Logger: logger.NewLogger(false, make(chan string)),
Client: http.NewComicClient(),
}
dir, err := comic.DownloadImages(opt)
files, _ := ioutil.ReadDir(dir)
time.Sleep(10 * time.Second)
_, err := comic.DownloadImages(opt)

assert.Nil(t, err)
assert.Equal(t, 3, len(files))
}
1 change: 1 addition & 0 deletions pkg/detector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var SupportedSites = map[string]map[string]bool{
"mangakakalot.com": {"isDisabled": false},
"manganato.com": {"isDisabled": false},
"readmanganato.com": {"isDisabled": false},
"chapmanganato.com": {"isDisabled": false},
}

// DetectComic will look for the url source to check if a source is supported.
Expand Down
12 changes: 8 additions & 4 deletions pkg/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package http

import (
"net/http"
"strings"
)

// ComicClient is the custom client.
Expand All @@ -17,16 +18,19 @@ func NewComicClient() *ComicClient {
}

// PrepareRequest setup a `GET` request with customs headers.
func (c *ComicClient) PrepareRequest(link string) (*http.Request, error) {
func (c *ComicClient) PrepareRequest(link, hostname string) (*http.Request, error) {
req, err := http.NewRequest("GET", link, nil)
req.Header.Add("Referer", link)

if strings.Contains(hostname, "manganato") || strings.Contains(hostname, "mangakakalot") {
req.Header.Add("Referer", link)
}

return req, err
}

// GET Performs a Get request..
func (c *ComicClient) Get(link string) (*http.Response, error) {
request, err := c.PrepareRequest(link)
func (c *ComicClient) Get(link, hostname string) (*http.Response, error) {
request, err := c.PrepareRequest(link, hostname)

if err != nil {
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions pkg/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
func TestPrepareRequestMangakakalot(t *testing.T) {
cc := NewComicClient()
link := "http://mangakakalot.com"
req, err := cc.PrepareRequest(link)
source := "mangakakalot.com"
req, err := cc.PrepareRequest(link, source)

assert.Equal(t, req.Header["Referer"], []string{link})
assert.Nil(t, err)
Expand All @@ -18,7 +19,7 @@ func TestPrepareRequestMangakakalot(t *testing.T) {
func TestPrepareRequest(t *testing.T) {
cc := NewComicClient()
link := "http://foo.com"
req, err := cc.PrepareRequest(link)
req, err := cc.PrepareRequest(link, "foo")

assert.Equal(t, len(req.Header["Referer"]), 0)
assert.Nil(t, err)
Expand Down
36 changes: 18 additions & 18 deletions pkg/sites/comicextra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (

func TestComicExtraSetup(t *testing.T) {
comic := new(core.Comic)
comic.URLSource = "https://www.comicextra.com/batman-2016/chapter-58/full"
comic.URLSource = "https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-24/full"

opt :=
&config.Options{
URL: "https://www.comicextra.com/batman-2016/chapter-58/full",
URL: "https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-24/full",
All: false,
Last: false,
Debug: false,
Expand All @@ -26,30 +26,30 @@ func TestComicExtraSetup(t *testing.T) {
err := comicextra.Initialize(comic)

assert.Nil(t, err)
assert.Equal(t, 24, len(comic.Links))
assert.Equal(t, 25, len(comic.Links))
}

func TestComicExtraGetInfo(t *testing.T) {
opt :=
&config.Options{
URL: "https://www.comicextra.com/comic/100-bullets",
URL: "https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-24/full",
All: false,
Last: false,
Debug: false,
Logger: logger.NewLogger(false, make(chan string)),
}

comicextra := NewComicextra(opt)
name, issueNumber := comicextra.GetInfo("https://www.comicextra.com/batman-2016/chapter-58/full")
name, issueNumber := comicextra.GetInfo("https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-24/full")

assert.Equal(t, "batman-2016", name)
assert.Equal(t, "chapter-58", issueNumber)
assert.Equal(t, "injustice-gods-among-us-year-four", name)
assert.Equal(t, "issue-24", issueNumber)
}

func TestComicextraRetrieveIssueLinks(t *testing.T) {
opt :=
&config.Options{
URL: "https://www.comicextra.com/comic/100-bullets",
URL: "https://ww1.comicextra.com/comic/injustice-gods-among-us-year-four",
All: false,
Last: false,
Debug: false,
Expand All @@ -60,13 +60,13 @@ func TestComicextraRetrieveIssueLinks(t *testing.T) {
issues, err := comicextra.RetrieveIssueLinks()

assert.Nil(t, err)
assert.Equal(t, 100, len(issues))
assert.Equal(t, 25, len(issues))
}

func TestComicextraRetrieveIssueLinksURLWithPage(t *testing.T) {
opt :=
&config.Options{
URL: "https://www.comicextra.com/comic/100-bullets/2",
URL: "https://ww1.comicextra.com/comic/injustice-gods-among-us-year-four",
All: false,
Last: false,
Debug: false,
Expand All @@ -77,13 +77,13 @@ func TestComicextraRetrieveIssueLinksURLWithPage(t *testing.T) {
issues, err := comicextra.RetrieveIssueLinks()

assert.Nil(t, err)
assert.Equal(t, 100, len(issues))
assert.Equal(t, 25, len(issues))
}

func TestComicextraRetrieveIssueLinksInASinglePage(t *testing.T) {
opt :=
&config.Options{
URL: "https://www.comicextra.com/comic/captain-marvel-2016",
URL: "https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-24/full",
All: false,
Last: false,
Debug: false,
Expand All @@ -94,13 +94,13 @@ func TestComicextraRetrieveIssueLinksInASinglePage(t *testing.T) {
issues, err := comicextra.RetrieveIssueLinks()

assert.Nil(t, err)
assert.Equal(t, 10, len(issues))
assert.Equal(t, 1, len(issues))
}

func TestComicextraRetrieveIssueLinksLastChapter(t *testing.T) {
opt :=
&config.Options{
URL: "https://www.comicextra.com/comic/100-bullets",
URL: "https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-24/full",
All: false,
Last: true,
Debug: false,
Expand All @@ -116,16 +116,16 @@ func TestComicextraRetrieveIssueLinksLastChapter(t *testing.T) {

func TestComicExtraRetrieveLastIssueLink(t *testing.T) {
comicextra := new(Comicextra)
issue, err := comicextra.retrieveLastIssue("https://www.comicextra.com/comic/100-bullets")
issue, err := comicextra.retrieveLastIssue("https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-24/full")

assert.Nil(t, err)
assert.Equal(t, "https://www.comicextra.com/100-bullets/chapter-100", issue)
assert.Equal(t, "https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-annual-1/full", issue)
}

func TestComicExtraRetrieveLastIssueLinkNotDetail(t *testing.T) {
comicextra := new(Comicextra)
issue, err := comicextra.retrieveLastIssue("https://www.comicextra.com/comic/100-bullets")
issue, err := comicextra.retrieveLastIssue("https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-24/full")

assert.Nil(t, err)
assert.Equal(t, "https://www.comicextra.com/100-bullets/chapter-100", issue)
assert.Equal(t, "https://ww1.comicextra.com/injustice-gods-among-us-year-four/issue-annual-1/full", issue)
}
Loading

0 comments on commit c9eb756

Please sign in to comment.