Retrive file via HTTP URL in `metainfo.go` (#778)
This commit is contained in:
parent
e81c6569af
commit
de4c16bbe9
|
@ -5,6 +5,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/anacrolix/bargle"
|
"github.com/anacrolix/bargle"
|
||||||
"github.com/anacrolix/torrent/metainfo"
|
"github.com/anacrolix/torrent/metainfo"
|
||||||
|
@ -27,7 +29,18 @@ func metainfoCmd() (cmd bargle.Command) {
|
||||||
Value: &bargle.String{Target: &metainfoPath},
|
Value: &bargle.String{Target: &metainfoPath},
|
||||||
AfterParseFunc: func(ctx bargle.Context) error {
|
AfterParseFunc: func(ctx bargle.Context) error {
|
||||||
ctx.AfterParse(func() (err error) {
|
ctx.AfterParse(func() (err error) {
|
||||||
|
if strings.HasPrefix(metainfoPath, "http://") || strings.HasPrefix(metainfoPath, "https://") {
|
||||||
|
response, err := http.Get(metainfoPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
mi, err = metainfo.Load(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
mi, err = metainfo.LoadFromFile(metainfoPath)
|
mi, err = metainfo.LoadFromFile(metainfoPath)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue