Skip to content
This repository has been archived by the owner on Sep 22, 2021. It is now read-only.

Commit

Permalink
fix: licensor in anime genre,producer,season
Browse files Browse the repository at this point in the history
  • Loading branch information
rl404 committed Sep 16, 2021
1 parent 5acd4bb commit 3ad2439
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 5 additions & 2 deletions api_producer_magazine_test.go
Expand Up @@ -35,7 +35,7 @@ func TestGetProducer(t *testing.T) {
require.NoError(t, err)

assert.NotZero(t, len(d))
emptyY, emptyM, emptyD, emptyLic, emptyEp := true, true, true, true, true
emptyY, emptyM, emptyD, emptyLic, emptyEp, emptyGen := true, true, true, true, true,true
for _, p := range d {
assert.NotZero(t, p.ID)
assert.NotEmpty(t, p.Image)
Expand All @@ -54,7 +54,9 @@ func TestGetProducer(t *testing.T) {
}
assert.NotZero(t, p.Member)
assert.NotZero(t, p.Score)
assert.NotZero(t, len(p.Genres))
if len(p.Genres) > 0 {
emptyGen = false
}
for _, g := range p.Genres {
assert.NotZero(t, g.ID)
assert.NotEmpty(t, g.Name)
Expand All @@ -77,6 +79,7 @@ func TestGetProducer(t *testing.T) {
assert.False(t, emptyD)
assert.False(t, emptyEp)
assert.False(t, emptyLic)
assert.False(t, emptyGen)
time.Sleep(sleepDur)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/parser/genre.go
Expand Up @@ -19,7 +19,7 @@ func (p *Parser) GetGenres(t string) ([]model.ItemCount, int, error) {
// GetAnimeWithGenre to get anime list with specific genre.
func (p *Parser) GetAnimeWithGenre(id int, page int) ([]model.AnimeItem, int, error) {
q := map[string]interface{}{"page": page}
doc, code, err := p.getDoc(utils.BuildURLWithQuery(q, malURL, "anime", "genre", id, "a"), "#contentWrapper")
doc, code, err := p.getDoc(utils.BuildURLWithQuery(q, malURL, "anime", "genre", id, "a"), "#content")
if err != nil {
return nil, code, err
}
Expand All @@ -29,7 +29,7 @@ func (p *Parser) GetAnimeWithGenre(id int, page int) ([]model.AnimeItem, int, er
// GetMangaWithGenre to get manga list with specific genre.
func (p *Parser) GetMangaWithGenre(id int, page int) ([]model.MangaItem, int, error) {
q := map[string]interface{}{"page": page}
doc, code, err := p.getDoc(utils.BuildURLWithQuery(q, malURL, "manga", "genre", id, "a"), "#contentWrapper")
doc, code, err := p.getDoc(utils.BuildURLWithQuery(q, malURL, "manga", "genre", id, "a"), "#content")
if err != nil {
return nil, code, err
}
Expand Down
16 changes: 13 additions & 3 deletions internal/parser/producer_magazine/producer.go
Expand Up @@ -78,7 +78,7 @@ func (p *producer) getGenres(eachArea *goquery.Selection) []model.Item {
}

func (p *producer) getSynopsis(eachArea *goquery.Selection) string {
synopsis := strings.TrimSpace(eachArea.Find("div[class=\"synopsis js-synopsis\"]").Text())
synopsis := strings.TrimSpace(eachArea.Find("div[class=\"synopsis js-synopsis\"]").Find(".preline").Text())
if regexp.MustCompile(`No synopsis`).FindString(synopsis) != "" {
return ""
}
Expand Down Expand Up @@ -115,8 +115,18 @@ func (p *producer) getProgress(area *goquery.Selection) int {
}

func (p *producer) getLicensors(eachArea *goquery.Selection) []string {
licensor, _ := eachArea.Find("div[class=\"synopsis js-synopsis\"] .licensors").Attr("data-licensors")
return utils.ArrayFilter(strings.Split(licensor, ","))
licensors := []string{}
area := eachArea.Find("div[class=\"synopsis js-synopsis\"]")
area.Find("p").EachWithBreak(func(i int, a *goquery.Selection) bool {
if a.Find("span").Text() == "Licensor:" {
a.Find("a").Each(func(i int, s *goquery.Selection) {
licensors = append(licensors, s.Text())
})
return false
}
return true
})
return licensors
}

func (p *producer) getType(area *goquery.Selection) string {
Expand Down

0 comments on commit 3ad2439

Please sign in to comment.