pcgamedb/crawler/johncena141.go

67 lines
1.4 KiB
Go
Raw Permalink Normal View History

2024-12-21 11:37:00 -05:00
package crawler
import (
"regexp"
"strings"
"pcgamedb/model"
"go.uber.org/zap"
)
const Johncena141Name string = "johncena141-torrents"
type Johncena141Crawler struct {
logger *zap.Logger
crawler s1337xCrawler
}
func NewJohncena141Crawler(logger *zap.Logger) *Johncena141Crawler {
return &Johncena141Crawler{
logger: logger,
crawler: *New1337xCrawler(
Johncena141Name,
"linux",
Johncena141Formatter,
logger,
),
}
}
func (c *Johncena141Crawler) Name() string {
return "Johncena141Crawler"
}
func (c *Johncena141Crawler) Crawl(page int) ([]*model.GameItem, error) {
return c.crawler.Crawl(page)
}
func (c *Johncena141Crawler) CrawlByUrl(url string) (*model.GameItem, error) {
return c.crawler.CrawlByUrl(url)
}
func (c *Johncena141Crawler) CrawlMulti(pages []int) ([]*model.GameItem, error) {
return c.crawler.CrawlMulti(pages)
}
func (c *Johncena141Crawler) CrawlAll() ([]*model.GameItem, error) {
return c.crawler.CrawlAll()
}
func (c *Johncena141Crawler) GetTotalPageNum() (int, error) {
return c.crawler.GetTotalPageNum()
}
var Johncena141Regexps = []*regexp.Regexp{
regexp.MustCompile(`(?i)\s{2,}`),
regexp.MustCompile(`(?i)[\-\+]\s?[^:\-]*?\s(Edition|Bundle|Pack|Set|Remake|Collection)`),
}
func Johncena141Formatter(name string) string {
nameslice := strings.Split(name, " - ")
name = nameslice[0]
reg1 := regexp.MustCompile(`(?i)\(.*?\)`)
name = reg1.ReplaceAllString(name, "")
return strings.TrimSpace(name)
}