pcgamedb/crawler/kaoskrew.go
2024-12-22 00:37:00 +08:00

73 lines
1.6 KiB
Go

package crawler
import (
"regexp"
"strings"
"pcgamedb/model"
"go.uber.org/zap"
)
const KaOsKrewName string = "KaOsKrew-torrents"
type KaOsKrewCrawler struct {
logger *zap.Logger
crawler s1337xCrawler
}
func NewKaOsKrewCrawler(logger *zap.Logger) *KaOsKrewCrawler {
return &KaOsKrewCrawler{
logger: logger,
crawler: *New1337xCrawler(
KaOsKrewName,
"windows",
KaOsKrewFormatter,
logger,
),
}
}
func (c *KaOsKrewCrawler) Name() string {
return "KaOsKrewCrawler"
}
func (c *KaOsKrewCrawler) Crawl(page int) ([]*model.GameItem, error) {
return c.crawler.Crawl(page)
}
func (c *KaOsKrewCrawler) CrawlByUrl(url string) (*model.GameItem, error) {
return c.crawler.CrawlByUrl(url)
}
func (c *KaOsKrewCrawler) CrawlMulti(pages []int) ([]*model.GameItem, error) {
return c.crawler.CrawlMulti(pages)
}
func (c *KaOsKrewCrawler) CrawlAll() ([]*model.GameItem, error) {
return c.crawler.CrawlAll()
}
func (c *KaOsKrewCrawler) GetTotalPageNum() (int, error) {
return c.crawler.GetTotalPageNum()
}
var kaOsKrewRegexps = []*regexp.Regexp{
regexp.MustCompile(`(?i)\.REPACK2?-KaOs`),
regexp.MustCompile(`(?i)\.UPDATE-KaOs`),
regexp.MustCompile(`(?i)v\.?\d+(\.\d+)*|Build\.\d+`),
regexp.MustCompile(`(?i)\.MULTi\d+`),
regexp.MustCompile(`(?i)\sgoty`),
}
func KaOsKrewFormatter(name string) string {
if index := kaOsKrewRegexps[2].FindIndex([]byte(name)); index != nil {
name = name[:index[0]]
}
for _, re := range kaOsKrewRegexps {
name = re.ReplaceAllString(name, "")
}
name = strings.Replace(name, ".", " ", -1)
return strings.TrimSpace(name)
}