Use new API endpoints to submit songs.

secondmonitor
sigonasr2 5 years ago
parent d8a85c462e
commit 7e1b536a1d
  1. 1
      DivaBot/.classpath
  2. 5
      DivaBot/pom.xml
  3. 2
      DivaBot/src/sig/DrawCanvas.java
  4. 94
      DivaBot/src/sig/MyRobot.java
  5. 11
      DivaBot/src/sig/Result.java

@ -2,7 +2,6 @@
<classpath> <classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes> <attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>

@ -29,5 +29,10 @@
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.5.12</version> <version>4.5.12</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.12</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -110,7 +110,7 @@ public class DrawCanvas extends JPanel{
artist = obj.getString("artist"); artist = obj.getString("artist");
obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty); obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/bestplay/sigonasr2/"+URLEncoder.encode(MyRobot.p.songname, StandardCharsets.UTF_8.toString()).replaceAll("\\+", "%20")+"/"+difficulty);
if (obj.has("cool")) { if (obj.has("cool")) {
bestPlay = new Result(MyRobot.p.songname,difficulty,obj.getInt("cool"),obj.getInt("fine"),obj.getInt("safe"),obj.getInt("sad"),obj.getInt("worst"),(float)obj.getDouble("percent")); bestPlay = new Result(MyRobot.p.songname,difficulty,obj.getInt("cool"),obj.getInt("fine"),obj.getInt("safe"),obj.getInt("sad"),obj.getInt("worst"),(float)obj.getDouble("percent"),null);
} else { } else {
bestPlay = null; bestPlay = null;
} }

@ -64,6 +64,7 @@ import org.json.JSONObject;
import sig.utils.FileUtils; import sig.utils.FileUtils;
import sig.utils.ImageUtils; import sig.utils.ImageUtils;
import sig.utils.SoundUtils; import sig.utils.SoundUtils;
import sig.utils.WebUtils;
public class MyRobot{ public class MyRobot{
static Robot MYROBOT; static Robot MYROBOT;
@ -107,7 +108,7 @@ public class MyRobot{
long lastSongSelectTime = System.currentTimeMillis(); long lastSongSelectTime = System.currentTimeMillis();
static TypeFace typeface1,typeface2; static TypeFace typeface1,typeface2;
static Thread t = null;
String prevSongTitle = ""; String prevSongTitle = "";
String prevDifficulty = ""; String prevDifficulty = "";
@ -242,6 +243,7 @@ public class MyRobot{
int playId = songFolderFiles.length; int playId = songFolderFiles.length;
File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId); File playFolder = new File(selectedSong.title+"/"+difficulty+"/"+playId);
playFolder.mkdir(); playFolder.mkdir();
File f = new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+cool+"_"+fine+"_"+safe+"_"+sad+"_"+worst+"_"+percent+".png");
try { try {
/*FileUtils.copyFileDir(new File(tmp,"cool"), new File(playFolder,"cool")); /*FileUtils.copyFileDir(new File(tmp,"cool"), new File(playFolder,"cool"));
FileUtils.copyFileDir(new File(tmp,"fine"), new File(playFolder,"fine")); FileUtils.copyFileDir(new File(tmp,"fine"), new File(playFolder,"fine"));
@ -250,21 +252,20 @@ public class MyRobot{
FileUtils.copyFileDir(new File(tmp,"worst"), new File(playFolder,"worst")); FileUtils.copyFileDir(new File(tmp,"worst"), new File(playFolder,"worst"));
FileUtils.copyFileDir(new File(tmp,"percent"), new File(playFolder,"percent"));*/ FileUtils.copyFileDir(new File(tmp,"percent"), new File(playFolder,"percent"));*/
//FileUtils.deleteFile(tmp); //FileUtils.deleteFile(tmp);
ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(418,204,1227,690)),"png",new File(playFolder,selectedSong.title+"_"+difficulty+"play_"+cool+"_"+fine+"_"+safe+"_"+sad+"_"+worst+"_"+percent+".png")); ImageIO.write(MYROBOT.createScreenCapture(new Rectangle(418,204,1227,690)),"png",f);
recordedResults=true;
lastcool=cool;
lastfine=fine;
lastsafe=safe;
lastsad=sad;
lastworst=worst;
lastpercent=percent;
lastfail=fail;
results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent,fail,f));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
recordedResults=true;
lastcool=cool;
lastfine=fine;
lastsafe=safe;
lastsad=sad;
lastworst=worst;
lastpercent=percent;
lastfail=fail;
results.add(new Result(selectedSong.title,difficulty,cool,fine,safe,sad,worst,percent,fail));
SoundUtils.playSound("collect_item.wav");
gotoxy(800,64); gotoxy(800,64);
click(); click();
MYROBOT.setAutoDelay(0); MYROBOT.setAutoDelay(0);
@ -279,60 +280,27 @@ public class MyRobot{
if (results.size()>0) { if (results.size()>0) {
recordingResults=true; recordingResults=true;
for (Result r : results) { for (Result r : results) {
r.songName=r.songName.equalsIgnoreCase("PIANOGIRL")?"PIANO*GIRL":(r.songName.equalsIgnoreCase("16 -out of the gravity-"))?"1/6 -out of the gravity-":r.songName; new Thread() {
HttpClient httpclient = HttpClients.createDefault(); public void run() {
HttpPost httppost = new HttpPost("http://45.33.13.215:4501/submit"); HashMap<String,String> s = new HashMap<>();
s.put("username","sigonasr2");
// Request parameters and other properties. s.put("authentication_token","sig");
List<NameValuePair> params = new ArrayList<NameValuePair>(); WebUtils.POSTimage("http://projectdivar.com/upload", r.f, s);
params.add(new BasicNameValuePair("song", r.songName)); SoundUtils.playSound("collect_item.wav");
params.add(new BasicNameValuePair("username", "sigonasr2"));
params.add(new BasicNameValuePair("authentication_token", "sig"));
params.add(new BasicNameValuePair("difficulty", r.difficulty));
params.add(new BasicNameValuePair("cool", Integer.toString(r.cool)));
params.add(new BasicNameValuePair("fine", Integer.toString(r.fine)));
params.add(new BasicNameValuePair("safe", Integer.toString(r.safe)));
params.add(new BasicNameValuePair("sad", Integer.toString(r.sad)));
params.add(new BasicNameValuePair("worst", Integer.toString(r.worst)));
params.add(new BasicNameValuePair("percent", Float.toString(r.percent)));
params.add(new BasicNameValuePair("fail", Boolean.toString(r.fail)));
try {
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//Execute and get the response.
HttpResponse response = null;
try {
response = httpclient.execute(httppost);
} catch (IOException e) {
e.printStackTrace();
}
HttpEntity entity = response.getEntity();
if (entity != null) { try {
try (InputStream instream = entity.getContent()) { JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
Scanner s = new Scanner(instream).useDelimiter("\\A"); p.lastRating = p.overallrating;
String result = s.hasNext() ? s.next() : ""; p.overallrating = (int)obj.getDouble("rating");
System.out.println(result); if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
instream.close(); p.pullData(selectedSong.title, difficulty);
} catch (UnsupportedOperationException | IOException e) { } catch (JSONException | IOException e) {
e.printStackTrace(); e.printStackTrace();
}
} }
} }.start();
} }
results.clear(); results.clear();
try {
JSONObject obj = FileUtils.readJsonFromUrl("http://45.33.13.215:4501/rating/sigonasr2");
p.lastRating = p.overallrating;
p.overallrating = (int)obj.getDouble("rating");
if (p.lastRating<p.overallrating) {p.ratingTime=System.currentTimeMillis();}
p.pullData(selectedSong.title, difficulty);
} catch (JSONException | IOException e) {
e.printStackTrace();
}
/*MYROBOT.setAutoDelay(0); /*MYROBOT.setAutoDelay(0);
MYROBOT.keyPress(KeyEvent.VK_ALT); MYROBOT.keyPress(KeyEvent.VK_ALT);
MYROBOT.keyPress(KeyEvent.VK_TAB); MYROBOT.keyPress(KeyEvent.VK_TAB);

@ -1,12 +1,16 @@
package sig; package sig;
import java.awt.image.BufferedImage;
import java.io.File;
public class Result { public class Result {
String songName; String songName;
String difficulty; String difficulty;
int cool,fine,safe,sad,worst; int cool,fine,safe,sad,worst;
float percent; float percent;
boolean fail; boolean fail;
public Result(String song,String diff,int cool,int fine,int safe,int sad,int worst,float percent) { File f;
public Result(String song,String diff,int cool,int fine,int safe,int sad,int worst,float percent,File f) {
this.songName=song; this.songName=song;
this.difficulty=diff; this.difficulty=diff;
this.cool=cool; this.cool=cool;
@ -15,9 +19,10 @@ public class Result {
this.sad=sad; this.sad=sad;
this.worst=worst; this.worst=worst;
this.percent=percent; this.percent=percent;
this.f=f;
} }
public Result(String song,String diff,int cool,int fine,int safe,int sad,int worst,float percent,boolean fail) { public Result(String song,String diff,int cool,int fine,int safe,int sad,int worst,float percent,boolean fail,File f) {
this(song,diff,cool,fine,safe,sad,worst,percent); this(song,diff,cool,fine,safe,sad,worst,percent,f);
this.fail=fail; this.fail=fail;
} }
public String display() { public String display() {

Loading…
Cancel
Save