Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9fd9924ba5 | |||
| 743823d67a | |||
| 9209b6fb2c |
@@ -145,6 +145,10 @@ func (f *TLSCoverFetcher) Fetch(ctx context.Context, sourceURL string) ([]byte,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", fmt.Errorf("build cover request: %w", err)
|
return nil, "", fmt.Errorf("build cover request: %w", err)
|
||||||
}
|
}
|
||||||
|
// cdn.asurascans.com answers Go's default User-Agent with a Cloudflare
|
||||||
|
// challenge (403, cf-mitigated) and a Chrome one with the image; measured
|
||||||
|
// 2026-12-04. No TLS fingerprint needed — the UA alone flips it.
|
||||||
|
req.Header.Set("User-Agent", chromeUA)
|
||||||
resp, err := f.client.Do(req)
|
resp, err := f.client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", fmt.Errorf("fetch cover: %w", err)
|
return nil, "", fmt.Errorf("fetch cover: %w", err)
|
||||||
|
|||||||
@@ -228,6 +228,24 @@ func TestCoverFetcherRejectsNonImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cdn.asurascans.com challenges Go's default User-Agent (measured 2026-12-04),
|
||||||
|
// so every cover from it failed until the fetcher sent a browser one.
|
||||||
|
func TestCoverFetcherSendsBrowserUserAgent(t *testing.T) {
|
||||||
|
client := &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) {
|
||||||
|
if r.UserAgent() != chromeUA {
|
||||||
|
return coverResponse(http.StatusForbidden, "text/html", "", []byte("Just a moment...")), nil
|
||||||
|
}
|
||||||
|
return coverResponse(http.StatusOK, "image/webp", "", []byte("cover-bytes")), nil
|
||||||
|
})}
|
||||||
|
fetcher := newCoverFetcher(client, func(context.Context, string) ([]netip.Addr, error) {
|
||||||
|
return []netip.Addr{netip.MustParseAddr("198.51.100.10")}, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if _, _, err := fetcher.Fetch(context.Background(), "https://cdn.asurascans.com/asura-images/covers/x.webp"); err != nil {
|
||||||
|
t.Fatalf("Fetch: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// comix labels its covers "image/jpg", which is not a registered type but is
|
// comix labels its covers "image/jpg", which is not a registered type but is
|
||||||
// what the Site actually answers with; the bytes are stored under the real
|
// what the Site actually answers with; the bytes are stored under the real
|
||||||
// name so one image cannot land under two spellings.
|
// name so one image cannot land under two spellings.
|
||||||
|
|||||||
@@ -341,13 +341,27 @@ func comixCoverURL(seriesURL, body string) string {
|
|||||||
return publishedCoverURL(entry.Poster.Medium)
|
return publishedCoverURL(entry.Poster.Medium)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ogImageCover reads the og:image metadata shared by asura, demonic and
|
// ogImageCover reads the og:image metadata shared by demonic and
|
||||||
// lightnovelworld.
|
// lightnovelworld.
|
||||||
func ogImageCover(_, body string) (string, bool) {
|
func ogImageCover(_, body string) (string, bool) {
|
||||||
cover := metaContent(body, "property", "og:image")
|
cover := metaContent(body, "property", "og:image")
|
||||||
return cover, cover != ""
|
return cover, cover != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// asuraCoverRe reads coverUrl from the astro-island props, in both quote forms
|
||||||
|
// asuraStatusRe accepts. asura's og:image stopped being the cover (seen
|
||||||
|
// 2026-12-04): it is now a 1200x630 social card on asurascans.com itself,
|
||||||
|
// which also challenges every fetch without a Chrome TLS fingerprint.
|
||||||
|
var asuraCoverRe = regexp.MustCompile(`(?:"|")coverUrl(?:"|"):\[0,(?:"|")(https://[^&"]+)`)
|
||||||
|
|
||||||
|
func asuraCover(_, body string) (string, bool) {
|
||||||
|
m := asuraCoverRe.FindStringSubmatch(body)
|
||||||
|
if m == nil {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return m[1], true
|
||||||
|
}
|
||||||
|
|
||||||
func novelfullCoverEntry(_, body string) (string, bool) {
|
func novelfullCoverEntry(_, body string) (string, bool) {
|
||||||
cover := metaContent(body, "name", "image")
|
cover := metaContent(body, "name", "image")
|
||||||
return cover, cover != ""
|
return cover, cover != ""
|
||||||
@@ -541,7 +555,7 @@ var sites = map[string]site{
|
|||||||
"asura": {
|
"asura": {
|
||||||
Host: "asurascans.com",
|
Host: "asurascans.com",
|
||||||
LatestChapter: asuraLatestChapter,
|
LatestChapter: asuraLatestChapter,
|
||||||
Cover: ogImageCover,
|
Cover: asuraCover,
|
||||||
Completed: asuraCompleted,
|
Completed: asuraCompleted,
|
||||||
Rest: defaultRest,
|
Rest: defaultRest,
|
||||||
Gap: defaultGap,
|
Gap: defaultGap,
|
||||||
|
|||||||
@@ -286,9 +286,11 @@ const lnwOngoingFixture = `<script type="application/ld+json">{
|
|||||||
"creativeWorkStatus": "https://schema.org/ActiveActionStatus"
|
"creativeWorkStatus": "https://schema.org/ActiveActionStatus"
|
||||||
}</script>`
|
}</script>`
|
||||||
|
|
||||||
// Trimmed from https://asurascans.com/comics/chronicles-of-the-demon-faction-f886a8af
|
// Trimmed from https://asurascans.com/comics/chronicles-of-the-demon-faction-ce13e3a9
|
||||||
// (redirected to ...-00dcbf97) on 2026-08-10.
|
// on 2026-12-04. og:image is a social card, not the cover; the cover is the
|
||||||
const asuraCoverFixture = `<meta property="og:image" content="https://cdn.asurascans.com/asura-images/covers/chronicles-of-the-demon-faction.d4dcb8.webp">`
|
// astro-island coverUrl prop.
|
||||||
|
const asuraCoverFixture = `<meta property="og:image" content="https://asurascans.com/og/comics/chronicles-of-the-demon-faction.jpg">` +
|
||||||
|
`<astro-island props="{"seriesTitle":[0,"Chronicles of the Demon Faction"],"coverUrl":[0,"https://cdn.asurascans.com/asura-images/covers/chronicles-of-the-demon-faction.d4dcb8.webp"]}"></astro-island>`
|
||||||
|
|
||||||
// Trimmed from https://demonicscans.org/manga/Catastrophic-Necromancer on 2026-08-10.
|
// Trimmed from https://demonicscans.org/manga/Catastrophic-Necromancer on 2026-08-10.
|
||||||
// The source publishes the raw space in this URL.
|
// The source publishes the raw space in this URL.
|
||||||
@@ -321,7 +323,7 @@ func TestCoverFrom(t *testing.T) {
|
|||||||
wantCover string
|
wantCover string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "asura uses published metadata URL",
|
name: "asura reads coverUrl prop, not og social card",
|
||||||
site: "asura", body: asuraCoverFixture, wantOK: true,
|
site: "asura", body: asuraCoverFixture, wantOK: true,
|
||||||
wantCover: "https://cdn.asurascans.com/asura-images/covers/chronicles-of-the-demon-faction.d4dcb8.webp",
|
wantCover: "https://cdn.asurascans.com/asura-images/covers/chronicles-of-the-demon-faction.d4dcb8.webp",
|
||||||
},
|
},
|
||||||
@@ -352,10 +354,10 @@ func TestCoverFrom(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "later metadata cover survives empty match",
|
name: "later metadata cover survives empty match",
|
||||||
site: "asura",
|
site: "demonic",
|
||||||
body: `<meta property="og:image" content="">` + asuraCoverFixture,
|
body: `<meta property="og:image" content="">` + demonicCoverFixture,
|
||||||
wantOK: true,
|
wantOK: true,
|
||||||
wantCover: "https://cdn.asurascans.com/asura-images/covers/chronicles-of-the-demon-faction.d4dcb8.webp",
|
wantCover: "https://readermc.org/images/thumbnails/Catastrophic%20Necromancer.webp",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "page without cover is empty",
|
name: "page without cover is empty",
|
||||||
|
|||||||
Reference in New Issue
Block a user