pcgamedb/crawler/kaoskrew.go

73 lines
1.6 KiB
Go
Raw Permalink Normal View History

2024-09-24 06:17:11 -04:00
package crawler
import (
"regexp"
"strings"
2024-11-20 06:09:04 -05:00
"pcgamedb/model"
2024-11-15 02:02:45 -05:00
2024-09-24 06:17:11 -04:00
"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,
2024-12-21 11:37:00 -05:00
"windows",
2024-09-24 06:17:11 -04:00
KaOsKrewFormatter,
logger,
),
}
}
2024-11-14 12:29:19 -05:00
func (c *KaOsKrewCrawler) Name() string {
return "KaOsKrewCrawler"
}
func (c *KaOsKrewCrawler) Crawl(page int) ([]*model.GameItem, error) {
2024-09-24 06:17:11 -04:00
return c.crawler.Crawl(page)
}
func (c *KaOsKrewCrawler) CrawlByUrl(url string) (*model.GameItem, error) {
2024-09-24 06:17:11 -04:00
return c.crawler.CrawlByUrl(url)
}
func (c *KaOsKrewCrawler) CrawlMulti(pages []int) ([]*model.GameItem, error) {
2024-09-24 06:17:11 -04:00
return c.crawler.CrawlMulti(pages)
}
func (c *KaOsKrewCrawler) CrawlAll() ([]*model.GameItem, error) {
2024-09-24 06:17:11 -04:00
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)
}