Skip to content

Commit

Permalink
Include webseed urls in MetaInfo.Magnet output
Browse files Browse the repository at this point in the history
Fixes #469.
  • Loading branch information
anacrolix committed Feb 24, 2021
1 parent 3546467 commit a22c133
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
5 changes: 3 additions & 2 deletions metainfo/metainfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metainfo

import (
"io"
"net/url"
"os"
"time"

Expand Down Expand Up @@ -80,8 +81,8 @@ func (mi *MetaInfo) Magnet(infoHash *Hash, info *Info) (m Magnet) {
} else {
m.InfoHash = mi.HashInfoBytes()
}
//m.Params = make(url.Values)
//m.Params["ws"] = mi.UrlList
m.Params = make(url.Values)
m.Params["ws"] = mi.UrlList
return
}

Expand Down
17 changes: 15 additions & 2 deletions metainfo/metainfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"path/filepath"
"strings"
"testing"

"github.com/anacrolix/missinggo"
Expand Down Expand Up @@ -123,15 +124,27 @@ func TestMetainfoWithListURLList(t *testing.T) {
require.NoError(t, err)
assert.Len(t, mi.UrlList, 3)
qt.Assert(t, mi.Magnet(nil, nil).String(), qt.ContentEquals,
"magnet:?xt=urn:btih:d4b197dff199aad447a9a352e31528adbbd97922&tr=http%3A%2F%2Fbt1.archive.org%3A6969%2Fannounce&tr=http%3A%2F%2Fbt2.archive.org%3A6969%2Fannounce")
strings.Join([]string{
"magnet:?xt=urn:btih:d4b197dff199aad447a9a352e31528adbbd97922",
"tr=http%3A%2F%2Fbt1.archive.org%3A6969%2Fannounce",
"tr=http%3A%2F%2Fbt2.archive.org%3A6969%2Fannounce",
"ws=https%3A%2F%2Farchive.org%2Fdownload%2F",
"ws=http%3A%2F%2Fia601600.us.archive.org%2F26%2Fitems%2F",
"ws=http%3A%2F%2Fia801600.us.archive.org%2F26%2Fitems%2F",
}, "&"))
}

func TestMetainfoWithStringURLList(t *testing.T) {
mi, err := LoadFromFile("testdata/flat-url-list.torrent")
require.NoError(t, err)
assert.Len(t, mi.UrlList, 1)
qt.Assert(t, mi.Magnet(nil, nil).String(), qt.ContentEquals,
"magnet:?xt=urn:btih:9da24e606e4ed9c7b91c1772fb5bf98f82bd9687&tr=http%3A%2F%2Fbt1.archive.org%3A6969%2Fannounce&tr=http%3A%2F%2Fbt2.archive.org%3A6969%2Fannounce")
strings.Join([]string{
"magnet:?xt=urn:btih:9da24e606e4ed9c7b91c1772fb5bf98f82bd9687",
"tr=http%3A%2F%2Fbt1.archive.org%3A6969%2Fannounce",
"tr=http%3A%2F%2Fbt2.archive.org%3A6969%2Fannounce",
"ws=https%3A%2F%2Farchive.org%2Fdownload%2F",
}, "&"))
}

// https://github.com/anacrolix/torrent/issues/247
Expand Down

0 comments on commit a22c133

Please sign in to comment.