New structures. Prelight for choice

This commit is contained in:
Alexey Kostin 2017-12-28 16:28:16 +03:00
parent 8c5a982eaf
commit 7f88b92772

25
b2q.go
View File

@ -16,6 +16,7 @@ import (
"bufio"
//"unicode/utf8"
"strconv"
"time"
)
func decodetorrentfile(path string) map[string]interface{} {
@ -68,15 +69,15 @@ func piecesconvert(s []byte ) (newpieces []byte) {
return
}
func logic(key string, value interface{}, bitdir *string, wg *sync.WaitGroup) {
func logic(key string, value interface{}, bitdir *string, wg *sync.WaitGroup, with_label *bool, with_tags *bool) {
defer wg.Done()
newstructure := map[string]interface{}{"active_time": 0, "added_time": 0, "announce_to_dht": 0,
"announce_to_lsd": 0, "announce_to_trackers": 0, "auto_managed": 0,
"banned_peers": new(string), "banned_peers6": new(string), "blocks per piece": 0,
"completed_time": 0, "download_rate_limit": 0, "file sizes": new([][]int),
"file-format": "libtorrent resume file", "file-version": 0, "file_priority": new([]int), "finished_time": 0,
"completed_time": 0, "download_rate_limit": -1, "file sizes": new([][]int),
"file-format": "libtorrent resume file", "file-version": 1, "file_priority": new([]int), "finished_time": 0,
"info-hash": new([]byte), "last_seen_complete": 0, "libtorrent-version": "1.1.5.0",
"max_connections": 0, "max_uploads": 0, "num_complete": 0, "num_downloaded": 0,
"max_connections": 100, "max_uploads": 100, "num_complete": 0, "num_downloaded": 0,
"num_incomplete": 0, "paused": 0, "peers": new(string), "peers6": new(string),
"pieces": new([]byte), "qBt-category": new(string), "qBt-hasRootFolder": 0, "qBt-name": new(string),
"qBt-queuePosition": 0, "qBt-ratioLimit": 0, "qBt-savePath": new(string),
@ -106,12 +107,23 @@ func logic(key string, value interface{}, bitdir *string, wg *sync.WaitGroup) {
files = append(files, strings.Join(newpath, "/"))
}
}
newstructure["active_time"] = local["runtime"]
newstructure["added_time"] = local["added_on"]
newstructure["completed_time"] = local["completed_on"]
newstructure["info-hash"] = local["info"]
newstructure["qBt-tags"] = local["labels"]
newstructure["blocks per piece"] = torrentfile["info"].(map[string]interface{})["piece length"].(int64) / local["blocksize"].(int64)
newstructure["pieces"] = piecesconvert([]byte(local["have"].(string)))
newstructure["seeding_time"] = local["runtime"]
if newstructure["paused"] = 0; local["started"] == 0 { newstructure["paused"] = 1 }
newstructure["finished_time"] = int(time.Since(time.Unix(local["completed_on"].(int64), 0)).Minutes())
if local["completed_on"] != 0 { newstructure["last_seen_complete"] = int(time.Now().Unix()) }
newstructure["total_downloaded"] = local["downloaded"]
newstructure["total_uploaded"] = local["uploaded"]
newstructure["upload_rate_limit"] = local["upspeed"]
if *with_label == true { newstructure["qBt-category"] = local["label"] }
if *with_tags == true { newstructure["qBt-tags"] = local["labels"] }
newstructure["trackers"] = [][]interface{}{local["trackers"].([]interface{})}
encodetorrentfile("F:/test.fastdecode", newstructure)
}
@ -122,10 +134,13 @@ func main() {
torrent := decodetorrentfile(bitfile)
var with_label, with_tags bool
with_label, with_tags = true, true
for key, value := range torrent {
if key != ".fileguard" && key != "rec" {
wg.Add(1)
go logic(key, value, &bitdir, &wg)
go logic(key, value, &bitdir, &wg, &with_label, &with_tags)
}
}
wg.Wait()