add platform

This commit is contained in:
Nite07 2024-12-22 00:37:00 +08:00
parent cc67966063
commit ee09d2b468
16 changed files with 100 additions and 12 deletions

View File

@ -21,15 +21,17 @@ type Formatter func(string) string
type s1337xCrawler struct {
source string
platform string
formatter Formatter
logger *zap.Logger
}
func New1337xCrawler(source string, formatter Formatter, logger *zap.Logger) *s1337xCrawler {
func New1337xCrawler(source string, platform string, formatter Formatter, logger *zap.Logger) *s1337xCrawler {
return &s1337xCrawler{
source: source,
formatter: formatter,
logger: logger,
platform: platform,
}
}
@ -104,6 +106,7 @@ func (c *s1337xCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
item.Name = c.formatter(item.RawName)
item.Download = magnetRegexRes[0]
item.Author = strings.Replace(c.source, "-torrents", "", -1)
item.Platform = c.platform
return item, nil
}

View File

@ -48,6 +48,7 @@ func (c *ChovkaCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
item.Name = ChovkaFormatter(item.RawName)
item.Author = "Chovka"
item.UpdateFlag = item.RawName
item.Platform = "windows"
downloadURL := doc.Find(".download-torrent").AttrOr("href", "")
if downloadURL == "" {
return nil, errors.New("failed to find download URL")

View File

@ -24,15 +24,16 @@ type PagedCrawler interface {
func BuildCrawlerMap(logger *zap.Logger) map[string]Crawler {
ret := map[string]Crawler{
"fitgirl": NewFitGirlCrawler(logger),
"dodi": NewDODICrawler(logger),
"kaoskrew": NewKaOsKrewCrawler(logger),
"freegog": NewFreeGOGCrawler(logger),
"xatab": NewXatabCrawler(logger),
"onlinefix": NewOnlineFixCrawler(logger),
"steamrip": NewSteamRIPCrawler(logger),
"chovka": NewChovkaCrawler(logger),
"goggames": NewGOGGamesCrawler(logger),
"fitgirl": NewFitGirlCrawler(logger),
"dodi": NewDODICrawler(logger),
"kaoskrew": NewKaOsKrewCrawler(logger),
"freegog": NewFreeGOGCrawler(logger),
"xatab": NewXatabCrawler(logger),
"onlinefix": NewOnlineFixCrawler(logger),
"steamrip": NewSteamRIPCrawler(logger),
"chovka": NewChovkaCrawler(logger),
"goggames": NewGOGGamesCrawler(logger),
"johncena141": NewJohncena141Crawler(logger),
// "gnarly": NewGnarlyCrawler(logger),
}
return ret

View File

@ -22,6 +22,7 @@ func NewDODICrawler(logger *zap.Logger) *DODICrawler {
logger: logger,
crawler: *New1337xCrawler(
DODIName,
"windows",
DODIFormatter,
logger,
),

View File

@ -69,6 +69,7 @@ func (c *FitGirlCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
item.Size = size
item.Author = "FitGirl"
item.Download = magnet
item.Platform = "windows"
return item, nil
}

View File

@ -153,6 +153,7 @@ func (c *FreeGOGCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
return nil, errors.New("failed to find magnet link")
}
item.Author = "FreeGOG"
item.Platform = "windows"
return item, nil
}

View File

@ -98,6 +98,7 @@ func (c *GOGGamesCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
item.Url = URL
item.Size = utils.BytesToSize(size)
item.Author = "GOGGames"
item.Platform = "windows"
return item, nil
}

66
crawler/johncena141.go Normal file
View File

@ -0,0 +1,66 @@
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)
}

View File

@ -21,6 +21,7 @@ func NewKaOsKrewCrawler(logger *zap.Logger) *KaOsKrewCrawler {
logger: logger,
crawler: *New1337xCrawler(
KaOsKrewName,
"windows",
KaOsKrewFormatter,
logger,
),

View File

@ -178,6 +178,7 @@ func (c *OnlineFixCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
} else {
return nil, errors.New("failed to find download link")
}
item.Platform = "windows"
return item, nil
}

View File

@ -47,6 +47,7 @@ func (c *SteamRIPCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
item.Name = SteamRIPFormatter(item.RawName)
item.Url = URL
item.Author = "SteamRIP"
item.Platform = "windows"
sizeRegex := regexp.MustCompile(`(?i)<li><strong>Game Size:\s?</strong>(.*?)</li>`)
sizeRegexRes := sizeRegex.FindStringSubmatch(string(resp.Body()))
if len(sizeRegexRes) != 0 {

View File

@ -96,6 +96,7 @@ func (c *XatabCrawler) CrawlByUrl(URL string) (*model.GameItem, error) {
item.Name = XatabFormatter(item.RawName)
item.Author = "Xatab"
item.UpdateFlag = item.RawName
item.Platform = "windows"
downloadURL := doc.Find("#download>a").First().AttrOr("href", "")
if downloadURL == "" {
return nil, errors.New("failed to find download URL")

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -34,6 +34,7 @@ type GameItem struct {
Url string `json:"url" bson:"url"`
Password string `json:"password,omitempty" bson:"password"`
Author string `json:"author,omitempty" bson:"author"`
Platform string `json:"platform,omitempty" bson:"platform"`
UpdateFlag string `json:"-" bson:"update_flag,omitempty"`
CreatedAt time.Time `json:"created_at" bson:"created_at"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at"`

View File

@ -143,11 +143,21 @@
<small class="text-muted">Source: {{.Author}}</small>
</div>
{{end}}
{{if .Platform}}
<div class="card-text">
<small class="text-muted">Platform: {{.Platform}}</small>
</div>
{{end}}
{{if .Password}}
<div class="card-text">
<small class="text-muted">Unzip password: <code>{{.Password}}</code></small>
</div>
{{end}}
{{if .UpdatedAt}}
<div class="card-text">
<small class="text-muted">Updated: {{.UpdatedAt}}</small>
</div>
{{end}}
<div class="mt-2 d-flex justify-content-between align-items-center">
<div class="input-group" style="max-width: 300px;">
<input type="text" class="form-control form-control-sm" value="{{.Download}}" readonly>