Skip to content

Commit

Permalink
Fixed a lot bugs, improved sound handling, pure search term added
Browse files Browse the repository at this point in the history
  • Loading branch information
thirdy committed Dec 30, 2015
1 parent da15d9c commit 45a3a26
Show file tree
Hide file tree
Showing 23 changed files with 701 additions and 640 deletions.
110 changes: 67 additions & 43 deletions durian/config.properties
Original file line number Diff line number Diff line change
@@ -1,61 +1,85 @@
########################################################################
# search
########################################################################
manual.search.prefix=tmpsc nobo online
automated.search.prefix=tmpsc bo online
manual.search.prefix=tmpsc bo online

automated.search.wait.minutes=15
automated.search.inbetween.wait.seconds=15

# restart to apply
automated.search.enabled=true

########################################################################
# sound
########################################################################
# can be mp3, can be full path, e.g. C:/Windows/Media/chimes.wav (do not use backlash)
automated.search.sound.filename=notification.wav
# valid values: 0.0 to 1.0
automated.search.sound.volume=0.8
# valid values:
# EACH_SEARCH - every search will play a sound if items are found for that search
# ONCE - sound is only played once if the items are found for all the searches
automated.search.sound.mode=ONCE

########################################################################
# blacklist
########################################################################
# comma separated values
automated.search.blacklist=
manual.search.blacklist=
automated.search.blacklist=
manual.search.blacklist=

# experimental
########################################################################
# auto-verify
# enabling this will make your search slower
# note that right-click on manual tab will run verify individually
automated.auto.verify=true
# note that right-click on manual tab will run verify individually
########################################################################
automated.auto.verify=true
manual.auto.verify=false
automated.auto.verify.wait.millisec=5000
manual.auto.verify.wait.millisec=5000

# look and feel
# see the ff for screenshots:
# http://insubstantial.github.io/insubstantial/substance/docs/skins/toneddown.html
# http://insubstantial.github.io/insubstantial/substance/docs/skins/dark.html

# available substance look n feel:
lookandfeel=org.pushingpixels.substance.api.skin.SubstanceDustLookAndFeel

# org.pushingpixels.substance.api.skin.SubstanceAutumnLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceBusinessBlackSteelLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceBusinessBlueSteelLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceCeruleanLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceChallengerDeepLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceCremeCoffeeLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceCremeLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceDustCoffeeLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceDustLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceEmeraldDuskLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceGeminiLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceGraphiteAquaLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceGraphiteGlassLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceGraphiteLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceMagellanLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceMarinerLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceMistAquaLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceMistSilverLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceModerateLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceNebulaBrickWallLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceNebulaLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceOfficeBlack2007LookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceOfficeBlue2007LookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceOfficeSilver2007LookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceRavenLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceSaharaLookAndFeel
# org.pushingpixels.substance.api.skin.SubstanceTwilightLookAndFeel
########################################################################
# Look and Feel
########################################################################
lookandfeel=SubstanceDustLookAndFeel

# Other choices:

# SubstanceAutumnLookAndFeel
# SubstanceBusinessBlackSteelLookAndFeel
# SubstanceBusinessBlueSteelLookAndFeel
# SubstanceBusinessLookAndFeel
# SubstanceCeruleanLookAndFeel
# SubstanceChallengerDeepLookAndFeel
# SubstanceCremeCoffeeLookAndFeel
# SubstanceCremeLookAndFeel
# SubstanceDustCoffeeLookAndFeel
# SubstanceDustLookAndFeel
# SubstanceEmeraldDuskLookAndFeel
# SubstanceGeminiLookAndFeel
# SubstanceGraphiteAquaLookAndFeel
# SubstanceGraphiteGlassLookAndFeel
# SubstanceGraphiteLookAndFeel
# SubstanceMagellanLookAndFeel
# SubstanceMarinerLookAndFeel
# SubstanceMistAquaLookAndFeel
# SubstanceMistSilverLookAndFeel
# SubstanceModerateLookAndFeel
# SubstanceNebulaBrickWallLookAndFeel
# SubstanceNebulaLookAndFeel
# SubstanceOfficeBlack2007LookAndFeel
# SubstanceOfficeBlue2007LookAndFeel
# SubstanceOfficeSilver2007LookAndFeel
# SubstanceRavenLookAndFeel
# SubstanceSaharaLookAndFeel
# SubstanceTwilightLookAndFeel
# com.sun.java.swing.plaf.windows.WindowsLookAndFeel

# enable look and feel to skin title bars
# this might cause flickering on non-windows - http://bugs.java.com/bugdatabase/view_bug.do?bug_id=5079688
lookandfeel.decorated.enabled=true
lookandfeel.decorated.enabled=true

# see the ff for screenshots on substance look and feel:
# http://insubstantial.github.io/insubstantial/substance/docs/skins/toneddown.html
# http://insubstantial.github.io/insubstantial/substance/docs/skins/dark.html
1 change: 1 addition & 0 deletions durian/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ ring 25wed 60life
1hsword 30flatphys
2hsword 100ipd 20flatphys
mirror
2haxe 450pdps
3 changes: 3 additions & 0 deletions durian/src/main/java/qic/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public static void reloadLookAndFeel() {
}
try {
String lookAndFeel = Config.getPropety(Config.LOOK_AND_FEEL, "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
if (lookAndFeel.startsWith("Substance")) {
lookAndFeel = "org.pushingpixels.substance.api.skin." + lookAndFeel;
}
UIManager.setLookAndFeel(lookAndFeel);
} catch (Exception e) {
try {
Expand Down
5 changes: 1 addition & 4 deletions durian/src/main/java/qic/SearchPageScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ public List<SearchResultItem> parse() {
items = content.getElementsByClass("item");
}

// System.out.println(items.get(86).toString());

// System.out.println("Items");
for (Element element : items) {

SearchResultItem item = new SearchResultItem();
Expand Down Expand Up @@ -311,7 +308,7 @@ public List<String> getSeller() {
labelVal("Thread", thread),
labelVal("Verified", verified.name()),
// labelVal("", threadUrl),
labelVal("Online", String.valueOf(containsIgnoreCase("online", online))));
labelVal("Online", String.valueOf(containsIgnoreCase(online, "online"))));
}

private String labelVal(String label, String val) {
Expand Down
32 changes: 19 additions & 13 deletions durian/src/main/java/qic/ui/AutomatedPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.Arrays;
import java.util.List;

import javax.sound.sampled.LineUnavailableException;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
Expand All @@ -53,8 +52,9 @@
import qic.SearchPageScraper.SearchResultItem;
import qic.ui.extra.CaptchaDetectedException;
import qic.util.Config;
import qic.util.Config.SoundMode;
import qic.util.DurianUtils;
import qic.util.SoundUtils;
import qic.util.SoundUtilsFX;
import qic.util.SwingUtil;
import qic.util.Util;
import qic.util.Verify;
Expand Down Expand Up @@ -148,8 +148,10 @@ protected Void doInBackground() {
countdown = waitSeconds;
try {
runJob();
} catch (CaptchaDetectedException e) {
} catch (Exception e) {
SwingUtil.showError(e);
} finally {
panel.runBtn.setEnabled(true);
}
} else {
countdown--;
Expand Down Expand Up @@ -181,24 +183,30 @@ private void runJob() throws CaptchaDetectedException {

itemResults.stream().forEach(this::publish);

int count = 0;
if (getBooleanProperty(AUTOMATED_AUTO_VERIFY, false)) {
long sleep = Config.getLongProperty(Config.AUTOMATED_AUTO_VERIFY_SLEEP, 5000);
total += runVerify(itemResults, sleep);
count += runVerify(itemResults, sleep);
} else {
total += itemResults.size();
count += itemResults.size();
}

if (total > 0) {
if (Config.getSoundMode() == SoundMode.EACH_SEARCH && count > 0) {
panel.playsound();
}

total += count;

if (idx < searches.length) {
logger.info(format("Automated Search - now sleep for %d seconds", waitSecondsInBetween));
sleep(waitSecondsInBetween * 1000);
}
}

if (Config.getSoundMode() == SoundMode.ONCE && total > 0) {
panel.playsound();
}
}
panel.runBtn.setEnabled(true);
}

@Override
Expand Down Expand Up @@ -248,11 +256,9 @@ public void saveToFile() {
}

private void playsound() {
try {
SoundUtils.tone(5000,100);
} catch (LineUnavailableException e) {
e.printStackTrace();
}
String pathToFile = Config.getPropety(Config.AUTOMATED_SEARCH_SOUND_FILENAME, "notification.wav");
double vol = Config.getDoubleProperty(Config.AUTOMATED_SEARCH_SOUND_VOLUME, 1.0);
new Thread(() -> SoundUtilsFX.play(pathToFile, vol)).run();
}

}
8 changes: 6 additions & 2 deletions durian/src/main/java/qic/ui/ConfigPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -67,9 +69,11 @@ public void focusGained(FocusEvent e) {

private void saveAndReloadConfig() {
try {
Util.overwriteFile(CONFIG_PROPERTIES_FILENAME, textArea.getText());
// directly calling getText() from TextArea is causing bad values, probably swing quirks
Document document = textArea.getDocument();
Util.overwriteFile(CONFIG_PROPERTIES_FILENAME, document.getText(0, document.getLength()));
Config.loadConfig();
} catch (IOException e) {
} catch (BadLocationException | IOException e) {
logger.error("Error while saving to " + CONFIG_PROPERTIES_FILENAME);
showError(e);
}
Expand Down
2 changes: 2 additions & 0 deletions durian/src/main/java/qic/ui/LoggerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package qic.ui;

import java.awt.BorderLayout;
import java.awt.Font;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
Expand All @@ -39,6 +40,7 @@ public class LoggerPanel extends JPanel {

public LoggerPanel() {
super(new BorderLayout());
textArea.setFont(new Font("Consolas", Font.TRUETYPE_FONT, 12));

JTextAreaAppender appender = new JTextAreaAppender(textArea);
String PATTERN = "%-4r [%t] %-5p %c %x - %m%n";
Expand Down
63 changes: 32 additions & 31 deletions durian/src/main/java/qic/ui/ManualPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,33 @@ public void actionPerformed(ActionEvent e) {
Worker<Command> worker = new Worker<Command>(
() -> {
runBtn.setEnabled(false);
return runQuery(main, tfText);
Command result = null;
try {
result = runQuery(main, tfText);
} catch (Exception ex) {
runBtn.setEnabled(true);
SwingUtil.showError(ex);
}
return result;
},
command -> {
if (command.invalidSearchTerms.isEmpty()) {
addDataToTable(command);
saveSearchToList(tfText);
invalidTermsLbl.setText("");
invalidTermsLblLbl.setText("");
if (getBooleanProperty(MANUAL_AUTO_VERIFY, false)) {
long sleep = Config.getLongProperty(Config.MANUAL_AUTO_VERIFY_SLEEP, 5000);
table.runAutoVerify(sleep);
if (command != null) {
if (command.invalidSearchTerms.isEmpty()) {
addDataToTable(command);
saveSearchToList(tfText);
invalidTermsLbl.setText("");
invalidTermsLblLbl.setText("");
if (getBooleanProperty(MANUAL_AUTO_VERIFY, false)) {
long sleep = Config.getLongProperty(Config.MANUAL_AUTO_VERIFY_SLEEP, 5000);
table.runAutoVerify(sleep);
}
} else {
String invalidTermsStr = command.invalidSearchTerms.stream().collect(joining(", "));
invalidTermsLbl.setText(invalidTermsStr + " ");
invalidTermsLblLbl.setText(" Invalid: ");
}
} else {
String invalidTermsStr = command.invalidSearchTerms.stream().collect(joining(", "));
invalidTermsLbl.setText(invalidTermsStr + " ");
invalidTermsLblLbl.setText(" Invalid: ");
}
runBtn.setEnabled(true);
}, ex -> {
runBtn.setEnabled(true);
logger.error("Exception occured: ", ex);
SwingUtil.showError(ex);
});
worker.execute();
}
Expand Down Expand Up @@ -208,21 +213,17 @@ private void saveSearchToList(String tfText) {
searchJListModel.addElement(tfText);
}

private Command runQuery(Main main, String tfText) {
try {
String line = null;
if (StringUtils.startsWithIgnoreCase(tfText, "sort")) {
line = tfText;
} else {
String prefix = Config.getPropety(Config.MANUAL_SEARCH_PREFIX, "tmpsc online bo").trim();
line = String.format("s %s %s", prefix, tfText);
}

logger.info("Now running search: " + line);
return main.processLine(line);
} catch (Exception e) {
throw new RuntimeException(e);
private Command runQuery(Main main, String tfText) throws Exception {
String line = null;
if (StringUtils.startsWithIgnoreCase(tfText, "sort")) {
line = tfText;
} else {
String prefix = Config.getPropety(Config.MANUAL_SEARCH_PREFIX, "tmpsc online bo").trim();
line = String.format("s %s %s", prefix, tfText);
}

logger.info("Now running search: " + line);
return main.processLine(line);
}

public void saveToFile() {
Expand Down
2 changes: 2 additions & 0 deletions durian/src/main/java/qic/ui/QicFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import javax.swing.event.ChangeListener;

import qic.Main;
import qic.util.SoundUtilsFX;

/**
* @author thirdy
Expand All @@ -44,6 +45,7 @@ public QicFrame(Main main, String query) {

Image icon = Toolkit.getDefaultToolkit().getImage(QicFrame.class.getResource("/durian128.png"));
this.setIconImage(icon);
SoundUtilsFX.init();

ManualPanel manualPanel = new ManualPanel(main);
AutomatedPanel automatedPanel = new AutomatedPanel(main);
Expand Down
Loading

0 comments on commit 45a3a26

Please sign in to comment.