Skip to content

Commit cf3e773

Browse files
committed
fix torrent tag issues with non-alphanumeric characters
1 parent d32b012 commit cf3e773

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

internal/parser/title.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,30 @@ func (t Metadata) TagBuildSeasonEpisode() string {
101101
return resp
102102
}
103103

104+
func filterAlphanumeric(s string) string {
105+
var result strings.Builder
106+
result.Grow(len(s))
107+
for i := 0; i < len(s); i++ {
108+
b := s[i]
109+
if ('a' <= b && b <= 'z') || ('A' <= b && b <= 'Z') || ('0' <= b && b <= '9') || b == ' ' {
110+
result.WriteByte(b)
111+
}
112+
}
113+
return result.String()
114+
}
115+
116+
func (t Metadata) buildTitle() string {
117+
return strings.ToLower(filterAlphanumeric(t.Title))
118+
}
119+
104120
// TagBuildBatch is used for when you download a torrent with multiple episodes.
105121
func (t Metadata) TagBuildBatch() string {
106-
return fmt.Sprintf("%s S%s batch", strings.ToLower(t.Title), t.Season)
122+
return fmt.Sprintf("%s S%s batch", t.buildTitle(), t.Season)
107123
}
108124

109125
// TagBuildSeries builds a !Serie Name tag for you to be able to search all it's episodes with a tag.
110126
func (t Metadata) TagBuildSeries() string {
111-
return "!" + strings.ToLower(t.Title)
127+
return "!" + t.buildTitle()
112128
}
113129

114130
// TagsBuildTorrent builds all tags Animeman needs from your torrent client.

0 commit comments

Comments
 (0)