From 13372baffd63abb77716e5b148ed853e182a2feb Mon Sep 17 00:00:00 2001 From: Alexey Kostin Date: Tue, 10 Apr 2018 00:26:23 +0300 Subject: [PATCH] Fix for paths. Fix for non utf-8 torrent names and paths --- b2q.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/b2q.go b/b2q.go index d4258c7..102efb2 100644 --- a/b2q.go +++ b/b2q.go @@ -202,6 +202,9 @@ func logic(key string, value map[string]interface{}, bitdir *string, with_label } else { hasfiles = false } + if value["path"].(string)[len(value["path"].(string))-1] == os.PathSeparator { + value["path"] = value["path"].(string)[:len(value["path"].(string))-1] + } filesizes := float32(0) var sizeandprio [][]int64 var torrentfilelist []string @@ -209,7 +212,17 @@ func logic(key string, value map[string]interface{}, bitdir *string, with_label var filelists []interface{} for num, file := range files.([]interface{}) { var lenght, mtime int64 - filename := file.(map[string]interface{})["path"].([]interface{})[0].(string) + var filestrings []string + if path, ok := file.(map[string]interface{})["path.utf-8"].([]interface{}); ok { + for _, f := range path { + filestrings = append(filestrings, f.(string)) + } + } else { + for _, f := range file.(map[string]interface{})["path"].([]interface{}) { + filestrings = append(filestrings, f.(string)) + } + } + filename := strings.Join(filestrings, string(os.PathSeparator)) torrentfilelist = append(torrentfilelist, filename) fullpath := value["path"].(string) + "\\" + filename filesizes += float32(file.(map[string]interface{})["length"].(int64)) @@ -242,7 +255,12 @@ func logic(key string, value map[string]interface{}, bitdir *string, with_label } else { newstructure["pieces"] = fillnothavefiles(&npieces) } - torrentname := torrentfile["info"].(map[string]interface{})["name"].(string) + var torrentname string + if name, ok := torrentfile["info"].(map[string]interface{})["name.utf-8"].(string); ok { + torrentname = name + } else { + torrentname = torrentfile["info"].(map[string]interface{})["name"].(string) + } origpath := value["path"].(string) _, lastdirname := filepath.Split(strings.Replace(origpath, "\\", "/", -1)) if hasfiles {