2024-09-24 06:17:11 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2024-11-20 06:09:04 -05:00
|
|
|
"pcgamedb/crawler"
|
|
|
|
"pcgamedb/db"
|
|
|
|
"pcgamedb/log"
|
2024-11-15 02:02:45 -05:00
|
|
|
|
2024-09-24 06:17:11 -04:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
var formatCmd = &cobra.Command{
|
|
|
|
Use: "format",
|
|
|
|
Short: "Format game downloads name by formatter",
|
|
|
|
Long: "Format game downloads name by formatter",
|
|
|
|
Run: formatRun,
|
|
|
|
}
|
|
|
|
|
|
|
|
type FormatCommandConfig struct {
|
|
|
|
Source string
|
|
|
|
}
|
|
|
|
|
|
|
|
var formatCmdCfg FormatCommandConfig
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
formatCmd.Flags().StringVarP(&formatCmdCfg.Source, "source", "s", "", "source to fix (fitgirl/dodi/kaoskrew/freegog/xatab/onlinefix/armgddn)")
|
|
|
|
RootCmd.AddCommand(formatCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func formatRun(cmd *cobra.Command, args []string) {
|
|
|
|
formatCmdCfg.Source = strings.ToLower(formatCmdCfg.Source)
|
|
|
|
switch formatCmdCfg.Source {
|
|
|
|
case "dodi":
|
2024-11-16 00:48:48 -05:00
|
|
|
items, err := db.GetDODIGameItems()
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to get games", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, item := range items {
|
|
|
|
oldName := item.Name
|
|
|
|
item.Name = crawler.DODIFormatter(item.RawName)
|
|
|
|
if oldName != item.Name {
|
|
|
|
log.Logger.Info("Fix name", zap.String("old", oldName), zap.String("raw", item.RawName), zap.String("name", item.Name))
|
2024-11-16 00:48:48 -05:00
|
|
|
err := db.SaveGameItem(item)
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to update item", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "kaoskrew":
|
2024-11-16 00:48:48 -05:00
|
|
|
items, err := db.GetKaOsKrewGameItems()
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to get games", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, item := range items {
|
|
|
|
oldName := item.Name
|
|
|
|
item.Name = crawler.KaOsKrewFormatter(item.RawName)
|
|
|
|
if oldName != item.Name {
|
|
|
|
log.Logger.Info("Fix name", zap.String("old", oldName), zap.String("raw", item.RawName), zap.String("name", item.Name))
|
2024-11-16 00:48:48 -05:00
|
|
|
err := db.SaveGameItem(item)
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to update item", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "freegog":
|
2024-11-16 00:48:48 -05:00
|
|
|
items, err := db.GetFreeGOGGameItems()
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to get games", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, item := range items {
|
|
|
|
oldName := item.Name
|
|
|
|
item.Name = crawler.FreeGOGFormatter(item.RawName)
|
|
|
|
if oldName != item.Name {
|
|
|
|
log.Logger.Info("Fix name", zap.String("old", oldName), zap.String("raw", item.RawName), zap.String("name", item.Name))
|
2024-11-16 00:48:48 -05:00
|
|
|
err := db.SaveGameItem(item)
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to update item", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "xatab":
|
2024-11-16 00:48:48 -05:00
|
|
|
items, err := db.GetXatabGameItems()
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to get games", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, item := range items {
|
|
|
|
oldName := item.Name
|
|
|
|
item.Name = crawler.XatabFormatter(item.RawName)
|
|
|
|
if oldName != item.Name {
|
|
|
|
log.Logger.Info("Fix name", zap.String("old", oldName), zap.String("raw", item.RawName), zap.String("name", item.Name))
|
2024-11-16 00:48:48 -05:00
|
|
|
err := db.SaveGameItem(item)
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to update item", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "onlinefix":
|
2024-11-16 00:48:48 -05:00
|
|
|
items, err := db.GetOnlineFixGameItems()
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to get games", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, item := range items {
|
|
|
|
oldName := item.Name
|
|
|
|
item.Name = crawler.OnlineFixFormatter(item.RawName)
|
|
|
|
if oldName != item.Name {
|
|
|
|
log.Logger.Info("Fix name", zap.String("old", oldName), zap.String("raw", item.RawName), zap.String("name", item.Name))
|
2024-11-16 00:48:48 -05:00
|
|
|
err := db.SaveGameItem(item)
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to update item", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "armgddn":
|
2024-11-16 00:48:48 -05:00
|
|
|
items, err := db.GetARMGDDNGameItems()
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to get games", zap.Error(err))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, item := range items {
|
|
|
|
oldName := item.Name
|
|
|
|
item.Name = crawler.ARMGDDNFormatter(item.RawName)
|
|
|
|
if oldName != item.Name {
|
|
|
|
log.Logger.Info("Fix name", zap.String("old", oldName), zap.String("raw", item.RawName), zap.String("name", item.Name))
|
2024-11-16 00:48:48 -05:00
|
|
|
err := db.SaveGameItem(item)
|
2024-09-24 06:17:11 -04:00
|
|
|
if err != nil {
|
|
|
|
log.Logger.Error("Failed to update item", zap.Error(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|