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) } }
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) } }