316ae2f9db
Add 8 all/ sources (7 Masonry, 1 Madara) and 38 en/ sources spanning Madara, MangaThemesia, MadTheme, Keyoapp, and Guya bases, plus 8 earlier all/ standalone sources from the previous session (ahottie, akuma, allporncomicsco, asmhentai, baobua, beauty3600000, buondua, comicfury, comicgrowl, comicklive, comicsvalley, comikey, commitstrip, coomer). Also annotates phase4-standalone.md with base-class tags for 43 additional unimplemented en/ sources identified in a full scan.
221 lines
5.9 KiB
Go
221 lines
5.9 KiB
Go
package ahottie
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
|
|
"goyomi/internal/httpclient"
|
|
"goyomi/internal/registry"
|
|
"goyomi/internal/source"
|
|
)
|
|
|
|
type Source struct {
|
|
cfg Config
|
|
client *httpclient.Client
|
|
id int64
|
|
}
|
|
|
|
type Config struct {
|
|
Name string
|
|
BaseURL string
|
|
Lang string
|
|
}
|
|
|
|
func New() *Source {
|
|
c := httpclient.NewClient(httpclient.WithRateLimit(1, 2))
|
|
return &Source{
|
|
cfg: Config{
|
|
Name: "AHottie",
|
|
BaseURL: "https://ahottie.top",
|
|
Lang: "all",
|
|
},
|
|
client: c,
|
|
id: source.GenerateSourceID("AHottie", "all"),
|
|
}
|
|
}
|
|
|
|
func (s *Source) ID() int64 { return s.id }
|
|
func (s *Source) Name() string { return s.cfg.Name }
|
|
func (s *Source) Lang() string { return s.cfg.Lang }
|
|
func (s *Source) SupportsLatest() bool { return false }
|
|
|
|
func (s *Source) base() string { return strings.TrimRight(s.cfg.BaseURL, "/") }
|
|
|
|
func (s *Source) get(ctx context.Context, rawURL string) (*goquery.Document, error) {
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, rawURL, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req.Header.Set("Referer", s.base()+"/")
|
|
resp, err := s.client.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
return nil, fmt.Errorf("ahottie: HTTP %d", resp.StatusCode)
|
|
}
|
|
return goquery.NewDocumentFromReader(resp.Body)
|
|
}
|
|
|
|
func (s *Source) parseMangas(doc *goquery.Document) source.MangasPage {
|
|
var mangas []source.SManga
|
|
doc.Find("#main > div > div").Each(func(_ int, el *goquery.Selection) {
|
|
link := el.Find("a").First()
|
|
href := link.AttrOr("href", "")
|
|
if href == "" {
|
|
return
|
|
}
|
|
titleEl := el.Find("h2")
|
|
if titleEl.Length() == 0 {
|
|
return
|
|
}
|
|
m := source.SManga{
|
|
URL: href,
|
|
Title: strings.TrimSpace(titleEl.Text()),
|
|
}
|
|
if img := el.Find(".relative img").First(); img.Length() > 0 {
|
|
m.ThumbnailURL = img.AttrOr("src", "")
|
|
}
|
|
var genres []string
|
|
el.Find(".flex a").Each(func(_ int, a *goquery.Selection) {
|
|
if t := strings.TrimSpace(a.Text()); t != "" {
|
|
genres = append(genres, t)
|
|
}
|
|
})
|
|
m.Genre = strings.Join(genres, ", ")
|
|
if m.URL != "" && m.Title != "" {
|
|
mangas = append(mangas, m)
|
|
}
|
|
})
|
|
hasNext := doc.Find("a[rel=next]").Length() > 0
|
|
return source.MangasPage{Mangas: mangas, HasNextPage: hasNext}
|
|
}
|
|
|
|
func (s *Source) GetPopularManga(page int) (source.MangasPage, error) {
|
|
doc, err := s.get(context.Background(), fmt.Sprintf("%s?page=%d", s.base(), page))
|
|
if err != nil {
|
|
return source.MangasPage{}, err
|
|
}
|
|
return s.parseMangas(doc), nil
|
|
}
|
|
|
|
func (s *Source) GetLatestUpdates(page int) (source.MangasPage, error) {
|
|
return source.MangasPage{}, fmt.Errorf("ahottie: latest updates not supported")
|
|
}
|
|
|
|
func (s *Source) GetSearchManga(page int, query string, filters []source.Filter) (source.MangasPage, error) {
|
|
if strings.HasPrefix(query, "http") {
|
|
doc, err := s.get(context.Background(), query)
|
|
if err != nil {
|
|
return source.MangasPage{}, err
|
|
}
|
|
m := s.parseMangaDetails(doc)
|
|
m.URL = strings.TrimPrefix(query, s.base())
|
|
return source.MangasPage{Mangas: []source.SManga{m}, HasNextPage: false}, nil
|
|
}
|
|
doc, err := s.get(context.Background(), fmt.Sprintf("%s/search?kw=%s&page=%d", s.base(), query, page))
|
|
if err != nil {
|
|
return source.MangasPage{}, err
|
|
}
|
|
if doc.Find("h1").Length() > 0 && doc.Find("div.pl-3 > a").Length() > 0 {
|
|
m := s.parseMangaDetails(doc)
|
|
m.URL = strings.TrimPrefix(doc.Find("div.pl-3 > a").First().AttrOr("href", ""), s.base())
|
|
return source.MangasPage{Mangas: []source.SManga{m}, HasNextPage: false}, nil
|
|
}
|
|
return s.parseMangas(doc), nil
|
|
}
|
|
|
|
func (s *Source) parseMangaDetails(doc *goquery.Document) source.SManga {
|
|
result := source.SManga{}
|
|
titleEl := doc.Find("h1").First()
|
|
if titleEl.Length() > 0 {
|
|
result.Title = strings.TrimSpace(titleEl.Text())
|
|
}
|
|
var genres []string
|
|
doc.Find("div.pl-3 > a").Each(func(_ int, a *goquery.Selection) {
|
|
if t := strings.TrimSpace(a.Text()); t != "" {
|
|
genres = append(genres, t)
|
|
}
|
|
})
|
|
result.Genre = strings.Join(genres, ", ")
|
|
result.Status = source.StatusUnknown
|
|
return result
|
|
}
|
|
|
|
func (s *Source) GetMangaDetails(manga source.SManga) (source.SManga, error) {
|
|
doc, err := s.get(context.Background(), s.base()+manga.URL)
|
|
if err != nil {
|
|
return manga, err
|
|
}
|
|
result := s.parseMangaDetails(doc)
|
|
result.URL = manga.URL
|
|
if result.Title == "" {
|
|
result.Title = manga.Title
|
|
}
|
|
return result, nil
|
|
}
|
|
|
|
func (s *Source) GetChapterList(manga source.SManga) ([]source.SChapter, error) {
|
|
doc, err := s.get(context.Background(), s.base()+manga.URL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
timeEl := doc.Find("time").First()
|
|
var date int64
|
|
if dateStr := strings.TrimSpace(timeEl.Text()); dateStr != "" {
|
|
t, err := time.Parse("2006-01-02", dateStr)
|
|
if err == nil {
|
|
date = t.UnixMilli()
|
|
}
|
|
}
|
|
canonical := doc.Find("link[rel=canonical]").First()
|
|
href := canonical.AttrOr("href", "")
|
|
if href == "" {
|
|
return nil, fmt.Errorf("ahottie: chapter link not found")
|
|
}
|
|
return []source.SChapter{
|
|
{
|
|
URL: strings.TrimPrefix(href, s.base()),
|
|
Name: "GALLERY",
|
|
DateUpload: date,
|
|
},
|
|
}, nil
|
|
}
|
|
|
|
func (s *Source) GetPageList(chapter source.SChapter) ([]source.Page, error) {
|
|
var pages []source.Page
|
|
doc, err := s.get(context.Background(), s.base()+chapter.URL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for {
|
|
doc.Find("#main img.block").Each(func(i int, img *goquery.Selection) {
|
|
src := img.AttrOr("src", "")
|
|
if src != "" {
|
|
pages = append(pages, source.Page{Index: len(pages), ImageURL: src})
|
|
}
|
|
})
|
|
nextURL := doc.Find("a[rel=next]").First().AttrOr("href", "")
|
|
if nextURL == "" {
|
|
break
|
|
}
|
|
doc, err = s.get(context.Background(), nextURL)
|
|
if err != nil {
|
|
break
|
|
}
|
|
}
|
|
return pages, nil
|
|
}
|
|
|
|
func (s *Source) GetImageURL(page source.Page) (string, error) { return page.ImageURL, nil }
|
|
func (s *Source) GetFilterList() []source.Filter { return nil }
|
|
|
|
func init() {
|
|
registry.Register(New())
|
|
} |