Only need one torrent magnet; tighten update type spec

This commit is contained in:
str4d
2014-11-21 13:02:57 +00:00
parent c88fa70f82
commit ce2a2cf684
3 changed files with 26 additions and 26 deletions

View File

@ -35,7 +35,7 @@ public class NewsMetadata {
public static class Update implements Comparable<Update> {
public String type;
public List<String> torrent;
public String torrent;
public List<String> clearnet;
public List<String> ssl;

View File

@ -196,30 +196,32 @@ public class NewsXMLParser {
List<NewsMetadata.Update> updates = new ArrayList<NewsMetadata.Update>();
List<Node> updateNodes = getNodes(r, "i2p:update");
Set<String> types = new HashSet<String>();
for (Node u : updateNodes) {
// returns "" for none
String type = u.getAttributeValue("type");
if (type.length() > 0) {
NewsMetadata.Update update = new NewsMetadata.Update();
update.type = type;
int totalSources = 0;
if (type.isEmpty())
throw new I2PParserException("update with no type");
if (types.contains(type))
throw new I2PParserException("update with duplicate type");
NewsMetadata.Update update = new NewsMetadata.Update();
update.type = type;
types.add(type);
int totalSources = 0;
List<String> torrents = new ArrayList<String>();
List<Node> torrentNodes = getNodes(u, "i2p:torrent");
for (Node t : torrentNodes) {
// returns "" for none
String href = t.getAttributeValue("href");
if (href.length() > 0) {
torrents.add(href);
}
Node t = u.getNode("i2p:torrent");
if (t != null) {
// returns "" for none
String href = t.getAttributeValue("href");
if (href.length() > 0) {
update.torrent = href;
totalSources += 1;
}
update.torrent = torrents;
totalSources += torrents.size();
if (totalSources == 0)
throw new I2PParserException("no sources for update type " + type);
updates.add(update);
}
if (totalSources == 0)
throw new I2PParserException("no sources for update type " + type);
updates.add(update);
}
Collections.sort(updates);
release.updates = updates;

View File

@ -469,13 +469,11 @@ class NewsFetcher extends UpdateRunner {
String su3Torrent = "";
String su2Torrent = "";
for (NewsMetadata.Update update : latestRelease.updates) {
if (update.torrent.size() > 0) {
// Only take the first torrent magnet
// TODO handle multiple torrent magnetss
if ("su3".equals(update.type) && su3Torrent.isEmpty())
su3Torrent = update.torrent.get(0);
else if ("su2".equals(update.type) && su2Torrent.isEmpty())
su2Torrent = update.torrent.get(0);
if (update.torrent != null) {
if ("su3".equals(update.type))
su3Torrent = update.torrent;
else if ("su2".equals(update.type))
su2Torrent = update.torrent;
}
}
if (!su2Torrent.isEmpty())