From 9e90770e83c11cd700f7fbe20cafab705cd2f1a6 Mon Sep 17 00:00:00 2001 From: turtletowerz Date: Fri, 17 Jan 2020 03:25:52 -0500 Subject: [PATCH] Mangadex URL fixes (#49) * Support mangadex.cc and mangadex.org This update re-adds support for "mangadex.org", and maintains support for the previous URL "mangadex.cc" * Mangadex testing fixes --- README.md | 2 +- pkg/sites/base.go | 1 + pkg/sites/loader.go | 4 ++-- pkg/sites/mangadex.go | 9 ++++++--- pkg/sites/mangadex_test.go | 39 ++++++++++++++++++++------------------ 5 files changed, 31 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index da93cf9f..9a14051c 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ You can invoke the `--help`: |https://www.mangareader.net/ |✓|✗|✓| |http://www.mangatown.com/ |✓|✗|✓| |https://mangadex.cc/ |✓|✓|✓| - +|https://mangadex.org/ |✓|✓|✓| ### Checking for mangas using a Raspberry Pi diff --git a/pkg/sites/base.go b/pkg/sites/base.go index 1e1fefba..f9e1bb61 100644 --- a/pkg/sites/base.go +++ b/pkg/sites/base.go @@ -9,6 +9,7 @@ var SupportedSites = []string{ "www.mangatown.com", "www.mangahere.cc", "mangadex.cc", + "mangadex.org", } // DisabledSites are the sites that are currently disabled. diff --git a/pkg/sites/loader.go b/pkg/sites/loader.go index e2b576c7..cc47e18e 100644 --- a/pkg/sites/loader.go +++ b/pkg/sites/loader.go @@ -57,8 +57,8 @@ func LoadComicFromSource(source, url, country, format, imagesFormat string, all, siteSource = &Mangareader{} case "www.mangatown.com": siteSource = &Mangatown{} - case "mangadex.cc": - siteSource = NewMangadex(country) + case "mangadex.cc", "mangadex.org": + siteSource = NewMangadex(country, source) default: err = fmt.Errorf("It was not possible to determine the source") return collection, err diff --git a/pkg/sites/mangadex.go b/pkg/sites/mangadex.go index 9f7b2d78..164cdde3 100644 --- a/pkg/sites/mangadex.go +++ b/pkg/sites/mangadex.go @@ -11,15 +11,18 @@ import ( type Mangadex struct { country string + baseURL string Client *mangadex.Client } // NewMangadex returns a Mangadex instance -func NewMangadex(country string) *Mangadex { +func NewMangadex(country, source string) *Mangadex { + mangadexBase := "https://"+source+"/" return &Mangadex{ country: country, + baseURL: mangadexBase, Client: mangadex.New( - mangadex.WithBase("https://mangadex.cc/"), + mangadex.WithBase(mangadexBase), ), } } @@ -58,7 +61,7 @@ func (m *Mangadex) RetrieveIssueLinks(url string, all, last bool) ([]string, err if m.country != "" && c.LangCode != m.country { continue } - urls = append(urls, "https://mangadex.cc/chapter"+c.ID.String()) + urls = append(urls, m.baseURL+"chapter/"+c.ID.String()) } if len(urls) == 0 { return nil, errors.New("no chapters found") diff --git a/pkg/sites/mangadex_test.go b/pkg/sites/mangadex_test.go index dc4e8bbb..872b8cba 100644 --- a/pkg/sites/mangadex_test.go +++ b/pkg/sites/mangadex_test.go @@ -7,19 +7,22 @@ import ( "github.com/stretchr/testify/assert" ) +const testMangadexBase string = "mangadex.org" +const testMangadexURL string = "https://"+testMangadexBase+"/" + func TestMangadexGetInfo(t *testing.T) { - md := NewMangadex("") + md := NewMangadex("", testMangadexBase) - name, issueNumber := md.GetInfo("https://mangadex.cc/chapter/155061/1") + name, issueNumber := md.GetInfo(testMangadexURL+"chapter/155061/1") assert.Equal(t, "Naruto", name) assert.Equal(t, "Vol 60 Chapter 575, A Will of Stone", issueNumber) } func TestMangadexSetup(t *testing.T) { - md := NewMangadex("") + md := NewMangadex("", testMangadexBase) comic := new(core.Comic) - comic.URLSource = "https://mangadex.cc/chapter/155061/1" + comic.URLSource = testMangadexURL+"chapter/155061/1" err := md.Initialize(comic) @@ -28,44 +31,44 @@ func TestMangadexSetup(t *testing.T) { } func TestMangadexRetrieveIssueLinks(t *testing.T) { - md := NewMangadex("") - urls, err := md.RetrieveIssueLinks("https://mangadex.cc/chapter/155061/", false, false) + md := NewMangadex("", testMangadexBase) + urls, err := md.RetrieveIssueLinks(testMangadexURL+"chapter/155061/", false, false) assert.Nil(t, err) assert.Equal(t, 1, len(urls)) } func TestMangadexRetrieveIssueLinksAllChapter(t *testing.T) { - md := NewMangadex("gb") - urls, err := md.RetrieveIssueLinks("https://mangadex.cc/title/5/naruto/", true, false) + md := NewMangadex("gb", testMangadexBase) + urls, err := md.RetrieveIssueLinks(testMangadexURL+"title/5/naruto/", true, false) assert.Nil(t, err) assert.Len(t, urls, 569) } func TestMangadexRetrieveIssueLinksLastChapter(t *testing.T) { - md := NewMangadex("gb") - urls, err := md.RetrieveIssueLinks("https://mangadex.cc/title/5/naruto/", false, true) + md := NewMangadex("gb", testMangadexBase) + urls, err := md.RetrieveIssueLinks(testMangadexURL+"title/5/naruto/", false, true) assert.Nil(t, err) assert.Len(t, urls, 1) - assert.Equal(t, "https://mangadex.cc/chapter670438", urls[0]) + assert.Equal(t, testMangadexURL+"chapter/670438", urls[0]) } func TestMangadexUnsupportedURL(t *testing.T) { - md := NewMangadex("") - _, err := md.RetrieveIssueLinks("https://mangadex.cc/", false, false) + md := NewMangadex("", testMangadexBase) + _, err := md.RetrieveIssueLinks(testMangadexURL, false, false) assert.EqualError(t, err, "URL not supported") - _, err = md.RetrieveIssueLinks("https://mangadex.cc/test/0/", false, false) + _, err = md.RetrieveIssueLinks(testMangadexURL+"test/0/", false, false) assert.EqualError(t, err, "URL not supported") } func TestMangadexNoManga(t *testing.T) { - md := NewMangadex("") - _, err := md.RetrieveIssueLinks("https://mangadex.cc/title/0/", false, false) + md := NewMangadex("", testMangadexBase) + _, err := md.RetrieveIssueLinks(testMangadexURL+"title/0/", false, false) assert.Error(t, err) assert.Contains(t, err.Error(), "Manga ID does not exist") } func TestMangadexNoChapters(t *testing.T) { - md := NewMangadex("xyz") - _, err := md.RetrieveIssueLinks("https://mangadex.cc/title/5/naruto/", true, false) + md := NewMangadex("xyz", testMangadexBase) + _, err := md.RetrieveIssueLinks(testMangadexURL+"title/5/naruto/", true, false) assert.EqualError(t, err, "no chapters found") }