From: Igor Shishkin Date: Tue, 25 Oct 2016 08:13:06 +0000 (+0300) Subject: Trivial HTTP support for adding torrent files by (#126) X-Git-Tag: v1.0.0~550 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c43751cfea61d47aa4cff19939d338d1840dc023;p=btrtrc.git Trivial HTTP support for adding torrent files by (#126) * Trivial HTTP support for adding torrent files by Sometimes it's really usefull to do not download torrent file locally but simply pass HTTP link this patch adds such ability. Signed-off-by: Igor Shishkin * Fix for closing http connection after use Signed-off-by: Igor Shishkin --- diff --git a/cmd/torrent/main.go b/cmd/torrent/main.go index 858c8054..0f075096 100644 --- a/cmd/torrent/main.go +++ b/cmd/torrent/main.go @@ -81,6 +81,23 @@ func addTorrents(client *torrent.Client) { log.Fatalf("error adding magnet: %s", err) } return t + } else if strings.HasPrefix(arg, "http://") || strings.HasPrefix(arg, "https://") { + response, err := http.Get(arg) + if err != nil { + log.Fatalf("Error downloading torrent file: %s", err) + } + + metaInfo, err := metainfo.Load(response.Body) + defer response.Body.Close() + if err != nil { + fmt.Fprintf(os.Stderr, "error loading torrent file %q: %s\n", arg, err) + os.Exit(1) + } + t, err := client.AddTorrent(metaInfo) + if err != nil { + log.Fatal(err) + } + return t } else { metaInfo, err := metainfo.LoadFromFile(arg) if err != nil {