From a22c1334c6e9a4d514b8568d47a7bae8967366d7 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 24 Feb 2021 12:11:41 +1100 Subject: [PATCH] Include webseed urls in MetaInfo.Magnet output Fixes #469. --- metainfo/metainfo.go | 5 +++-- metainfo/metainfo_test.go | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/metainfo/metainfo.go b/metainfo/metainfo.go index 9b06ebd4..9041fced 100644 --- a/metainfo/metainfo.go +++ b/metainfo/metainfo.go @@ -2,6 +2,7 @@ package metainfo import ( "io" + "net/url" "os" "time" @@ -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 } diff --git a/metainfo/metainfo_test.go b/metainfo/metainfo_test.go index 6aae2b4f..63a26d94 100644 --- a/metainfo/metainfo_test.go +++ b/metainfo/metainfo_test.go @@ -6,6 +6,7 @@ import ( "os" "path" "path/filepath" + "strings" "testing" "github.com/anacrolix/missinggo" @@ -123,7 +124,14 @@ 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) { @@ -131,7 +139,12 @@ func TestMetainfoWithStringURLList(t *testing.T) { 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