Search in sources :

Example 1 with TorrentAnnounceURLListSet

use of com.biglybt.pif.torrent.TorrentAnnounceURLListSet in project BiglyBT by BiglySoftware.

the class UrlUtils method getMagnetURI.

public static String getMagnetURI(String name, Torrent torrent, String[] networks) {
    String magnet_str = getMagnetURI(torrent.getHash());
    magnet_str += encodeName(name);
    if (networks != null) {
        magnet_str += encodeNetworks(networks);
    }
    List<String> tracker_urls = new ArrayList<>();
    URL announce_url = torrent.getAnnounceURL();
    if (announce_url != null) {
        if (!TorrentUtils.isDecentralised(announce_url)) {
            tracker_urls.add(announce_url.toExternalForm());
        }
    }
    TorrentAnnounceURLList list = torrent.getAnnounceURLList();
    TorrentAnnounceURLListSet[] sets = list.getSets();
    for (TorrentAnnounceURLListSet set : sets) {
        URL[] set_urls = set.getURLs();
        if (set_urls.length > 0) {
            URL set_url = set_urls[0];
            if (!TorrentUtils.isDecentralised(set_url)) {
                String str = set_url.toExternalForm();
                if (!tracker_urls.contains(str)) {
                    tracker_urls.add(str);
                }
            }
        }
    }
    for (String str : tracker_urls) {
        magnet_str += "&tr=" + UrlUtils.encode(str);
    }
    List<String> ws_urls = new ArrayList<>();
    Object obj = torrent.getAdditionalProperty("url-list");
    if (obj instanceof byte[]) {
        try {
            ws_urls.add(new URL(new String((byte[]) obj, "UTF-8")).toExternalForm());
        } catch (Throwable e) {
        }
    } else if (obj instanceof List) {
        for (Object o : (List) obj) {
            try {
                if (o instanceof byte[]) {
                    ws_urls.add(new URL(new String((byte[]) o, "UTF-8")).toExternalForm());
                } else if (o instanceof String) {
                    ws_urls.add(new URL((String) o).toExternalForm());
                }
            } catch (Throwable e) {
            }
        }
    } else if (obj instanceof String) {
        try {
            ws_urls.add(new URL((String) obj).toExternalForm());
        } catch (Throwable e) {
        }
    }
    for (String str : ws_urls) {
        magnet_str += "&ws=" + UrlUtils.encode(str);
    }
    return (magnet_str);
}
Also used : TorrentAnnounceURLListSet(com.biglybt.pif.torrent.TorrentAnnounceURLListSet) TorrentAnnounceURLList(com.biglybt.pif.torrent.TorrentAnnounceURLList) TorrentAnnounceURLList(com.biglybt.pif.torrent.TorrentAnnounceURLList)

Example 2 with TorrentAnnounceURLListSet

use of com.biglybt.pif.torrent.TorrentAnnounceURLListSet in project BiglyBT by BiglySoftware.

the class TorrentAnnounceURLListImpl method getSets.

@Override
public TorrentAnnounceURLListSet[] getSets() {
    TOTorrentAnnounceURLGroup group = torrent.getTorrent().getAnnounceURLGroup();
    TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
    TorrentAnnounceURLListSet[] res = new TorrentAnnounceURLListSet[sets.length];
    for (int i = 0; i < res.length; i++) {
        res[i] = new TorrentAnnounceURLListSetImpl(this, sets[i]);
    }
    return (res);
}
Also used : TorrentAnnounceURLListSet(com.biglybt.pif.torrent.TorrentAnnounceURLListSet) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)

Aggregations

TorrentAnnounceURLListSet (com.biglybt.pif.torrent.TorrentAnnounceURLListSet)2 TOTorrentAnnounceURLGroup (com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)1 TOTorrentAnnounceURLSet (com.biglybt.core.torrent.TOTorrentAnnounceURLSet)1 TorrentAnnounceURLList (com.biglybt.pif.torrent.TorrentAnnounceURLList)1