use of com.biglybt.core.torrent.TOTorrentAnnounceURLGroup in project BiglyBT by BiglySoftware.
the class TorrentAnnounceURLListImpl method setSets.
@Override
public void setSets(TorrentAnnounceURLListSet[] sets) {
TOTorrentAnnounceURLGroup group = torrent.getTorrent().getAnnounceURLGroup();
TOTorrentAnnounceURLSet[] res = new TOTorrentAnnounceURLSet[sets.length];
for (int i = 0; i < res.length; i++) {
res[i] = ((TorrentAnnounceURLListSetImpl) sets[i]).getSet();
}
group.setAnnounceURLSets(res);
updated();
}
use of com.biglybt.core.torrent.TOTorrentAnnounceURLGroup in project BiglyBT by BiglySoftware.
the class TOTorrentXMLDeserialiser method decodeRoot.
protected TOTorrent decodeRoot(SimpleXMLParserDocument doc) throws TOTorrentException {
String root_name = doc.getName();
if (root_name.equalsIgnoreCase("TORRENT")) {
TOTorrentImpl torrent = new TOTorrentImpl();
SimpleXMLParserDocumentNode[] kids = doc.getChildren();
URL announce_url = null;
byte[] torrent_hash = null;
byte[] torrent_hash_override = null;
for (int i = 0; i < kids.length; i++) {
SimpleXMLParserDocumentNode kid = kids[i];
String name = kid.getName();
if (name.equalsIgnoreCase("ANNOUNCE_URL")) {
try {
announce_url = new URL(kid.getValue());
} catch (MalformedURLException e) {
throw (new TOTorrentException("ANNOUNCE_URL malformed", TOTorrentException.RT_DECODE_FAILS));
}
} else if (name.equalsIgnoreCase("ANNOUNCE_LIST")) {
SimpleXMLParserDocumentNode[] set_nodes = kid.getChildren();
TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
TOTorrentAnnounceURLSet[] sets = new TOTorrentAnnounceURLSet[set_nodes.length];
for (int j = 0; j < sets.length; j++) {
SimpleXMLParserDocumentNode[] url_nodes = set_nodes[j].getChildren();
URL[] urls = new URL[url_nodes.length];
for (int k = 0; k < urls.length; k++) {
try {
urls[k] = new URL(url_nodes[k].getValue());
} catch (MalformedURLException e) {
throw (new TOTorrentException("ANNOUNCE_LIST malformed", TOTorrentException.RT_DECODE_FAILS));
}
}
sets[j] = group.createAnnounceURLSet(urls);
}
group.setAnnounceURLSets(sets);
} else if (name.equalsIgnoreCase("COMMENT")) {
torrent.setComment(readLocalisableString(kid));
} else if (name.equalsIgnoreCase("CREATED_BY")) {
torrent.setCreatedBy(readLocalisableString(kid));
} else if (name.equalsIgnoreCase("CREATION_DATE")) {
torrent.setCreationDate(readGenericLong(kid).longValue());
} else if (name.equalsIgnoreCase("TORRENT_HASH")) {
torrent_hash = readGenericBytes(kid);
} else if (name.equalsIgnoreCase("TORRENT_HASH_OVERRIDE")) {
torrent_hash_override = readGenericBytes(kid);
} else if (name.equalsIgnoreCase("INFO")) {
decodeInfo(kid, torrent);
} else {
mapEntry entry = readGenericMapEntry(kid);
torrent.addAdditionalProperty(entry.name, entry.value);
}
}
if (announce_url == null) {
throw (new TOTorrentException("ANNOUNCE_URL missing", TOTorrentException.RT_DECODE_FAILS));
}
torrent.setAnnounceURL(announce_url);
if (torrent_hash_override != null) {
try {
torrent.setHashOverride(torrent_hash_override);
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
if (torrent_hash != null) {
if (!Arrays.equals(torrent.getHash(), torrent_hash)) {
throw (new TOTorrentException("Hash differs - declared TORRENT_HASH and computed hash differ. If this really is the intent (unlikely) then remove the TORRENT_HASH element", TOTorrentException.RT_DECODE_FAILS));
}
}
return (torrent);
} else {
throw (new TOTorrentException("Invalid root element", TOTorrentException.RT_DECODE_FAILS));
}
}
use of com.biglybt.core.torrent.TOTorrentAnnounceURLGroup in project BiglyBT by BiglySoftware.
the class MagnetPlugin method addTrackersAndWebSeedsEtc.
private byte[] addTrackersAndWebSeedsEtc(byte[] torrent_data, String args, Set<String> networks) {
List<String> new_web_seeds = new ArrayList<>();
List<String> new_trackers = new ArrayList<>();
Set<String> tags = new HashSet<>();
if (args != null) {
String[] bits = args.split("&");
for (String bit : bits) {
String[] x = bit.split("=");
if (x.length == 2) {
String lhs = x[0].toLowerCase();
if (lhs.equals("ws")) {
try {
new_web_seeds.add(new URL(UrlUtils.decode(x[1])).toExternalForm());
} catch (Throwable e) {
}
} else if (lhs.equals("tr")) {
try {
new_trackers.add(new URL(UrlUtils.decode(x[1])).toExternalForm());
} catch (Throwable e) {
}
} else if (lhs.equals("tag")) {
tags.add(UrlUtils.decode(x[1]));
}
}
}
}
if (new_web_seeds.size() > 0 || new_trackers.size() > 0 || networks.size() > 0) {
try {
TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedByteArray(torrent_data);
boolean update_torrent = false;
if (new_web_seeds.size() > 0) {
Object obj = torrent.getAdditionalProperty("url-list");
List<String> existing = new ArrayList<>();
if (obj instanceof byte[]) {
try {
new_web_seeds.remove(new URL(new String((byte[]) obj, "UTF-8")).toExternalForm());
} catch (Throwable e) {
}
} else if (obj instanceof List) {
List<byte[]> l = (List<byte[]>) obj;
for (byte[] b : l) {
try {
existing.add(new URL(new String((byte[]) b, "UTF-8")).toExternalForm());
} catch (Throwable e) {
}
}
}
boolean update_ws = false;
for (String e : new_web_seeds) {
if (!existing.contains(e)) {
existing.add(e);
update_ws = true;
}
}
if (update_ws) {
List<byte[]> l = new ArrayList<>();
for (String s : existing) {
l.add(s.getBytes("UTF-8"));
}
torrent.setAdditionalProperty("url-list", l);
update_torrent = true;
}
}
if (new_trackers.size() > 0) {
URL announce_url = torrent.getAnnounceURL();
new_trackers.remove(announce_url.toExternalForm());
TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
for (TOTorrentAnnounceURLSet set : sets) {
URL[] set_urls = set.getAnnounceURLs();
for (URL set_url : set_urls) {
new_trackers.remove(set_url.toExternalForm());
}
}
if (new_trackers.size() > 0) {
TOTorrentAnnounceURLSet[] new_sets = new TOTorrentAnnounceURLSet[sets.length + new_trackers.size()];
System.arraycopy(sets, 0, new_sets, 0, sets.length);
for (int i = 0; i < new_trackers.size(); i++) {
TOTorrentAnnounceURLSet new_set = group.createAnnounceURLSet(new URL[] { new URL(new_trackers.get(i)) });
new_sets[i + sets.length] = new_set;
}
group.setAnnounceURLSets(new_sets);
update_torrent = true;
}
}
if (networks.size() > 0) {
TorrentUtils.setNetworkCache(torrent, new ArrayList<>(networks));
update_torrent = true;
}
if (tags.size() > 0) {
TorrentUtils.setTagCache(torrent, new ArrayList<>(tags));
update_torrent = true;
}
if (update_torrent) {
torrent_data = BEncoder.encode(torrent.serialiseToMap());
}
} catch (Throwable e) {
}
}
return (torrent_data);
}
use of com.biglybt.core.torrent.TOTorrentAnnounceURLGroup in project BiglyBT by BiglySoftware.
the class TorrentInfoView method initialize.
private void initialize(Composite composite) {
this.parent = composite;
if (download_manager == null) {
return;
}
// I don't want to waste my time :) [tux]
if (sc != null && !sc.isDisposed()) {
sc.dispose();
}
sc = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL);
sc.getVerticalBar().setIncrement(16);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
Utils.setLayoutData(sc, gridData);
outer_panel = sc;
Composite panel = new Composite(sc, SWT.NULL);
sc.setContent(panel);
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.numColumns = 1;
panel.setLayout(layout);
// int userMode = COConfigurationManager.getIntParameter("User Mode");
// header
Composite cHeader = new Composite(panel, SWT.BORDER);
GridLayout configLayout = new GridLayout();
configLayout.marginHeight = 3;
configLayout.marginWidth = 0;
cHeader.setLayout(configLayout);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
Utils.setLayoutData(cHeader, gridData);
Display d = panel.getDisplay();
cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
Label lHeader = new Label(cHeader, SWT.NULL);
lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
FontData[] fontData = lHeader.getFont().getFontData();
fontData[0].setStyle(SWT.BOLD);
int fontHeight = (int) (fontData[0].getHeight() * 1.2);
fontData[0].setHeight(fontHeight);
headerFont = new Font(d, fontData);
lHeader.setFont(headerFont);
lHeader.setText(" " + MessageText.getString("authenticator.torrent") + " : " + download_manager.getDisplayName().replaceAll("&", "&&"));
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
Utils.setLayoutData(lHeader, gridData);
Composite gTorrentInfo = new Composite(panel, SWT.NULL);
gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
Utils.setLayoutData(gTorrentInfo, gridData);
layout = new GridLayout();
layout.numColumns = 2;
gTorrentInfo.setLayout(layout);
// torrent encoding
Label label = new Label(gTorrentInfo, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(label, gridData);
label.setText(MessageText.getString("TorrentInfoView.torrent.encoding") + ": ");
TOTorrent torrent = download_manager.getTorrent();
BufferedLabel blabel = new BufferedLabel(gTorrentInfo, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(blabel, gridData);
blabel.setText(torrent == null ? "" : LocaleTorrentUtil.getCurrentTorrentEncoding(torrent));
// trackers
label = new Label(gTorrentInfo, SWT.NULL);
gridData = new GridData();
Utils.setLayoutData(label, gridData);
label.setText(MessageText.getString("label.tracker") + ": ");
String trackers = "";
if (torrent != null) {
TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
List<String> tracker_list = new ArrayList<>();
URL url = torrent.getAnnounceURL();
tracker_list.add(url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort())));
for (int i = 0; i < sets.length; i++) {
TOTorrentAnnounceURLSet set = sets[i];
URL[] urls = set.getAnnounceURLs();
for (int j = 0; j < urls.length; j++) {
url = urls[j];
String str = url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort()));
if (!tracker_list.contains(str)) {
tracker_list.add(str);
}
}
}
TRTrackerAnnouncer announcer = download_manager.getTrackerClient();
URL active_url = null;
if (announcer != null) {
active_url = announcer.getTrackerURL();
} else {
TRTrackerScraperResponse scrape = download_manager.getTrackerScrapeResponse();
if (scrape != null) {
active_url = scrape.getURL();
}
}
if (active_url == null) {
active_url = torrent.getAnnounceURL();
}
trackers = active_url.getHost() + (active_url.getPort() == -1 ? "" : (":" + active_url.getPort()));
tracker_list.remove(trackers);
if (tracker_list.size() > 0) {
trackers += " (";
for (int i = 0; i < tracker_list.size(); i++) {
trackers += (i == 0 ? "" : ", ") + tracker_list.get(i);
}
trackers += ")";
}
}
blabel = new BufferedLabel(gTorrentInfo, SWT.WRAP);
Utils.setLayoutData(blabel, Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL));
blabel.setText(trackers);
// columns
Group gColumns = new Group(panel, SWT.NULL);
Messages.setLanguageText(gColumns, "TorrentInfoView.columns");
gridData = new GridData(GridData.FILL_BOTH);
Utils.setLayoutData(gColumns, gridData);
layout = new GridLayout();
layout.numColumns = 4;
gColumns.setLayout(layout);
Map<String, FakeTableCell> usable_cols = new HashMap<>();
TableColumnManager col_man = TableColumnManager.getInstance();
TableColumnCore[][] cols_sets = { col_man.getAllTableColumnCoreAsArray(DownloadTypeIncomplete.class, TableManager.TABLE_MYTORRENTS_INCOMPLETE), col_man.getAllTableColumnCoreAsArray(DownloadTypeComplete.class, TableManager.TABLE_MYTORRENTS_COMPLETE) };
for (int i = 0; i < cols_sets.length; i++) {
TableColumnCore[] cols = cols_sets[i];
for (int j = 0; j < cols.length; j++) {
TableColumnCore col = cols[j];
String id = col.getName();
if (usable_cols.containsKey(id)) {
continue;
}
FakeTableCell fakeTableCell = null;
try {
fakeTableCell = new FakeTableCell(col, download_manager);
fakeTableCell.setOrentation(SWT.LEFT);
fakeTableCell.setWrapText(false);
col.invokeCellAddedListeners(fakeTableCell);
// One refresh to see if it throws up
fakeTableCell.refresh();
usable_cols.put(id, fakeTableCell);
} catch (Throwable t) {
// System.out.println("not usable col: " + id + " - " + Debug.getCompressedStackTrace());
try {
if (fakeTableCell != null) {
fakeTableCell.dispose();
}
} catch (Throwable t2) {
// ignore;
}
}
}
}
Collection<FakeTableCell> values = usable_cols.values();
cells = new FakeTableCell[values.size()];
values.toArray(cells);
Arrays.sort(cells, new Comparator<FakeTableCell>() {
@Override
public int compare(FakeTableCell o1, FakeTableCell o2) {
TableColumnCore c1 = (TableColumnCore) o1.getTableColumn();
TableColumnCore c2 = (TableColumnCore) o2.getTableColumn();
String key1 = MessageText.getString(c1.getTitleLanguageKey());
String key2 = MessageText.getString(c2.getTitleLanguageKey());
return key1.compareToIgnoreCase(key2);
}
});
for (int i = 0; i < cells.length; i++) {
final FakeTableCell cell = cells[i];
label = new Label(gColumns, SWT.NULL);
gridData = new GridData();
if (i % 2 == 1) {
gridData.horizontalIndent = 16;
}
Utils.setLayoutData(label, gridData);
String key = ((TableColumnCore) cell.getTableColumn()).getTitleLanguageKey();
label.setText(MessageText.getString(key) + ": ");
label.setToolTipText(MessageText.getString(key + ".info", ""));
final Composite c = new Composite(gColumns, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.heightHint = 16;
Utils.setLayoutData(c, gridData);
cell.setControl(c);
cell.invalidate();
cell.refresh();
c.addListener(SWT.MouseHover, new Listener() {
@Override
public void handleEvent(Event event) {
Object toolTip = cell.getToolTip();
if (toolTip instanceof String) {
String s = (String) toolTip;
c.setToolTipText(s);
}
}
});
}
refresh();
sc.setMinSize(panel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
use of com.biglybt.core.torrent.TOTorrentAnnounceURLGroup in project BiglyBT by BiglySoftware.
the class RelatedContentManager method getKeys.
private byte[][] getKeys(Download download) {
byte[] tracker_keys = null;
byte[] ws_keys = null;
try {
Torrent torrent = download.getTorrent();
if (torrent != null) {
TOTorrent to_torrent = PluginCoreUtils.unwrap(torrent);
Set<String> tracker_domains = new HashSet<>();
addURLToDomainKeySet(tracker_domains, to_torrent.getAnnounceURL());
TOTorrentAnnounceURLGroup group = to_torrent.getAnnounceURLGroup();
TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
for (TOTorrentAnnounceURLSet set : sets) {
URL[] urls = set.getAnnounceURLs();
for (URL u : urls) {
addURLToDomainKeySet(tracker_domains, u);
}
}
tracker_keys = domainsToArray(tracker_domains, 8);
Set<String> ws_domains = new HashSet<>();
List getright = BDecoder.decodeStrings(getURLList(to_torrent, "url-list"));
List webseeds = BDecoder.decodeStrings(getURLList(to_torrent, "httpseeds"));
for (List l : new List[] { getright, webseeds }) {
for (Object o : l) {
if (o instanceof String) {
try {
addURLToDomainKeySet(ws_domains, new URL((String) o));
} catch (Throwable e) {
}
}
}
}
ws_keys = domainsToArray(ws_domains, 3);
}
} catch (Throwable e) {
}
return (new byte[][] { tracker_keys, ws_keys });
}
Aggregations