From 8f995006b14c595e394c1762e54693ac06c09120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejo=20Gait=C3=A1n?= Date: Tue, 16 Jul 2024 19:39:29 -0300 Subject: [PATCH] fix(indexers): OPS log score parsing (#1592) * fix(parsing): OPS Missing % The message from OPS Announce does not contain a % sign and that seemed to break it. This is probably not the best fix but it is something. * fix(parsing): Join Tags and Remove Unnecessary Char Replacement Forgot to join tags before parsing, and removed an unnecessary char replacement that was not needed. * fix(parsing): Added Regex for 0-100 I forgot to check for all score values, also added the regex import * feat: add test cases for OPS log score parsing --------- Co-authored-by: ze0s --- internal/domain/irc.go | 15 ++++++++++++ internal/indexer/indexer_test.go | 42 +++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/internal/domain/irc.go b/internal/domain/irc.go index 26ce8fa..7a67c92 100644 --- a/internal/domain/irc.go +++ b/internal/domain/irc.go @@ -7,6 +7,7 @@ import ( "context" "encoding/json" "fmt" + "regexp" "strings" "time" ) @@ -207,6 +208,20 @@ func (p IRCParserOrpheus) Parse(rls *Release, vars map[string]string) error { year := vars["year"] releaseTagsString := vars["releaseTags"] + splittedTags := strings.Split(releaseTagsString, "/") + + // Check and replace the last tag if it's a number between 0 and 100 + if len(splittedTags) > 0 { + lastTag := splittedTags[len(splittedTags)-1] + match, _ := regexp.MatchString(`^\d{1,2}$|^100$`, lastTag) + if match { + splittedTags[len(splittedTags)-1] = lastTag + "%" + } + } + + // Join tags back into a string + releaseTagsString = strings.Join(splittedTags, " ") + //cleanTags := strings.ReplaceAll(releaseTagsString, "/", " ") cleanTags := CleanReleaseTags(releaseTagsString) diff --git a/internal/indexer/indexer_test.go b/internal/indexer/indexer_test.go index 9dff652..5fc4f36 100644 --- a/internal/indexer/indexer_test.go +++ b/internal/indexer/indexer_test.go @@ -79,7 +79,7 @@ func TestIndexersParseAndFilter(t *testing.T) { { name: "announce_2", args: args{ - announceLines: []string{"TORRENT: Dirty Dike – Bogies & Alcohol – [2024] [EP] CD/FLAC/Lossless – hip.hop,uk.hip.hop,united.kingdom – https://orpheus.network/torrents.php?id=0000000 – https://orpheus.network/torrents.php?id=0000000&torrentid=0000000&action=download"}, + announceLines: []string{"TORRENT: Dirty Dike – Bogies & Alcohol – [2024] [EP] CD/FLAC/Lossless/Cue/Log/100 – hip.hop,uk.hip.hop,united.kingdom – https://orpheus.network/torrents.php?id=0000000 – https://orpheus.network/torrents.php?id=0000000&torrentid=0000000&action=download"}, filters: []filterTest{ { filter: &domain.Filter{ @@ -94,6 +94,22 @@ func TestIndexersParseAndFilter(t *testing.T) { }, match: true, }, + { + filter: &domain.Filter{ + Name: "filter_1", + MatchCategories: "EP,Album", + Years: "2024", + Quality: []string{"Lossless"}, + Sources: []string{"CD"}, + Formats: []string{"FLAC"}, + Log: true, + LogScore: 100, + PerfectFlac: true, + Artists: "Dirty Dike", + Albums: "Bogies & Alcohol", + }, + match: true, + }, { filter: &domain.Filter{ Name: "filter_2", @@ -111,6 +127,30 @@ func TestIndexersParseAndFilter(t *testing.T) { }, match: false, }, + { + name: "announce_3", + args: args{ + announceLines: []string{"TORRENT: Dirty Dike – Bogies & Alcohol – [2024] [EP] CD/FLAC/Lossless/Cue/Log/80 – hip.hop,uk.hip.hop,united.kingdom – https://orpheus.network/torrents.php?id=0000000 – https://orpheus.network/torrents.php?id=0000000&torrentid=0000000&action=download"}, + filters: []filterTest{ + { + filter: &domain.Filter{ + Name: "filter_1", + MatchCategories: "EP,Album", + Years: "2024", + Quality: []string{"24bit Lossless"}, + Sources: []string{"CD"}, + Formats: []string{"FLAC"}, + Log: true, + LogScore: 100, + Albums: "Best album", + }, + match: false, + rejections: []string{"albums not matching. got: Bogies & Alcohol want: Best album", "quality not matching. got: [Cue FLAC Lossless Log80 Log] want: [24bit Lossless]", "log score. got 80 want: 100"}, + }, + }, + }, + match: false, + }, }, match: true, },