Skip to content

Commit 7b89c5f

Browse files
authored
Fix: Remove Invalid dir symobl (#35)
* chore(util): add replace string chars func * fix(dl): remove invalid dir_name symbol * fix: fix linting issue
1 parent f28c4df commit 7b89c5f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

internal/resolvers/hanime1me/hanime1me.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ func (re *resolver) Resolve(u string, opt *resolvers.Option) ([]*resolvers.HAnim
9696
return res, nil
9797
}
9898

99+
func removeDirInvalidSymbol(title string) string {
100+
return util.ReplaceChars(title, util.InvalidDirSymbols[:])
101+
}
102+
99103
func resolvePlaylist(u string) ([]*resolvers.HAnime, error) {
100104
doc, err := util.GetHTMLPage(newClient(), u, map[string]string{"User-Agent": resolvers.UA})
101105
if err != nil {
@@ -217,6 +221,7 @@ func getDLInfo(vid string) (map[string]*resolvers.Video, []string, error) {
217221
for _, a := range aTags {
218222
link := util.GetAttrVal(a, "href")
219223
title := util.GetAttrVal(a, "download")
224+
title = removeDirInvalidSymbol(title) // remove invalid symbols
220225

221226
id := getID(link)
222227
quality := ""

pkg/util/str.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package util
2+
3+
import "strings"
4+
5+
var InvalidDirSymbols = [10]rune{'/', '<', '>', ':', '"', '/', '\\', '|', '?', '*'}
6+
7+
func ReplaceChars(str string, chars []rune) string {
8+
strs := make([]string, 0, 20) //nolint:gomnd
9+
for _, c := range chars {
10+
strs = append(strs, string(c), "")
11+
}
12+
r := strings.NewReplacer(strs...)
13+
return r.Replace(str)
14+
}

0 commit comments

Comments
 (0)