Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #36: Added support to mangadex
- Loading branch information
Showing
11 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package sites | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Girbons/comics-downloader/pkg/core" | ||
"github.com/Girbons/comics-downloader/pkg/util" | ||
"github.com/bake/mangadex" | ||
) | ||
|
||
type Mangadex struct { | ||
Client *mangadex.Client | ||
} | ||
|
||
// NewMangadex returns a Mangadex instance | ||
func NewMangadex() *Mangadex { | ||
return &Mangadex{ | ||
Client: mangadex.New(), | ||
} | ||
} | ||
|
||
func (m *Mangadex) getLinks(url string) ([]string, error) { | ||
var links []string | ||
|
||
parts := util.TrimAndSplitURL(url) | ||
chapterID := parts[4] | ||
|
||
res, err := m.Client.Chapter(chapterID) | ||
if err != nil { | ||
return links, err | ||
} | ||
|
||
links = res.Images() | ||
|
||
return links, nil | ||
} | ||
|
||
func (m *Mangadex) RetrieveIssueLinks(url string, all, last bool) ([]string, error) { | ||
return []string{url}, nil | ||
} | ||
|
||
func (m *Mangadex) GetInfo(url string) (string, string) { | ||
parts := util.TrimAndSplitURL(url) | ||
chapterID := parts[4] | ||
|
||
chapterInfo, err := m.Client.Chapter(chapterID) | ||
if err != nil { | ||
return "", "" | ||
} | ||
|
||
mangaInfo, _, err := m.Client.Manga(string(chapterInfo.MangaID)) | ||
if err != nil { | ||
return "", "" | ||
} | ||
|
||
issueNumber := fmt.Sprintf("Vol %s Chapter %s, %s", chapterInfo.Volume, chapterInfo.Chapter, chapterInfo.Title) | ||
|
||
return mangaInfo.Title, issueNumber | ||
} | ||
|
||
// Initialize loads links and metadata from mangadex | ||
func (m *Mangadex) Initialize(comic *core.Comic) error { | ||
links, err := m.getLinks(comic.URLSource) | ||
comic.Links = links | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package sites | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Girbons/comics-downloader/pkg/core" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMangadexGetInfo(t *testing.T) { | ||
md := NewMangadex() | ||
|
||
name, issueNumber := md.GetInfo("https://mangadex.org/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() | ||
comic := new(core.Comic) | ||
|
||
comic.URLSource = "https://mangadex.org/chapter/155061/1" | ||
|
||
err := md.Initialize(comic) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, 14, len(comic.Links)) | ||
} | ||
|
||
func TestMangadexRetrieveIssueLinks(t *testing.T) { | ||
md := NewMangadex() | ||
|
||
issues, err := md.RetrieveIssueLinks("https://mangadex.org/chapter/155061/1", false, false) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, 1, len(issues)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters