fix: update HTTP client to flare for misclassified sources

Based on Kotlin reference verification:
- Batch 1: colorlibanime, eromuse, fansubscat → flare
- Batch 2: fmreader, galleryadults, greenshit, grouple → flare
- Batch 3: heancms, lectormoe → flare

Also renamed methods appropriately:
- get() for HTML scraping
- getJSON() for JSON APIs
This commit is contained in:
achmad
2026-05-13 10:07:09 +07:00
parent 9a42dd2ab1
commit 46f930718c
9 changed files with 64 additions and 102 deletions
+4 -9
View File
@@ -11,7 +11,7 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"goyomi/internal/httpclient" "goyomi/internal/httpclient/flare"
"goyomi/internal/source" "goyomi/internal/source"
"goyomi/sources/base/util" "goyomi/sources/base/util"
) )
@@ -24,12 +24,12 @@ type Config struct {
type Source struct { type Source struct {
cfg Config cfg Config
client *httpclient.Client client *flare.Client
id int64 id int64
} }
func New(cfg Config) *Source { func New(cfg Config) *Source {
c := httpclient.NewClient(httpclient.WithRateLimit(3, 1)) c := flare.NewClient(flare.WithRateLimit(3, 1))
return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)}
} }
@@ -41,12 +41,7 @@ func (s *Source) SupportsLatest() bool { return true }
func (s *Source) base() string { return strings.TrimRight(s.cfg.BaseURL, "/") } func (s *Source) base() string { return strings.TrimRight(s.cfg.BaseURL, "/") }
func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) { func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) resp, err := s.client.Get(ctx, rawURL)
if err != nil {
return nil, err
}
req.Header.Set("Referer", s.cfg.BaseURL+"/")
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+24 -9
View File
@@ -10,7 +10,7 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"goyomi/internal/httpclient" "goyomi/internal/httpclient/flare"
"goyomi/internal/source" "goyomi/internal/source"
"goyomi/sources/base/util" "goyomi/sources/base/util"
) )
@@ -23,12 +23,12 @@ type Config struct {
type Source struct { type Source struct {
cfg Config cfg Config
client *httpclient.Client client *flare.Client
id int64 id int64
} }
func New(cfg Config) *Source { func New(cfg Config) *Source {
c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) c := flare.NewClient(flare.WithRateLimit(1, 2))
return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)}
} }
@@ -40,12 +40,7 @@ func (s *Source) SupportsLatest() bool { return true }
func (s *Source) base() string { return strings.TrimRight(s.cfg.BaseURL, "/") } func (s *Source) base() string { return strings.TrimRight(s.cfg.BaseURL, "/") }
func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) { func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) resp, err := s.client.Get(ctx, rawURL)
if err != nil {
return nil, err
}
req.Header.Set("Referer", s.cfg.BaseURL+"/")
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -56,6 +51,26 @@ func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, err
return goquery.NewDocumentFromReader(resp.Body) return goquery.NewDocumentFromReader(resp.Body)
} }
func (s *Source) getWithNextPage(ctx context.Context, rawURL string) (*goquery.Document, string, error) {
resp, err := s.client.Get(ctx, rawURL)
if err != nil {
return nil, "", err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, "", fmt.Errorf("eromuse: HTTP %d", resp.StatusCode)
}
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
return nil, "", err
}
var next string
doc.Find(".pagination span.current + span a").First().Each(func(_ int, a *goquery.Selection) {
next, _ = a.Attr("href")
})
return doc, next, nil
}
func (s *Source) parseMangaList(doc *goquery.Document) ([]source.SManga, string) { func (s *Source) parseMangaList(doc *goquery.Document) ([]source.SManga, string) {
var mangas []source.SManga var mangas []source.SManga
doc.Find("a.c-tile:has(img)").Each(func(_ int, el *goquery.Selection) { doc.Find("a.c-tile:has(img)").Each(func(_ int, el *goquery.Selection) {
+4 -10
View File
@@ -10,7 +10,7 @@ import (
"net/http" "net/http"
"strings" "strings"
"goyomi/internal/httpclient" "goyomi/internal/httpclient/flare"
"goyomi/internal/source" "goyomi/internal/source"
"goyomi/sources/base/util" "goyomi/sources/base/util"
) )
@@ -25,7 +25,7 @@ type Config struct {
type Source struct { type Source struct {
cfg Config cfg Config
client *httpclient.Client client *flare.Client
id int64 id int64
} }
@@ -33,7 +33,7 @@ func New(cfg Config) *Source {
if cfg.APIURL == "" { if cfg.APIURL == "" {
cfg.APIURL = cfg.BaseURL cfg.APIURL = cfg.BaseURL
} }
c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) c := flare.NewClient(flare.WithRateLimit(1, 2))
return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)}
} }
@@ -45,13 +45,7 @@ func (s *Source) SupportsLatest() bool { return true }
func (s *Source) api() string { return strings.TrimRight(s.cfg.APIURL, "/") } func (s *Source) api() string { return strings.TrimRight(s.cfg.APIURL, "/") }
func (s *Source) getJSON(ctx context.Context, rawURL string, out any) error { func (s *Source) getJSON(ctx context.Context, rawURL string, out any) error {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) resp, err := s.client.Get(ctx, rawURL)
if err != nil {
return err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("Referer", s.cfg.BaseURL+"/")
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return err return err
} }
+4 -8
View File
@@ -11,7 +11,7 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"goyomi/internal/httpclient" "goyomi/internal/httpclient/flare"
"goyomi/internal/source" "goyomi/internal/source"
"goyomi/sources/base/util" "goyomi/sources/base/util"
) )
@@ -25,7 +25,7 @@ type Config struct {
type Source struct { type Source struct {
cfg Config cfg Config
client *httpclient.Client client *flare.Client
id int64 id int64
} }
@@ -33,7 +33,7 @@ func New(cfg Config) *Source {
if cfg.RequestPath == "" { if cfg.RequestPath == "" {
cfg.RequestPath = "manga-list.html" cfg.RequestPath = "manga-list.html"
} }
c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) c := flare.NewClient(flare.WithRateLimit(1, 2))
return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)}
} }
@@ -43,11 +43,7 @@ func (s *Source) Lang() string { return s.cfg.Lang }
func (s *Source) SupportsLatest() bool { return true } func (s *Source) SupportsLatest() bool { return true }
func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) { func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) resp, err := s.client.Get(ctx, rawURL)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+4 -9
View File
@@ -11,7 +11,7 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"goyomi/internal/httpclient" "goyomi/internal/httpclient/flare"
"goyomi/internal/source" "goyomi/internal/source"
"goyomi/sources/base/util" "goyomi/sources/base/util"
) )
@@ -25,12 +25,12 @@ type Config struct {
type Source struct { type Source struct {
cfg Config cfg Config
client *httpclient.Client client *flare.Client
id int64 id int64
} }
func New(cfg Config) *Source { func New(cfg Config) *Source {
c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) c := flare.NewClient(flare.WithRateLimit(1, 2))
return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)}
} }
@@ -42,12 +42,7 @@ func (s *Source) SupportsLatest() bool { return true }
func (s *Source) base() string { return strings.TrimRight(s.cfg.BaseURL, "/") } func (s *Source) base() string { return strings.TrimRight(s.cfg.BaseURL, "/") }
func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) { func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) resp, err := s.client.Get(ctx, rawURL)
if err != nil {
return nil, err
}
req.Header.Set("Referer", s.cfg.BaseURL+"/")
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+12 -29
View File
@@ -3,7 +3,6 @@
package greenshit package greenshit
import ( import (
"bytes"
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
@@ -16,7 +15,7 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"goyomi/internal/httpclient" "goyomi/internal/httpclient/flare"
"goyomi/internal/source" "goyomi/internal/source"
) )
@@ -36,7 +35,7 @@ type Config struct {
type Source struct { type Source struct {
cfg Config cfg Config
client *httpclient.Client client *flare.Client
id int64 id int64
mu sync.Mutex mu sync.Mutex
@@ -51,7 +50,7 @@ func New(cfg Config) *Source {
if cfg.LimitPerPage == "" { if cfg.LimitPerPage == "" {
cfg.LimitPerPage = "26" cfg.LimitPerPage = "26"
} }
c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) c := flare.NewClient(flare.WithRateLimit(1, 2))
return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)}
} }
@@ -88,14 +87,7 @@ func (s *Source) getToken(ctx context.Context) string {
Senha: s.cfg.Password, Senha: s.cfg.Password,
TipoUsuario: "email", TipoUsuario: "email",
}) })
req, err := http.NewRequestWithContext(ctx, http.MethodPost, s.api()+"/auth/login", bytes.NewReader(body)) resp, err := s.client.Post(ctx, s.api()+"/auth/login", "application/json", strings.NewReader(string(body)))
if err != nil {
return ""
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("scan-id", s.cfg.ScanID)
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return "" return ""
} }
@@ -118,17 +110,8 @@ func (s *Source) getToken(ctx context.Context) string {
return tok return tok
} }
func (s *Source) doGet(ctx context.Context, url string, out any) error { func (s *Source) getJSON(ctx context.Context, url string, out any) error {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) resp, err := s.client.Get(ctx, url)
if err != nil {
return err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("scan-id", s.cfg.ScanID)
if tok := s.getToken(ctx); tok != "" {
req.Header.Set("Authorization", "Bearer "+tok)
}
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return err return err
} }
@@ -285,7 +268,7 @@ func (s *Source) GetPopularManga(page int) (source.MangasPage, error) {
u := fmt.Sprintf("%s/obras/ranking?tipo=visualizacoes_geral&limite=%s&pagina=%d&gen_id=%s", u := fmt.Sprintf("%s/obras/ranking?tipo=visualizacoes_geral&limite=%s&pagina=%d&gen_id=%s",
s.api(), s.cfg.LimitPerPage, page, s.cfg.DefaultGenreID) s.api(), s.cfg.LimitPerPage, page, s.cfg.DefaultGenreID)
var dto listDTO var dto listDTO
if err := s.doGet(context.Background(), u, &dto); err != nil { if err := s.getJSON(context.Background(), u, &dto); err != nil {
return source.MangasPage{}, err return source.MangasPage{}, err
} }
mangas := make([]source.SManga, len(dto.Obras)) mangas := make([]source.SManga, len(dto.Obras))
@@ -299,7 +282,7 @@ func (s *Source) GetLatestUpdates(page int) (source.MangasPage, error) {
u := fmt.Sprintf("%s/obras/atualizacoes?pagina=%d&limite=%s&gen_id=%s", u := fmt.Sprintf("%s/obras/atualizacoes?pagina=%d&limite=%s&gen_id=%s",
s.api(), page, s.cfg.LimitPerPage, s.cfg.DefaultGenreID) s.api(), page, s.cfg.LimitPerPage, s.cfg.DefaultGenreID)
var dto listDTO var dto listDTO
if err := s.doGet(context.Background(), u, &dto); err != nil { if err := s.getJSON(context.Background(), u, &dto); err != nil {
return source.MangasPage{}, err return source.MangasPage{}, err
} }
mangas := make([]source.SManga, len(dto.Obras)) mangas := make([]source.SManga, len(dto.Obras))
@@ -313,7 +296,7 @@ func (s *Source) GetSearchManga(page int, query string, filters []source.Filter)
u := fmt.Sprintf("%s/obras/search?limite=%s&pagina=%d&obr_nome=%s", u := fmt.Sprintf("%s/obras/search?limite=%s&pagina=%d&obr_nome=%s",
s.api(), s.cfg.LimitPerPage, page, query) s.api(), s.cfg.LimitPerPage, page, query)
var dto listDTO var dto listDTO
if err := s.doGet(context.Background(), u, &dto); err != nil { if err := s.getJSON(context.Background(), u, &dto); err != nil {
return source.MangasPage{}, err return source.MangasPage{}, err
} }
mangas := make([]source.SManga, len(dto.Obras)) mangas := make([]source.SManga, len(dto.Obras))
@@ -326,7 +309,7 @@ func (s *Source) GetSearchManga(page int, query string, filters []source.Filter)
func (s *Source) GetMangaDetails(manga source.SManga) (source.SManga, error) { func (s *Source) GetMangaDetails(manga source.SManga) (source.SManga, error) {
id := s.extractID(manga.URL) id := s.extractID(manga.URL)
var dto mangaDTO var dto mangaDTO
if err := s.doGet(context.Background(), fmt.Sprintf("%s/obras/%s", s.api(), id), &dto); err != nil { if err := s.getJSON(context.Background(), fmt.Sprintf("%s/obras/%s", s.api(), id), &dto); err != nil {
return manga, err return manga, err
} }
result := s.toSManga(dto) result := s.toSManga(dto)
@@ -337,7 +320,7 @@ func (s *Source) GetMangaDetails(manga source.SManga) (source.SManga, error) {
func (s *Source) GetChapterList(manga source.SManga) ([]source.SChapter, error) { func (s *Source) GetChapterList(manga source.SManga) ([]source.SChapter, error) {
id := s.extractID(manga.URL) id := s.extractID(manga.URL)
var dto mangaDTO var dto mangaDTO
if err := s.doGet(context.Background(), fmt.Sprintf("%s/obras/%s", s.api(), id), &dto); err != nil { if err := s.getJSON(context.Background(), fmt.Sprintf("%s/obras/%s", s.api(), id), &dto); err != nil {
return nil, err return nil, err
} }
seen := map[string]bool{} seen := map[string]bool{}
@@ -362,7 +345,7 @@ func (s *Source) GetPageList(chapter source.SChapter) ([]source.Page, error) {
// URL format: /capitulo/{id} // URL format: /capitulo/{id}
chID := strings.TrimPrefix(chapter.URL, "/capitulo/") chID := strings.TrimPrefix(chapter.URL, "/capitulo/")
var dto chapterDetailDTO var dto chapterDetailDTO
if err := s.doGet(context.Background(), fmt.Sprintf("%s/capitulos/%s", s.api(), chID), &dto); err != nil { if err := s.getJSON(context.Background(), fmt.Sprintf("%s/capitulos/%s", s.api(), chID), &dto); err != nil {
return nil, err return nil, err
} }
obraID := 0 obraID := 0
+4 -8
View File
@@ -10,7 +10,7 @@ import (
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"goyomi/internal/httpclient" "goyomi/internal/httpclient/flare"
"goyomi/internal/source" "goyomi/internal/source"
"goyomi/sources/base/util" "goyomi/sources/base/util"
) )
@@ -23,12 +23,12 @@ type Config struct {
type Source struct { type Source struct {
cfg Config cfg Config
client *httpclient.Client client *flare.Client
id int64 id int64
} }
func New(cfg Config) *Source { func New(cfg Config) *Source {
c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) c := flare.NewClient(flare.WithRateLimit(1, 2))
return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)}
} }
@@ -38,11 +38,7 @@ func (s *Source) Lang() string { return s.cfg.Lang }
func (s *Source) SupportsLatest() bool { return true } func (s *Source) SupportsLatest() bool { return true }
func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) { func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) resp, err := s.client.Get(ctx, rawURL)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+4 -9
View File
@@ -12,7 +12,7 @@ import (
"strings" "strings"
"time" "time"
"goyomi/internal/httpclient" "goyomi/internal/httpclient/flare"
"goyomi/internal/source" "goyomi/internal/source"
"goyomi/sources/base/util" "goyomi/sources/base/util"
) )
@@ -30,7 +30,7 @@ type Config struct {
type Source struct { type Source struct {
cfg Config cfg Config
client *httpclient.Client client *flare.Client
id int64 id int64
} }
@@ -50,7 +50,7 @@ func New(cfg Config) *Source {
if cfg.MangaSubDirectory == "" { if cfg.MangaSubDirectory == "" {
cfg.MangaSubDirectory = "series" cfg.MangaSubDirectory = "series"
} }
c := httpclient.NewClient(httpclient.WithRateLimit(1, 2)) c := flare.NewClient(flare.WithRateLimit(1, 2))
return &Source{ return &Source{
cfg: cfg, cfg: cfg,
client: c, client: c,
@@ -228,12 +228,7 @@ func (s *Source) toSChapter(dto chapterDTO, seriesSlug string) source.SChapter {
// --- API calls --- // --- API calls ---
func (s *Source) getJSON(ctx context.Context, rawURL string, out any) error { func (s *Source) getJSON(ctx context.Context, rawURL string, out any) error {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) resp, err := s.client.Get(ctx, rawURL)
if err != nil {
return err
}
req.Header.Set("Accept", "application/json")
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return err return err
} }
+4 -11
View File
@@ -10,7 +10,7 @@ import (
"net/http" "net/http"
"strings" "strings"
"goyomi/internal/httpclient" "goyomi/internal/httpclient/flare"
"goyomi/internal/source" "goyomi/internal/source"
"goyomi/sources/base/util" "goyomi/sources/base/util"
) )
@@ -27,7 +27,7 @@ type Config struct {
type Source struct { type Source struct {
cfg Config cfg Config
client *httpclient.Client client *flare.Client
id int64 id int64
} }
@@ -38,7 +38,7 @@ func New(cfg Config) *Source {
if cfg.OrganizationDomain == "" { if cfg.OrganizationDomain == "" {
cfg.OrganizationDomain = util.SlugFromURL(cfg.BaseURL) cfg.OrganizationDomain = util.SlugFromURL(cfg.BaseURL)
} }
c := httpclient.NewClient(httpclient.WithRateLimit(3, 1)) c := flare.NewClient(flare.WithRateLimit(3, 1))
return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)} return &Source{cfg: cfg, client: c, id: source.GenerateSourceID(cfg.Name, cfg.Lang)}
} }
@@ -50,14 +50,7 @@ func (s *Source) SupportsLatest() bool { return true }
func (s *Source) api() string { return strings.TrimRight(s.cfg.APIBaseURL, "/") } func (s *Source) api() string { return strings.TrimRight(s.cfg.APIBaseURL, "/") }
func (s *Source) getJSON(ctx context.Context, rawURL string, out any) error { func (s *Source) getJSON(ctx context.Context, rawURL string, out any) error {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil) resp, err := s.client.Get(ctx, rawURL)
if err != nil {
return err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("Referer", s.cfg.BaseURL+"/")
req.Header.Set("x-organization", s.cfg.OrganizationDomain)
resp, err := s.client.Do(req)
if err != nil { if err != nil {
return err return err
} }