]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Trivial HTTP support for adding torrent files by (#126)
authorIgor Shishkin <me@teran.ru>
Tue, 25 Oct 2016 08:13:06 +0000 (11:13 +0300)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 25 Oct 2016 08:13:06 +0000 (19:13 +1100)
* 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 <me@teran.ru>
* Fix for closing http connection after use

Signed-off-by: Igor Shishkin <me@teran.ru>
cmd/torrent/main.go

index 858c8054aeef0d7e295d05e4438d25980b63a010..0f075096c4211d5afd35508af5d9f374c925382e 100644 (file)
@@ -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 {