Fix removing path separator from utorrent path field

This commit is contained in:
rumanzo 2021-05-07 17:38:38 +03:00
parent f421df467c
commit f7c5d00b94

View File

@ -22,6 +22,7 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"unicode/utf8"
) )
type Flags struct { type Flags struct {
@ -203,11 +204,16 @@ func logic(key string, value map[string]interface{}, flags *Flags, chans *Channe
} else { } else {
newstructure.HasFiles = false newstructure.HasFiles = false
} }
if value["path"].(string)[len(value["path"].(string))-1] == os.PathSeparator {
newstructure.Path = value["path"].(string)[:len(value["path"].(string))-1] // remove separator from end
lastRune, lastRuneSize := utf8.DecodeLastRuneInString(value["path"].(string))
separatorRunes := []rune("/\\")
if lastRune == separatorRunes[0] || lastRune == separatorRunes[1] {
newstructure.Path = value["path"].(string)[:len(value["path"].(string))-lastRuneSize]
} else { } else {
newstructure.Path = value["path"].(string) newstructure.Path = value["path"].(string)
} }
// if torrent name was renamed, add modified name // if torrent name was renamed, add modified name
if value["caption"] != nil { if value["caption"] != nil {
newstructure.QbtName = value["caption"].(string) newstructure.QbtName = value["caption"].(string)