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 static class Update implements Comparable<Update> {
public String type; public String type;
public List<String> torrent; public String torrent;
public List<String> clearnet; public List<String> clearnet;
public List<String> ssl; public List<String> ssl;

View File

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

View File

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