Exemplo n.º 1
0
func main() {
	opts, err := docopt.Parse("Usage: torrent-create <root>", nil, true, "", true)
	if err != nil {
		panic(err)
	}
	root := opts["<root>"].(string)
	mi := metainfo.MetaInfo{
		AnnounceList: builtinAnnounceList,
	}
	mi.SetDefaults()
	err = mi.Info.BuildFromFilePath(root)
	if err != nil {
		log.Fatal(err)
	}
	err = mi.Info.GeneratePieces(func(fi metainfo.FileInfo) (io.ReadCloser, error) {
		return os.Open(filepath.Join(root, strings.Join(fi.Path, string(filepath.Separator))))
	})
	if err != nil {
		log.Fatalf("error generating pieces: %s", err)
	}
	err = mi.Write(os.Stdout)
	if err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 2
0
// Writes to w, a metainfo containing the file at name.
func CreateMetaInfo(name string, w io.Writer) {
	var mi metainfo.MetaInfo
	mi.Info.Name = filepath.Base(name)
	fi, _ := os.Stat(name)
	mi.Info.Length = fi.Size()
	mi.Announce = "lol://cheezburger"
	mi.Info.PieceLength = 5
	err := mi.Info.GeneratePieces(func(metainfo.FileInfo) (io.ReadCloser, error) {
		return os.Open(name)
	})
	if err != nil {
		panic(err)
	}
	err = mi.Write(w)
	if err != nil {
		panic(err)
	}
}
Exemplo n.º 3
0
func main() {
	log.SetFlags(log.Flags() | log.Lshortfile)
	var args struct {
		AnnounceList []string `name:"a" help:"extra announce-list tier entry"`
		tagflag.StartPos
		Root string
	}
	tagflag.Parse(&args, tagflag.Description("Creates a torrent metainfo for the file system rooted at ROOT, and outputs it to stdout."))
	mi := metainfo.MetaInfo{
		AnnounceList: builtinAnnounceList,
	}
	for _, a := range args.AnnounceList {
		mi.AnnounceList = append(mi.AnnounceList, []string{a})
	}
	mi.SetDefaults()
	err := mi.Info.BuildFromFilePath(args.Root)
	if err != nil {
		log.Fatal(err)
	}
	err = mi.Write(os.Stdout)
	if err != nil {
		log.Fatal(err)
	}
}