Add announce and download commands to cmd/torrent
This commit is contained in:
parent
6920298770
commit
d3b6bcef97
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/anacrolix/tagflag"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
|
||||
"github.com/anacrolix/torrent"
|
||||
"github.com/anacrolix/torrent/tracker"
|
||||
)
|
||||
|
||||
func announceErr(args []string, parent *tagflag.Parser) error {
|
||||
var flags struct {
|
||||
tagflag.StartPos
|
||||
Tracker string
|
||||
InfoHash torrent.InfoHash
|
||||
}
|
||||
tagflag.ParseArgs(&flags, args, tagflag.Parent(parent))
|
||||
response, err := tracker.Announce{
|
||||
TrackerUrl: flags.Tracker,
|
||||
Request: tracker.AnnounceRequest{
|
||||
InfoHash: flags.InfoHash,
|
||||
Port: uint16(torrent.NewDefaultClientConfig().ListenPort),
|
||||
},
|
||||
}.Do()
|
||||
if err != nil {
|
||||
return fmt.Errorf("doing announce: %w", err)
|
||||
}
|
||||
spew.Dump(response)
|
||||
return nil
|
||||
}
|
|
@ -178,7 +178,24 @@ func main() {
|
|||
}
|
||||
|
||||
func mainErr() error {
|
||||
tagflag.Parse(&flags)
|
||||
var flags struct {
|
||||
tagflag.StartPos
|
||||
Command string
|
||||
Args tagflag.ExcessArgs
|
||||
}
|
||||
parser := tagflag.Parse(&flags, tagflag.ParseIntermixed(false))
|
||||
switch flags.Command {
|
||||
case "announce":
|
||||
return announceErr(flags.Args, parser)
|
||||
case "download":
|
||||
return downloadErr(flags.Args, parser)
|
||||
default:
|
||||
return fmt.Errorf("unknown command %q", flags.Command)
|
||||
}
|
||||
}
|
||||
|
||||
func downloadErr(args []string, parent *tagflag.Parser) error {
|
||||
tagflag.ParseArgs(&flags, args, tagflag.Parent(parent))
|
||||
defer envpprof.Stop()
|
||||
clientConfig := torrent.NewDefaultClientConfig()
|
||||
clientConfig.DisableAcceptRateLimiting = true
|
||||
|
|
Loading…
Reference in New Issue