mirror of
https://github.com/rumanzo/bt2qbt.git
synced 2024-09-20 07:41:40 +02:00
Right piece field len
This commit is contained in:
parent
b9b12c755f
commit
638d80786c
23
bt2qbt.go
23
bt2qbt.go
@ -154,7 +154,7 @@ type NewTorrentStructure struct {
|
|||||||
torrentfilepath string
|
torrentfilepath string
|
||||||
torrentfile map[string]interface{}
|
torrentfile map[string]interface{}
|
||||||
path string
|
path string
|
||||||
filesizes float64
|
filesizes int64
|
||||||
sizeandprio [][]int64
|
sizeandprio [][]int64
|
||||||
torrentfilelist []string
|
torrentfilelist []string
|
||||||
npieces int64
|
npieces int64
|
||||||
@ -231,7 +231,7 @@ func (newstructure *NewTorrentStructure) prioconvert(src string) {
|
|||||||
|
|
||||||
func (newstructure *NewTorrentStructure) fillmissing() {
|
func (newstructure *NewTorrentStructure) fillmissing() {
|
||||||
newstructure.ifcompletedon()
|
newstructure.ifcompletedon()
|
||||||
newstructure.getnpieces()
|
newstructure.fillsizes()
|
||||||
newstructure.fillsavepaths()
|
newstructure.fillsavepaths()
|
||||||
if newstructure.Unfinished != nil {
|
if newstructure.Unfinished != nil {
|
||||||
newstructure.Pieces = newstructure.fillnothavefiles("0")
|
newstructure.Pieces = newstructure.fillnothavefiles("0")
|
||||||
@ -263,7 +263,7 @@ func (newstructure *NewTorrentStructure) fillsizes() {
|
|||||||
filename := strings.Join(filestrings, string(os.PathSeparator))
|
filename := strings.Join(filestrings, string(os.PathSeparator))
|
||||||
newstructure.torrentfilelist = append(newstructure.torrentfilelist, filename)
|
newstructure.torrentfilelist = append(newstructure.torrentfilelist, filename)
|
||||||
fullpath := newstructure.path + string(os.PathSeparator) + filename
|
fullpath := newstructure.path + string(os.PathSeparator) + filename
|
||||||
newstructure.filesizes += float64(file.(map[string]interface{})["length"].(int64))
|
newstructure.filesizes += file.(map[string]interface{})["length"].(int64)
|
||||||
if n := newstructure.File_priority[num]; n != 0 {
|
if n := newstructure.File_priority[num]; n != 0 {
|
||||||
lenght = file.(map[string]interface{})["length"].(int64)
|
lenght = file.(map[string]interface{})["length"].(int64)
|
||||||
newstructure.sizeandprio = append(newstructure.sizeandprio, []int64{lenght, 1})
|
newstructure.sizeandprio = append(newstructure.sizeandprio, []int64{lenght, 1})
|
||||||
@ -277,20 +277,11 @@ func (newstructure *NewTorrentStructure) fillsizes() {
|
|||||||
}
|
}
|
||||||
newstructure.Filesizes = filelists
|
newstructure.Filesizes = filelists
|
||||||
} else {
|
} else {
|
||||||
newstructure.filesizes = float64(newstructure.torrentfile["info"].(map[string]interface{})["length"].(int64))
|
newstructure.filesizes = newstructure.torrentfile["info"].(map[string]interface{})["length"].(int64)
|
||||||
newstructure.Filesizes = [][]int64{{newstructure.torrentfile["info"].(map[string]interface{})["length"].(int64), fmtime(newstructure.path)}}
|
newstructure.Filesizes = [][]int64{{newstructure.torrentfile["info"].(map[string]interface{})["length"].(int64), fmtime(newstructure.path)}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (newstructure *NewTorrentStructure) getnpieces() {
|
|
||||||
newstructure.fillsizes()
|
|
||||||
if ((newstructure.filesizes / float64(newstructure.piecelenght)) - float64((int64(newstructure.filesizes) / newstructure.piecelenght))) != 0 { // check fraction
|
|
||||||
newstructure.npieces = int64(newstructure.filesizes)/newstructure.torrentfile["info"].(map[string]interface{})["piece length"].(int64) + 1
|
|
||||||
} else {
|
|
||||||
newstructure.npieces = int64(newstructure.filesizes) / newstructure.torrentfile["info"].(map[string]interface{})["piece length"].(int64)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (newstructure *NewTorrentStructure) fillnothavefiles(chr string) []byte {
|
func (newstructure *NewTorrentStructure) fillnothavefiles(chr string) []byte {
|
||||||
var newpieces = make([]byte, 0, newstructure.npieces)
|
var newpieces = make([]byte, 0, newstructure.npieces)
|
||||||
for i := int64(0); i < newstructure.npieces; i++ {
|
for i := int64(0); i < newstructure.npieces; i++ {
|
||||||
@ -417,6 +408,12 @@ func logic(key string, value map[string]interface{}, bitdir *string, with_label
|
|||||||
newstructure.prioconvert(value["prio"].(string))
|
newstructure.prioconvert(value["prio"].(string))
|
||||||
newstructure.Blockperpiece = newstructure.torrentfile["info"].(map[string]interface{})["piece length"].(int64) / 16 / 1024 // https://libtorrent.org/manual-ref.html#fast-resume
|
newstructure.Blockperpiece = newstructure.torrentfile["info"].(map[string]interface{})["piece length"].(int64) / 16 / 1024 // https://libtorrent.org/manual-ref.html#fast-resume
|
||||||
newstructure.piecelenght = newstructure.torrentfile["info"].(map[string]interface{})["piece length"].(int64)
|
newstructure.piecelenght = newstructure.torrentfile["info"].(map[string]interface{})["piece length"].(int64)
|
||||||
|
/*
|
||||||
|
pieces maps to a string whose length is a multiple of 20. It is to be subdivided into strings of length 20,
|
||||||
|
each of which is the SHA1 hash of the piece at the corresponding index.
|
||||||
|
http://www.bittorrent.org/beps/bep_0003.html
|
||||||
|
*/
|
||||||
|
newstructure.npieces = int64(len(newstructure.torrentfile["info"].(map[string]interface{})["pieces"].(string))) / 20
|
||||||
newstructure.fillmissing()
|
newstructure.fillmissing()
|
||||||
newbasename := newstructure.gethash()
|
newbasename := newstructure.gethash()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user