本文整理汇总了Golang中github.com/anacrolix/torrent/metainfo.Builder.AddAnnounceGroup方法的典型用法代码示例。如果您正苦于以下问题:Golang Builder.AddAnnounceGroup方法的具体用法?Golang Builder.AddAnnounceGroup怎么用?Golang Builder.AddAnnounceGroup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/anacrolix/torrent/metainfo.Builder
的用法示例。
在下文中一共展示了Builder.AddAnnounceGroup方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createTorrent
func (v Video) createTorrent() error {
log.Println("creating torrent")
f, err := os.Create(v.torrentFilename())
defer f.Close()
if err != nil {
return err
}
b := torrent.Builder{}
b.AddFile(v.OutputFilename)
for _, group := range builtinAnnounceList {
b.AddAnnounceGroup(group)
}
batch, err := b.Submit()
if err != nil {
log.Fatal(err)
}
errs, status := batch.Start(f, runtime.NumCPU())
lastProgress := int64(-1)
for {
select {
case err, ok := <-errs:
if !ok || err == nil {
return err
}
log.Print(err)
case bytesDone := <-status:
progress := 100 * bytesDone / batch.TotalSize()
if progress != lastProgress {
log.Printf("%d%%", progress)
lastProgress = progress
}
}
}
}
示例2: CreateMetaInfo
// Writes to w, a metainfo containing the file at name.
func CreateMetaInfo(name string, w io.Writer) {
builder := metainfo.Builder{}
builder.AddFile(name)
builder.AddAnnounceGroup([]string{"lol://cheezburger"})
builder.SetPieceLength(5)
batch, err := builder.Submit()
if err != nil {
panic(err)
}
errs, _ := batch.Start(w, 1)
<-errs
}
示例3: main
func main() {
b := torrent.Builder{}
for _, filename := range flag.Args() {
if err := filepath.Walk(filename, func(path string, info os.FileInfo, err error) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
return err
}
log.Print(path)
if info.IsDir() {
return nil
}
b.AddFile(path)
return nil
}); err != nil {
log.Print(err)
}
}
for _, group := range builtinAnnounceList {
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
}
}
}
}
示例4: CreateTorrent
func (b *Builtin) CreateTorrent(path, torrentPath string, trackers []string) (err error) {
builder := metainfo.Builder{}
builder.AddFile(path)
builder.AddAnnounceGroup(trackers)
batch, err := builder.Submit()
if err != nil {
return
}
torrentFile, err := os.Create(torrentPath)
if err != nil {
return
}
defer torrentFile.Close()
errs, _ := batch.Start(torrentFile, runtime.NumCPU())
err = <-errs
if err != nil {
return
}
return
}