Пример #1
0
  /** AKA scraping */
  public TorrentStatus getStatus() throws IOException {
    if (!isGetStatusSupported()) {
      throw new IllegalStateException("Get status (scraping) not supported on this tracker");
    }
    String path = announceUrl.getFile();
    int i = path.lastIndexOf('/');
    path = path.substring(0, i + 1) + "scrape" + path.substring(i + ANNOUNCE.length() + 1);

    GetMethod method = new GetMethod(path);
    method.setRequestHeader("User-Agent", "BlackBits/0.1");
    StringBuffer queryString =
        new StringBuffer(announceUrl.getQuery() == null ? "" : announceUrl.getQuery());
    queryString.append("info_hash=" + URLUtils.encode(infoHash.getBytes()));
    method.setQueryString(queryString.toString());
    httpClient.executeMethod(method);

    BDecoder decoder = new BDecoder(method.getResponseBodyAsStream());
    BDictionary dictionary = (BDictionary) decoder.decodeNext();
    BDictionary files = (BDictionary) dictionary.get("files");
    String key = (String) files.keySet().iterator().next();
    BDictionary info = (BDictionary) files.get(key);
    BLong seeders = (BLong) info.get("complete");
    BLong leechers = (BLong) info.get("incomplete");
    BLong numberOfDownloads = (BLong) info.get("downloaded");
    return new TorrentStatus(seeders.intValue(), leechers.intValue(), numberOfDownloads.intValue());
  }