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 <me@teran.ru>

* Fix for closing http connection after use

Signed-off-by: Igor Shishkin <me@teran.ru>
This commit is contained in:
Igor Shishkin 2016-10-25 11:13:06 +03:00 committed by Matt Joiner
parent 5c5a26afed
commit c43751cfea
1 changed files with 17 additions and 0 deletions

View 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 {