mirror of
https://github.com/rumanzo/bt2qbt.git
synced 2024-11-22 10:22:38 +01:00
Add ability to transfer torrents with renamed files
This commit is contained in:
parent
e1c226eb89
commit
10551a7d24
@ -163,6 +163,7 @@ func logic(key string, value map[string]interface{}, flags *Flags, chans *Channe
|
|||||||
WithoutLabels: flags.WithoutLabels,
|
WithoutLabels: flags.WithoutLabels,
|
||||||
WithoutTags: flags.WithoutTags,
|
WithoutTags: flags.WithoutTags,
|
||||||
Separator: flags.PathSeparator,
|
Separator: flags.PathSeparator,
|
||||||
|
Targets: map[int64]string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
if isAbs, _ := regexp.MatchString(`^([A-Za-z]:)?\\`, key); isAbs == true {
|
if isAbs, _ := regexp.MatchString(`^([A-Za-z]:)?\\`, key); isAbs == true {
|
||||||
@ -206,6 +207,12 @@ func logic(key string, value map[string]interface{}, flags *Flags, chans *Channe
|
|||||||
newstructure.HasFiles = false
|
newstructure.HasFiles = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ok := value["targets"]; ok != nil {
|
||||||
|
for _, entry := range value["targets"].([]interface{}) {
|
||||||
|
newstructure.Targets[entry.([]interface{})[0].(int64)] = entry.([]interface{})[1].(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// remove separator from end
|
// remove separator from end
|
||||||
lastRune, lastRuneSize := utf8.DecodeLastRuneInString(value["path"].(string))
|
lastRune, lastRuneSize := utf8.DecodeLastRuneInString(value["path"].(string))
|
||||||
separatorRunes := []rune("/\\")
|
separatorRunes := []rune("/\\")
|
||||||
|
@ -72,6 +72,7 @@ type NewTorrentStructure struct {
|
|||||||
PieceLenght int64 `bencode:"-"`
|
PieceLenght int64 `bencode:"-"`
|
||||||
Replace []replace.Replace `bencode:"-"`
|
Replace []replace.Replace `bencode:"-"`
|
||||||
Separator string `bencode:"-"`
|
Separator string `bencode:"-"`
|
||||||
|
Targets map[int64]string `bencode:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (newstructure *NewTorrentStructure) Started(started int64) {
|
func (newstructure *NewTorrentStructure) Started(started int64) {
|
||||||
@ -173,12 +174,21 @@ func (newstructure *NewTorrentStructure) FillSizes() {
|
|||||||
for num, file := range newstructure.TorrentFile["info"].(map[string]interface{})["files"].([]interface{}) {
|
for num, file := range newstructure.TorrentFile["info"].(map[string]interface{})["files"].([]interface{}) {
|
||||||
var lenght, mtime int64
|
var lenght, mtime int64
|
||||||
var filestrings []string
|
var filestrings []string
|
||||||
if path, ok := file.(map[string]interface{})["path.utf-8"].([]interface{}); ok {
|
var mappedPath []interface{}
|
||||||
for _, f := range path {
|
if paths, ok := file.(map[string]interface{})["path.utf-8"].([]interface{}); ok {
|
||||||
filestrings = append(filestrings, f.(string))
|
mappedPath = paths
|
||||||
|
} else {
|
||||||
|
mappedPath = file.(map[string]interface{})["path"].([]interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
for n, f := range mappedPath {
|
||||||
|
if len(mappedPath)-1 == n && len(newstructure.Targets) > 0 {
|
||||||
|
for index, rewrittenFileName := range newstructure.Targets {
|
||||||
|
if index == int64(num) {
|
||||||
|
filestrings = append(filestrings, rewrittenFileName)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, f := range file.(map[string]interface{})["path"].([]interface{}) {
|
|
||||||
filestrings = append(filestrings, f.(string))
|
filestrings = append(filestrings, f.(string))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -264,6 +274,15 @@ func (newstructure *NewTorrentStructure) FillSavePaths() {
|
|||||||
if lastdirname == torrentname {
|
if lastdirname == torrentname {
|
||||||
newstructure.QbthasRootFolder = 1
|
newstructure.QbthasRootFolder = 1
|
||||||
newstructure.QbtSavePath = origpath[0 : len(origpath)-len(lastdirname)]
|
newstructure.QbtSavePath = origpath[0 : len(origpath)-len(lastdirname)]
|
||||||
|
if len(newstructure.Targets) > 0 {
|
||||||
|
for _, path := range newstructure.torrentFileList {
|
||||||
|
if len(path) > 0 {
|
||||||
|
newstructure.MappedFiles = append(newstructure.MappedFiles, lastdirname+newstructure.Separator+path)
|
||||||
|
} else {
|
||||||
|
newstructure.MappedFiles = append(newstructure.MappedFiles, path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
newstructure.QbthasRootFolder = 0
|
newstructure.QbthasRootFolder = 0
|
||||||
newstructure.QbtSavePath = newstructure.Path + newstructure.Separator
|
newstructure.QbtSavePath = newstructure.Path + newstructure.Separator
|
||||||
|
Loading…
Reference in New Issue
Block a user