use of com.github.mob41.osumer.io.OsuDownloader in project osumer by mob41.
the class UIFrame method addQuietBtQueue.
public boolean addQuietBtQueue(String url) {
if (config.getCheckUpdateFreq() == Config.CHECK_UPDATE_FREQ_EVERY_ACT) {
checkUpdate();
}
String user = config.getUser();
String pass = config.getPass();
if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
LoginPanel loginPanel = new LoginPanel();
int option = JOptionPane.showOptionDialog(UIFrame.this, loginPanel, "Login to osu!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION) {
if (loginPanel.getUsername().isEmpty() || loginPanel.getPassword().isEmpty()) {
JOptionPane.showMessageDialog(UIFrame.this, "Username or password cannot be empty.", "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
user = loginPanel.getUsername();
pass = loginPanel.getPassword();
} else {
return false;
}
}
try {
osu.login(user, pass);
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error logging in:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
try {
map = osu.getBeatmapInfo(url);
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error getting beatmap info:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
String modUrl = map.getThumbUrl();
URL thumbUrl = null;
try {
thumbUrl = new URL("http:" + modUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
return false;
}
URLConnection conn = null;
try {
conn = thumbUrl.openConnection();
} catch (IOException e) {
e.printStackTrace();
return false;
}
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
try {
thumb = ImageIO.read(conn.getInputStream());
} catch (IOException e) {
e.printStackTrace();
thumb = null;
}
URL downloadUrl = null;
try {
downloadUrl = new URL("http://osu.ppy.sh" + map.getDwnUrl());
} catch (MalformedURLException e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error validating download URL:\n" + e1, "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
String tmpdir = System.getProperty("java.io.tmpdir");
final String mapName = map.getName();
OsuDownloader dwn = new OsuDownloader(tmpdir, map.getDwnUrl().substring(3, map.getDwnUrl().length()) + " " + map.getName(), osu, downloadUrl);
QueueAction importAction;
if (rdbtnUseDefaultSettings.isSelected()) {
importAction = new BeatmapImportAction(config);
} else {
int action = -1;
String targetFileOrFolder = null;
if (rdbtnDownloadAndImport.isSelected()) {
action = 0;
} else if (rdbtnDownloadToOsu.isSelected()) {
action = 1;
} else if (rdbtnDownloadToFile.isSelected()) {
action = 2;
targetFileOrFolder = targetFile;
} else if (rdbtnDownloadToFolder.isSelected()) {
action = 3;
targetFileOrFolder = targetFolder;
}
importAction = new CustomImportAction(action, targetFileOrFolder);
}
QueueAction[] beforeActions = new QueueAction[] { new BeforeSoundAction(config) };
QueueAction[] afterActions = new QueueAction[] { new AfterSoundAction(config), new QueueAction() {
@Override
public void run(Queue queue) {
icon.displayMessage("Download completed for \"" + mapName + "\"", "This osumer queue has completed downloading.", TrayIcon.MessageType.INFO);
}
}, importAction };
boolean added = mgr.addQueue(new Queue(map.getName(), dwn, thumb, beforeActions, afterActions));
if (added) {
icon.displayMessage("Downloading \"" + mapName + "\"", "osumerExpress is downloading the requested beatmap!", TrayIcon.MessageType.INFO);
} else {
icon.displayMessage("Could not add \"" + mapName + "\" to queue", "It has already in queue/downloading or completed.", TrayIcon.MessageType.INFO);
}
tableModel.fireTableDataChanged();
return true;
}
use of com.github.mob41.osumer.io.OsuDownloader in project osumer by mob41.
the class Daemon method addQueue.
@Override
public MethodResult<Integer> addQueue(String url, int downloadAction, String targetFileOrFolder) throws RemoteException {
DumpManager.reportEvent("event", "queueAdd");
String user = config.getUser();
String pass = config.getPass();
if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
return new MethodResult<Integer>(ErrorCode.RESULT_NO_CREDENTIALS);
}
try {
osums.login(user, pass);
} catch (WithDumpException e) {
e.printStackTrace();
return new MethodResult<Integer>(ErrorCode.RESULT_LOGIN_FAILED, e.getDump());
}
OsuSong map;
try {
if (url.contains("b/")) {
map = osums.getBeatmapInfo(url);
} else {
map = osums.getSongInfo(url);
}
} catch (WithDumpException e) {
e.printStackTrace();
return new MethodResult<Integer>(ErrorCode.RESULT_GET_BEATMAP_INFO_FAILED, e.getDump());
}
String thumbUrl = "http:" + map.getThumbUrl();
String dwnUrlStr = map.getDwnUrl();
if (dwnUrlStr.length() <= 3) {
return new MethodResult<Integer>(ErrorCode.RESULT_DOWNLOAD_URL_TOO_SHORT);
}
URL downloadUrl = null;
try {
downloadUrl = new URL("https://osu.ppy.sh" + dwnUrlStr);
} catch (MalformedURLException e) {
e.printStackTrace();
return new MethodResult<Integer>(ErrorCode.RESULT_VALIDATE_DOWNLOAD_URL_FAILED);
}
String tmpdir = System.getProperty("java.io.tmpdir");
final String mapName = map.getName();
String fileName = dwnUrlStr.substring(3, map.getDwnUrl().length()) + " " + mapName;
fileName = fileName.replaceAll("[\\/:*?\"<>|]", " ");
OsuDownloader dwn = new OsuDownloader(tmpdir, fileName, osums, downloadUrl);
QueueAction importAction;
if (downloadAction == -1) {
importAction = new BeatmapImportAction(config);
} else {
importAction = new CustomImportAction(downloadAction, targetFileOrFolder);
}
QueueAction[] beforeActions = new QueueAction[] { new BeforeSoundAction(config) };
QueueAction[] afterActions = new QueueAction[] { new AfterSoundAction(config), new QueueAction() {
@Override
public void run(Queue queue) {
trayIcon.displayMessage("Download completed for \"" + mapName + "\"", "This osumer queue has completed downloading.", TrayIcon.MessageType.INFO);
}
}, importAction };
boolean added = queueManager.addQueue(new Queue(map.getName(), dwn, thumbUrl, beforeActions, afterActions));
if (added) {
trayIcon.displayMessage("Downloading \"" + mapName + "\"", "osumerExpress is downloading the requested beatmap!", TrayIcon.MessageType.INFO);
dwn.addObserver(new Observer() {
@Override
public void update(Observable o, Object arg) {
requestAllUiUpdateQueues();
}
});
DumpManager.reportEvent("event", "queueAdded");
if (!url.endsWith("/")) {
String beatmapNum = url.replaceAll("\\D+", "");
;
DumpManager.reportEvent("beatmap", "queueFrequency", beatmapNum);
}
} else {
trayIcon.displayMessage("Could not add \"" + mapName + "\" to queue", "It has already in queue/downloading or completed.", TrayIcon.MessageType.INFO);
}
requestAllUiUpdateQueues();
return new MethodResult<Integer>(ErrorCode.RESULT_OK);
}
use of com.github.mob41.osumer.io.OsuDownloader in project osumer by mob41.
the class UIFrame method addBtQueue.
public boolean addBtQueue(String url, boolean preview, boolean changeTab, QueueAction[] beforeActions, QueueAction[] afterActions) {
if (config.getCheckUpdateFreq() == Config.CHECK_UPDATE_FREQ_EVERY_ACT) {
checkUpdate();
}
map = null;
thumb = null;
pbd = new ProgressDialog();
new Thread() {
public void run() {
pbd.getProgressBar().setIndeterminate(true);
pbd.getLabel().setText("Status: Getting configuration...");
String user = config.getUser();
String pass = config.getPass();
if (user == null || user.isEmpty() || pass == null || pass.isEmpty()) {
pbd.getLabel().setText("Status: Prompting username and password...");
LoginPanel loginPanel = new LoginPanel();
int option = JOptionPane.showOptionDialog(UIFrame.this, loginPanel, "Login to osu!", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION) {
if (loginPanel.getUsername().isEmpty() || loginPanel.getPassword().isEmpty()) {
JOptionPane.showMessageDialog(UIFrame.this, "Username or password cannot be empty.", "Error", JOptionPane.ERROR_MESSAGE);
pbd.dispose();
return;
}
user = loginPanel.getUsername();
pass = loginPanel.getPassword();
} else {
pbd.dispose();
return;
}
}
pbd.getLabel().setText("Status: Logging in...");
try {
osu.login(user, pass);
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error logging in:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
pbd.dispose();
return;
}
String modUrl = url.replace("osu.ppy.sh", "old.ppy.sh");
pbd.getLabel().setText("Status: Obtaining beatmap information...");
try {
map = osu.getBeatmapInfo(modUrl);
} catch (DebuggableException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error getting beatmap info:\n" + e.getDump().getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
pbd.dispose();
return;
}
pbd.dispose();
pbd = null;
}
}.start();
pbd.setLocationRelativeTo(UIFrame.this);
pbd.setModal(true);
pbd.setVisible(true);
if (map == null) {
return false;
}
boolean stillDwn = true;
if (preview) {
BeatmapPreviewDialog bpd = new BeatmapPreviewDialog(map);
bpd.setLocationRelativeTo(UIFrame.this);
bpd.setModal(true);
bpd.setVisible(true);
stillDwn = bpd.isSelectedYes();
thumb = bpd.getDownloadedImage();
}
if (thumb == null) {
pbd = new ProgressDialog();
new Thread() {
public void run() {
pbd.getProgressBar().setIndeterminate(true);
pbd.getLabel().setText("Status: Downloading thumb image...");
URL url = null;
try {
url = new URL("http:" + map.getThumbUrl());
} catch (MalformedURLException e) {
e.printStackTrace();
pbd.dispose();
return;
}
URLConnection conn = null;
try {
conn = url.openConnection();
} catch (IOException e) {
e.printStackTrace();
pbd.dispose();
return;
}
conn.setConnectTimeout(5000);
conn.setReadTimeout(5000);
try {
thumb = ImageIO.read(conn.getInputStream());
} catch (IOException e) {
e.printStackTrace();
pbd.dispose();
return;
}
pbd.dispose();
}
}.start();
pbd.setLocationRelativeTo(UIFrame.this);
pbd.setModal(true);
pbd.setVisible(true);
}
if (stillDwn) {
URL downloadUrl = null;
try {
downloadUrl = new URL("http://osu.ppy.sh" + map.getDwnUrl());
} catch (MalformedURLException e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(UIFrame.this, "Error validating download URL:\n" + e1, "Error", JOptionPane.ERROR_MESSAGE);
return false;
}
String tmpdir = System.getProperty("java.io.tmpdir");
final String mapName = map.getName();
OsuDownloader dwn = new OsuDownloader(tmpdir, map.getDwnUrl().substring(3, map.getDwnUrl().length()) + " " + map.getName(), osu, downloadUrl);
QueueAction importAction;
if (rdbtnUseDefaultSettings.isSelected()) {
importAction = new BeatmapImportAction(config);
} else {
int action = -1;
String targetFileOrFolder = null;
if (rdbtnDownloadAndImport.isSelected()) {
action = 0;
} else if (rdbtnDownloadToOsu.isSelected()) {
action = 1;
} else if (rdbtnDownloadToFile.isSelected()) {
action = 2;
targetFileOrFolder = targetFile;
} else if (rdbtnDownloadToFolder.isSelected()) {
action = 3;
targetFileOrFolder = targetFolder;
}
importAction = new CustomImportAction(action, targetFileOrFolder);
}
if (beforeActions == null) {
beforeActions = new QueueAction[] { new BeforeSoundAction(config) };
}
if (afterActions == null) {
afterActions = new QueueAction[] { new AfterSoundAction(config), new QueueAction() {
@Override
public void run(Queue queue) {
icon.displayMessage("Download completed for \"" + mapName + "\"", "This osumer queue has completed downloading.", TrayIcon.MessageType.INFO);
}
}, importAction };
}
boolean added = mgr.addQueue(new Queue(map.getName(), dwn, thumb, beforeActions, afterActions));
if (added) {
icon.displayMessage("Downloading \"" + mapName + "\"", "osumerExpress is downloading the requested beatmap!", TrayIcon.MessageType.INFO);
} else {
icon.displayMessage("Could not add \"" + mapName + "\" to queue", "It has already in queue/downloading or completed.", TrayIcon.MessageType.INFO);
}
tableModel.fireTableDataChanged();
if (changeTab) {
tab.setSelectedIndex(1);
}
} else {
icon.displayMessage("Could not download \"" + url + "\"", "Error occurred when finding beatmap. Start UI to see details.", TrayIcon.MessageType.INFO);
}
return stillDwn;
}
Aggregations