Skip to content

Commit

Permalink
Fix(fanza/dvd): no preview images
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Dec 17, 2023
1 parent f7b9ae0 commit 347d0d8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
22 changes: 19 additions & 3 deletions provider/fanza/fanza.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/antchfx/htmlquery"
"github.com/gocolly/colly/v2"
"github.com/iancoleman/orderedmap"
"golang.org/x/net/html"

"github.com/metatube-community/metatube-sdk-go/common/comparer"
Expand Down Expand Up @@ -319,10 +320,25 @@ func (fz *FANZA) GetMovieInfoByURL(rawURL string) (info *model.MovieInfo, err er
FindString(e.Attr("onclick"))))
})

// Preview Images
// In case of any duplication
previewImageSet := orderedmap.New()

// Preview Images Digital/DVD
c.OnXML(`//*[@id="sample-image-block"]//a[@name="sample-image"]`, func(e *colly.XMLElement) {
previewImageSet.Set(e.Request.AbsoluteURL(PreviewSrc(e.ChildAttr(`.//img`, "src"))), nil)
})

// Preview Images Digital (Fallback)
c.OnXML(`//*[@id="sample-image-block"]/a`, func(e *colly.XMLElement) {
info.PreviewImages = append(info.PreviewImages,
e.Request.AbsoluteURL(PreviewSrc(e.ChildAttr(`.//img`, "src"))))
if len(previewImageSet.Keys()) == 0 {
return
}
previewImageSet.Set(e.Request.AbsoluteURL(PreviewSrc(e.ChildAttr(`.//img`, "src"))), nil)
})

// Final Preview Images
c.OnScraped(func(_ *colly.Response) {
info.PreviewImages = append(info.PreviewImages, previewImageSet.Keys()...)
})

// Final (images)
Expand Down
16 changes: 16 additions & 0 deletions provider/fanza/fanza_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ func TestFANZA_GetMovieInfoByID(t *testing.T) {
}
}

func TestFANZA_GetMovieInfoByURL(t *testing.T) {
provider := New()
for _, item := range []string{
"https://www.dmm.co.jp/mono/dvd/-/detail/=/cid=41hodv21810/",
"https://www.dmm.co.jp/mono/dvd/-/detail/=/cid=h_346rebd655/",
"https://www.dmm.co.jp/digital/videoa/-/detail/=/cid=ipvr00231/",
"https://www.dmm.co.jp/mono/anime/-/detail/=/cid=196glod0323t/",
"https://www.dmm.co.jp/digital/videoc/-/detail/=/cid=fuyu079/",
} {
info, err := provider.GetMovieInfoByURL(item)
data, _ := json.MarshalIndent(info, "", "\t")
assert.True(t, assert.NoError(t, err) && assert.True(t, info.Valid()))
t.Logf("%s", data)
}
}

func TestFANZA_SearchMovie(t *testing.T) {
provider := New()
for _, item := range []string{
Expand Down

0 comments on commit 347d0d8

Please sign in to comment.