9 "github.com/anacrolix/torrent/bencode"
10 "github.com/anacrolix/torrent/tracker/udp"
11 "github.com/anacrolix/torrent/types/infohash"
14 type scrapeResponse struct {
15 Files files `bencode:"files"`
18 // Bencode should support bencode.Unmarshalers from a string in the dict key position.
19 type files = map[string]udp.ScrapeInfohashResult
21 func (cl Client) Scrape(ctx context.Context, ihs []infohash.T) (out udp.ScrapeResponse, err error) {
22 _url := cl.url_.JoinPath("..", "scrape")
23 query, err := url.ParseQuery(_url.RawQuery)
27 for _, ih := range ihs {
28 query.Add("info_hash", ih.AsString())
30 _url.RawQuery = query.Encode()
31 log.Printf("%q", _url.String())
32 req, err := http.NewRequestWithContext(ctx, http.MethodGet, _url.String(), nil)
36 resp, err := cl.hc.Do(req)
40 defer resp.Body.Close()
41 var decodedResp scrapeResponse
42 err = bencode.NewDecoder(resp.Body).Decode(&decodedResp)
43 for _, ih := range ihs {
44 out = append(out, decodedResp.Files[ih.AsString()])