2
0
mirror of synced 2025-02-24 22:58:28 +00:00

60 lines
1.1 KiB
Go
Raw Normal View History

package main
import (
"flag"
"github.com/nsf/libtorgo/torrent"
"log"
"os"
"path/filepath"
"runtime"
)
var (
builtinAnnounceGroups = [][]string{{"udp://tracker.openbittorrent.com:80"}, {"udp://tracker.publicbt.com:80"}, {"udp://tracker.istole.it:6969"}}
)
func init() {
flag.Parse()
runtime.GOMAXPROCS(runtime.NumCPU())
}
func main() {
b := torrent.Builder{}
for _, filename := range flag.Args() {
if err := filepath.Walk(filename, func(path string, info os.FileInfo, err error) error {
log.Print(path)
if info.IsDir() {
return nil
}
b.AddFile(path)
return nil
}); err != nil {
log.Print(err)
}
}
for _, group := range builtinAnnounceGroups {
b.AddAnnounceGroup(group)
}
batch, err := b.Submit()
if err != nil {
log.Fatal(err)
}
errs, status := batch.Start(os.Stdout, runtime.NumCPU())
lastProgress := int64(-1)
for {
select {
case err, ok := <-errs:
if !ok || err == nil {
return
}
log.Print(err)
case bytesDone := <-status:
progress := 100 * bytesDone / batch.TotalSize()
if progress != lastProgress {
log.Printf("%d%%", progress)
lastProgress = progress
}
}
}
}