Skip to content

Commit

Permalink
Feature(provider/fanza): support hi-res images (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu authored Nov 16, 2024
1 parent 4e6af97 commit c75f340
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
36 changes: 36 additions & 0 deletions provider/fanza/fanza.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"time"

"github.com/antchfx/htmlquery"
"github.com/docker/go-units"
"github.com/gocolly/colly/v2"
"golang.org/x/net/html"

Expand Down Expand Up @@ -366,6 +367,41 @@ func (fz *FANZA) GetMovieInfoByURL(rawURL string) (info *model.MovieInfo, err er
}
})

// Find big thumb/cover images (awsimgsrc.dmm.co.jp)
c.OnScraped(func(_ *colly.Response) {
start := time.Date(2024, 5, 20, 0, 0, 0, 0, time.UTC)
if time.Time(info.ReleaseDate).Before(start) {
return // ignore movies released before this date.
}
if !strings.Contains(info.Homepage, "/digital/videoa") {
return // ignore non-digital/videoa typed movies.
}
d := c.Clone()
d.Async = true
d.ParseHTTPErrorResponse = false
d.OnResponseHeaders(func(r *colly.Response) {
if r.Headers.Get("Content-Type") != "image/jpeg" {
return // ignore non-image/jpeg contents.
}
length, _ := strconv.Atoi(r.Headers.Get("Content-Length"))
switch {
case strings.HasSuffix(info.ThumbURL, path.Base(r.Request.URL.Path)) && length > 100*units.KiB:
info.BigThumbURL = r.Request.URL.String()
case strings.HasSuffix(info.CoverURL, path.Base(r.Request.URL.Path)) && length > 500*units.KiB:
info.BigCoverURL = r.Request.URL.String()
}
// abort to prevent image content from being downloaded.
r.Request.Abort()
})
d.Visit(strings.ReplaceAll(info.ThumbURL,
"https://pics.dmm.co.jp/",
"https://awsimgsrc.dmm.co.jp/pics_dig/"))
d.Visit(strings.ReplaceAll(info.CoverURL,
"https://pics.dmm.co.jp/",
"https://awsimgsrc.dmm.co.jp/pics_dig/"))
d.Wait()
})

// Final (big thumb image)
c.OnScraped(func(_ *colly.Response) {
if info.BigThumbURL != "" /* big thumb already exist */ ||
Expand Down
4 changes: 3 additions & 1 deletion provider/fanza/fanza_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ func TestFANZA_GetMovieInfoByID(t *testing.T) {

func TestFANZA_GetMovieInfoByURL(t *testing.T) {
testkit.Test(t, New, []string{
"https://www.dmm.co.jp/digital/videoa/-/detail/=/cid=1start00190/",
"https://www.dmm.co.jp/digital/videoa/-/detail/=/cid=ebwh00164/",
"https://www.dmm.co.jp/digital/videoa/-/detail/=/cid=fpre00106/",
"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=fpre00106/",
"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/",
Expand Down

0 comments on commit c75f340

Please sign in to comment.