feat(indexers): GGn improve release name parsing (#1366)

* feat(indexers): GGn improve IRC parsing

* chore: organize imports
This commit is contained in:
ze0s 2024-01-24 17:58:46 +01:00 committed by GitHub
parent dea0b32b89
commit fffd5bbf56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 435 additions and 403 deletions

View file

@ -6,6 +6,7 @@ package domain
import (
"context"
"encoding/json"
"strings"
"time"
)
@ -137,3 +138,82 @@ type IrcRepo interface {
GetNetworkByID(ctx context.Context, id int64) (*IrcNetwork, error)
DeleteNetwork(ctx context.Context, id int64) error
}
type IRCParser interface {
Parse(rls *Release, vars map[string]string) error
}
type IRCParserDefault struct{}
func (p IRCParserDefault) Parse(rls *Release, _ map[string]string) error {
// parse fields
// run before ParseMatch to not potentially use a reconstructed TorrentName
rls.ParseString(rls.TorrentName)
return nil
}
type IRCParserGazelleGames struct{}
func (p IRCParserGazelleGames) Parse(rls *Release, vars map[string]string) error {
torrentName := vars["torrentName"]
category := vars["category"]
releaseName := ""
title := ""
switch category {
case "OST":
// OST does not have the Title in Group naming convention
releaseName = torrentName
default:
releaseName, title = splitInMiddle(torrentName, " in ")
if releaseName == "" && title != "" {
releaseName = torrentName
}
}
rls.ParseString(releaseName)
if title != "" {
rls.Title = title
}
return nil
}
type IRCParserOrpheus struct{}
func (p IRCParserOrpheus) Parse(rls *Release, vars map[string]string) error {
// OPS uses en-dashes as separators, which causes moistari/rls to not parse the torrentName properly,
// we replace the en-dashes with hyphens here
torrentName := vars["torrentName"]
rls.TorrentName = strings.ReplaceAll(torrentName, "", "-")
rls.ParseString(rls.TorrentName)
return nil
}
// mergeVars merge maps
func mergeVars(data ...map[string]string) map[string]string {
tmpVars := map[string]string{}
for _, vars := range data {
// copy vars to new tmp map
for k, v := range vars {
tmpVars[k] = v
}
}
return tmpVars
}
// splitInMiddle utility for GGn that tries to split the announced release name
// torrent name consists of "This.Game-GRP in This Game Group" but titles can include "in"
// this function tries to split in the correct place
func splitInMiddle(s, sep string) (string, string) {
parts := strings.Split(s, sep)
l := len(parts)
return strings.Join(parts[:l/2], sep), strings.Join(parts[l/2:], sep)
}