Add announce and download commands to cmd/torrent
This commit is contained in:
parent
6920298770
commit
d3b6bcef97
32
cmd/torrent/announce.go
Normal file
32
cmd/torrent/announce.go
Normal file
@ -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 {
|
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()
|
defer envpprof.Stop()
|
||||||
clientConfig := torrent.NewDefaultClientConfig()
|
clientConfig := torrent.NewDefaultClientConfig()
|
||||||
clientConfig.DisableAcceptRateLimiting = true
|
clientConfig.DisableAcceptRateLimiting = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user