refactor options
This commit is contained in:
@@ -34,11 +34,17 @@ import java.util.Date;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||
|
||||
/**
|
||||
* Download server: http://bloodcat.com/osu/
|
||||
*/
|
||||
public class BloodcatServer extends DownloadServer {
|
||||
|
||||
@Inject
|
||||
public InstanceContainer instanceContainer;
|
||||
|
||||
/** Server name. */
|
||||
private static final String SERVER_NAME = "Bloodcat";
|
||||
|
||||
@@ -54,8 +60,9 @@ public class BloodcatServer extends DownloadServer {
|
||||
/** Total result count from the last query. */
|
||||
private int totalResults = -1;
|
||||
|
||||
/** Constructor. */
|
||||
public BloodcatServer() {}
|
||||
@Inject
|
||||
public BloodcatServer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() { return SERVER_NAME; }
|
||||
@@ -82,12 +89,12 @@ public class BloodcatServer extends DownloadServer {
|
||||
nodes = new DownloadNode[arr.length()];
|
||||
for (int i = 0; i < nodes.length; i++) {
|
||||
JSONObject item = arr.getJSONObject(i);
|
||||
nodes[i] = new DownloadNode(
|
||||
nodes[i] = instanceContainer.injectFields(new DownloadNode(
|
||||
item.getInt("id"), formatDate(item.getString("synced")), //"date"
|
||||
item.getString("title"), item.isNull("titleU") ? null : item.getString("titleU"), //"titleUnicode"
|
||||
item.getString("artist"), item.isNull("artistU") ? null : item.getString("artistU"), //"artistUnicode"
|
||||
item.getString("creator")
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
// store total result count
|
||||
|
||||
@@ -30,6 +30,8 @@ import java.net.URLEncoder;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||
|
||||
/**
|
||||
* Download server: https://osu.hexide.com/
|
||||
@@ -37,6 +39,10 @@ import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
* <i>This server went offline in 2016.</i>
|
||||
*/
|
||||
public class HexideServer extends DownloadServer {
|
||||
|
||||
@Inject
|
||||
private InstanceContainer instanceContainer;
|
||||
|
||||
/** Server name. */
|
||||
private static final String SERVER_NAME = "Hexide";
|
||||
|
||||
@@ -58,8 +64,9 @@ public class HexideServer extends DownloadServer {
|
||||
/** Total result count from the last query. */
|
||||
private int totalResults = -1;
|
||||
|
||||
/** Constructor. */
|
||||
public HexideServer() {}
|
||||
@Inject
|
||||
public HexideServer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() { return SERVER_NAME; }
|
||||
@@ -117,10 +124,10 @@ public class HexideServer extends DownloadServer {
|
||||
artist = creator = "?";
|
||||
}
|
||||
}
|
||||
nodes[i] = new DownloadNode(
|
||||
nodes[i] = instanceContainer.injectFields(new DownloadNode(
|
||||
item.getInt("ranked_id"), item.getString("date"),
|
||||
title, null, artist, null, creator
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
// store total result count
|
||||
|
||||
@@ -30,11 +30,17 @@ import java.net.URLEncoder;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||
|
||||
/**
|
||||
* Download server: http://osu.mengsky.net/
|
||||
*/
|
||||
public class MengSkyServer extends DownloadServer {
|
||||
|
||||
@Inject
|
||||
private InstanceContainer instanceContainer;
|
||||
|
||||
/** Server name. */
|
||||
private static final String SERVER_NAME = "MengSky";
|
||||
|
||||
@@ -50,8 +56,9 @@ public class MengSkyServer extends DownloadServer {
|
||||
/** Total result count from the last query. */
|
||||
private int totalResults = -1;
|
||||
|
||||
/** Constructor. */
|
||||
public MengSkyServer() {}
|
||||
@Inject
|
||||
public MengSkyServer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() { return SERVER_NAME; }
|
||||
@@ -86,19 +93,18 @@ public class MengSkyServer extends DownloadServer {
|
||||
// sometimes titleU is artistU instead of the proper title
|
||||
if (titleU.equals(artistU) && !titleU.equals(title))
|
||||
titleU = title;
|
||||
nodes[i] = new DownloadNode(
|
||||
nodes[i] = instanceContainer.injectFields(new DownloadNode(
|
||||
item.getInt("id"), item.getString("syncedDateTime"),
|
||||
title, titleU, artist, artistU, creator
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
// store total result count
|
||||
int pageTotal = json.getInt("pageTotal");
|
||||
int resultCount = nodes.length;
|
||||
if (page == pageTotal)
|
||||
resultCount = nodes.length + (pageTotal - 1) * PAGE_LIMIT;
|
||||
else
|
||||
resultCount = 1 + (pageTotal - 1) * PAGE_LIMIT;
|
||||
int resultCount = 1 + (pageTotal - 1) * PAGE_LIMIT;
|
||||
if (page == pageTotal) {
|
||||
resultCount += nodes.length - 1;
|
||||
}
|
||||
this.totalResults = resultCount;
|
||||
} catch (MalformedURLException | UnsupportedEncodingException e) {
|
||||
ErrorHandler.error(String.format("Problem loading result list for query '%s'.", query), e).show();
|
||||
|
||||
@@ -21,6 +21,8 @@ package itdelatrisu.opsu.downloads.servers;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import itdelatrisu.opsu.downloads.DownloadNode;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -36,6 +38,10 @@ import java.util.regex.Pattern;
|
||||
* Download server: http://osu.uu.gl/
|
||||
*/
|
||||
public class MnetworkServer extends DownloadServer {
|
||||
|
||||
@Inject
|
||||
private InstanceContainer instanceContainer;
|
||||
|
||||
/** Server name. */
|
||||
private static final String SERVER_NAME = "Mnetwork";
|
||||
|
||||
@@ -51,8 +57,9 @@ public class MnetworkServer extends DownloadServer {
|
||||
/** Beatmap pattern. */
|
||||
private Pattern BEATMAP_PATTERN = Pattern.compile("^(\\d+) ([^-]+) - (.+)\\.osz$");
|
||||
|
||||
/** Constructor. */
|
||||
public MnetworkServer() {}
|
||||
@Inject
|
||||
public MnetworkServer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() { return SERVER_NAME; }
|
||||
@@ -112,7 +119,7 @@ public class MnetworkServer extends DownloadServer {
|
||||
if (!m.matches())
|
||||
continue;
|
||||
|
||||
nodeList.add(new DownloadNode(Integer.parseInt(m.group(1)), date, m.group(3), null, m.group(2), null, ""));
|
||||
nodeList.add(instanceContainer.injectFields(new DownloadNode(Integer.parseInt(m.group(1)), date, m.group(3), null, m.group(2), null, "")));
|
||||
}
|
||||
|
||||
nodes = nodeList.toArray(new DownloadNode[nodeList.size()]);
|
||||
|
||||
@@ -36,6 +36,8 @@ import java.util.TimeZone;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||
|
||||
/**
|
||||
* Download server: http://loli.al/
|
||||
@@ -43,6 +45,10 @@ import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
* <i>This server went offline in August 2015.</i>
|
||||
*/
|
||||
public class OsuMirrorServer extends DownloadServer {
|
||||
|
||||
@Inject
|
||||
private InstanceContainer instanceContainer;
|
||||
|
||||
/** Server name. */
|
||||
private static final String SERVER_NAME = "osu!Mirror";
|
||||
|
||||
@@ -67,8 +73,9 @@ public class OsuMirrorServer extends DownloadServer {
|
||||
/** Lookup table from beatmap set ID -> server download ID. */
|
||||
private HashMap<Integer, Integer> idTable = new HashMap<Integer, Integer>();
|
||||
|
||||
/** Constructor. */
|
||||
public OsuMirrorServer() {}
|
||||
@Inject
|
||||
public OsuMirrorServer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() { return SERVER_NAME; }
|
||||
@@ -106,12 +113,12 @@ public class OsuMirrorServer extends DownloadServer {
|
||||
JSONObject item = arr.getJSONObject(i);
|
||||
int beatmapSetID = item.getInt("OSUSetid");
|
||||
int serverID = item.getInt("id");
|
||||
nodes[i] = new DownloadNode(
|
||||
nodes[i] = instanceContainer.injectFields(new DownloadNode(
|
||||
beatmapSetID, formatDate(item.getString("ModifyDate")),
|
||||
item.getString("Title"), null,
|
||||
item.getString("Artist"), null,
|
||||
item.getString("Mapper")
|
||||
);
|
||||
));
|
||||
idTable.put(beatmapSetID, serverID);
|
||||
if (serverID > maxServerID)
|
||||
maxServerID = serverID;
|
||||
|
||||
@@ -34,11 +34,17 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import yugecin.opsudance.core.errorhandling.ErrorHandler;
|
||||
import yugecin.opsudance.core.inject.Inject;
|
||||
import yugecin.opsudance.core.inject.InstanceContainer;
|
||||
|
||||
/**
|
||||
* Download server: http://osu.yas-online.net/
|
||||
*/
|
||||
public class YaSOnlineServer extends DownloadServer {
|
||||
|
||||
@Inject
|
||||
public InstanceContainer instanceContainer;
|
||||
|
||||
/** Server name. */
|
||||
private static final String SERVER_NAME = "YaS Online";
|
||||
|
||||
@@ -66,8 +72,9 @@ public class YaSOnlineServer extends DownloadServer {
|
||||
/** Max server download ID seen (for approximating total pages). */
|
||||
private int maxServerID = 0;
|
||||
|
||||
/** Constructor. */
|
||||
public YaSOnlineServer() {}
|
||||
@Inject
|
||||
public YaSOnlineServer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() { return SERVER_NAME; }
|
||||
@@ -176,7 +183,7 @@ public class YaSOnlineServer extends DownloadServer {
|
||||
if (serverID > maxServerID)
|
||||
maxServerID = serverID;
|
||||
|
||||
nodeList.add(new DownloadNode(item.getInt("mapid"), date, title, null, artist, null, ""));
|
||||
nodeList.add(instanceContainer.injectFields(new DownloadNode(item.getInt("mapid"), date, title, null, artist, null, "")));
|
||||
}
|
||||
nodes = nodeList.toArray(new DownloadNode[nodeList.size()]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user