This commit is contained in:
Gaboso 2018-06-02 09:51:17 -04:00
commit 3529d679ff
5 changed files with 150 additions and 82 deletions

View File

@ -1,5 +1,5 @@
{ {
"currentHash": "689d4a5b270b62be7defbdbb696de79c8a223ab7497391e1d610eaf1cb860510", "currentHash": "f6e1e6c931abfbeffdd37dabb65f83e4335ca11ccc017f31e1d835ee6e6bec7a",
"changeList": [ "changeList": [
"1.7.50: Ripme now checks file hash before running update; fixed update bug which cased ripme to report every update as new", "1.7.50: Ripme now checks file hash before running update; fixed update bug which cased ripme to report every update as new",
"1.7.49: Fixed -n flag; Added ability to change locale at runtime and from gui; Update kr_KR translation; Removed support for tnbtu.com; No longer writes url to url_history file is save urls only is checked", "1.7.49: Fixed -n flag; Added ability to change locale at runtime and from gui; Update kr_KR translation; Removed support for tnbtu.com; No longer writes url to url_history file is save urls only is checked",

View File

@ -241,6 +241,10 @@ public class App {
ripURL(url, !cl.hasOption("n")); ripURL(url, !cl.hasOption("n"));
} }
if (cl.hasOption('j')) {
UpdateUtils.updateProgramCLI();
}
} }
/** /**
@ -290,6 +294,7 @@ public class App {
opts.addOption("v", "version", false, "Show current version"); opts.addOption("v", "version", false, "Show current version");
opts.addOption("s", "socks-server", true, "Use socks server ([user:password]@host[:port])"); opts.addOption("s", "socks-server", true, "Use socks server ([user:password]@host[:port])");
opts.addOption("p", "proxy-server", true, "Use HTTP Proxy server ([user:password]@host[:port])"); opts.addOption("p", "proxy-server", true, "Use HTTP Proxy server ([user:password]@host[:port])");
opts.addOption("j", "update", false, "Update ripme");
return opts; return opts;
} }

View File

@ -37,11 +37,8 @@ public class TumblrRipper extends AlbumRipper {
private static final String TUMBLR_AUTH_CONFIG_KEY = "tumblr.auth"; private static final String TUMBLR_AUTH_CONFIG_KEY = "tumblr.auth";
private static boolean useDefaultApiKey = false; // fall-back for bad user-specified key private static boolean useDefaultApiKey = false; // fall-back for bad user-specified key
private static final List<String> APIKEYS = Arrays.asList("JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX", private static String API_KEY = null;
"FQrwZMCxVnzonv90rgNUJcAk4FpnoS0mYuSuGYqIpM2cFgp9L4",
"qpdkY6nMknksfvYAhf2xIHp0iNRLkMlcWShxqzXyFJRxIsZ1Zz");
private static int genNum = new Random().nextInt(APIKEYS.size());
private static final String API_KEY = APIKEYS.get(genNum); // Select random API key from APIKEYS
/** /**
* Gets the API key. * Gets the API key.
@ -49,6 +46,10 @@ public class TumblrRipper extends AlbumRipper {
* @return Tumblr API key * @return Tumblr API key
*/ */
public static String getApiKey() { public static String getApiKey() {
if (API_KEY == null) {
API_KEY = pickRandomApiKey();
}
if (useDefaultApiKey || Utils.getConfigString(TUMBLR_AUTH_CONFIG_KEY, "JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX").equals("JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX")) { if (useDefaultApiKey || Utils.getConfigString(TUMBLR_AUTH_CONFIG_KEY, "JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX").equals("JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX")) {
logger.info("Using api key: " + API_KEY); logger.info("Using api key: " + API_KEY);
return API_KEY; return API_KEY;
@ -60,9 +61,19 @@ public class TumblrRipper extends AlbumRipper {
} }
private static String pickRandomApiKey() {
final List<String> APIKEYS = Arrays.asList("JFNLu3CbINQjRdUvZibXW9VpSEVYYtiPJ86o8YmvgLZIoKyuNX",
"FQrwZMCxVnzonv90rgNUJcAk4FpnoS0mYuSuGYqIpM2cFgp9L4",
"qpdkY6nMknksfvYAhf2xIHp0iNRLkMlcWShxqzXyFJRxIsZ1Zz");
int genNum = new Random().nextInt(APIKEYS.size());
logger.info(genNum);
final String API_KEY = APIKEYS.get(genNum); // Select random API key from APIKEYS
return API_KEY;
}
public TumblrRipper(URL url) throws IOException { public TumblrRipper(URL url) throws IOException {
super(url); super(url);
if (API_KEY == null) { if (getApiKey() == null) {
throw new IOException("Could not find tumblr authentication key in configuration"); throw new IOException("Could not find tumblr authentication key in configuration");
} }
} }
@ -245,7 +256,7 @@ public class TumblrRipper extends AlbumRipper {
} }
} else if (post.has("video_url")) { } else if (post.has("video_url")) {
try { try {
fileURL = new URL(post.getString("video_url").replaceAll("http", "https")); fileURL = new URL(post.getString("video_url").replaceAll("http:", "https:"));
addURLToDownload(fileURL); addURLToDownload(fileURL);
} catch (Exception e) { } catch (Exception e) {
logger.error("[!] Error while parsing video in " + post, e); logger.error("[!] Error while parsing video in " + post, e);

View File

@ -198,7 +198,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
if (!configurationPanel.isVisible()) { if (!configurationPanel.isVisible()) {
optionConfiguration.doClick(); optionConfiguration.doClick();
} }
Runnable r = () -> UpdateUtils.updateProgram(configUpdateLabel); Runnable r = () -> UpdateUtils.updateProgramGUI(configUpdateLabel);
new Thread(r).start(); new Thread(r).start();
} }
@ -786,7 +786,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
} }
}); });
configUpdateButton.addActionListener(arg0 -> { configUpdateButton.addActionListener(arg0 -> {
Thread t = new Thread(() -> UpdateUtils.updateProgram(configUpdateLabel)); Thread t = new Thread(() -> UpdateUtils.updateProgramGUI(configUpdateLabel));
t.start(); t.start();
}); });
configLogLevelCombobox.addActionListener(arg0 -> { configLogLevelCombobox.addActionListener(arg0 -> {

View File

@ -39,8 +39,57 @@ public class UpdateUtils {
} }
return thisVersion; return thisVersion;
} }
public static void updateProgramCLI() {
logger.info("Checking for update...");
public static void updateProgram(JLabel configUpdateLabel) { Document doc = null;
try {
logger.debug("Retrieving " + UpdateUtils.updateJsonURL);
doc = Jsoup.connect(UpdateUtils.updateJsonURL)
.timeout(10 * 1000)
.ignoreContentType(true)
.get();
} catch (IOException e) {
logger.error("Error while fetching update: ", e);
JOptionPane.showMessageDialog(null,
"<html><font color=\"red\">Error while fetching update: " + e.getMessage() + "</font></html>",
"RipMe Updater",
JOptionPane.ERROR_MESSAGE);
return;
} finally {
logger.info("Current version: " + getThisJarVersion());
}
String jsonString = doc.body().html().replaceAll("&quot;", "\"");
ripmeJson = new JSONObject(jsonString);
JSONArray jsonChangeList = ripmeJson.getJSONArray("changeList");
StringBuilder changeList = new StringBuilder();
for (int i = 0; i < jsonChangeList.length(); i++) {
String change = jsonChangeList.getString(i);
if (change.startsWith(UpdateUtils.getThisJarVersion() + ":")) {
break;
}
changeList.append("<br> + ").append(change);
}
String latestVersion = ripmeJson.getString("latestVersion");
if (UpdateUtils.isNewerVersion(latestVersion)) {
logger.info("Found newer version: " + latestVersion);
logger.info("Downloading new version...");
logger.info("New version found, downloading...");
try {
UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion), false);
} catch (IOException e) {
logger.error("Error while updating: ", e);
}
} else {
logger.debug("This version (" + UpdateUtils.getThisJarVersion() +
") is the same or newer than the website's version (" + latestVersion + ")");
logger.info("v" + UpdateUtils.getThisJarVersion() + " is the latest version");
logger.debug("Running latest version: " + UpdateUtils.getThisJarVersion());
}
}
public static void updateProgramGUI(JLabel configUpdateLabel) {
configUpdateLabel.setText("Checking for update..."); configUpdateLabel.setText("Checking for update...");
Document doc = null; Document doc = null;
@ -90,7 +139,7 @@ public class UpdateUtils {
configUpdateLabel.setText("<html><font color=\"green\">Downloading new version...</font></html>"); configUpdateLabel.setText("<html><font color=\"green\">Downloading new version...</font></html>");
logger.info("New version found, downloading..."); logger.info("New version found, downloading...");
try { try {
UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion)); UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion), true);
} catch (IOException e) { } catch (IOException e) {
JOptionPane.showMessageDialog(null, JOptionPane.showMessageDialog(null,
"Error while updating: " + e.getMessage(), "Error while updating: " + e.getMessage(),
@ -166,7 +215,7 @@ public class UpdateUtils {
return null; return null;
} }
private static void downloadJarAndLaunch(String updateJarURL) private static void downloadJarAndLaunch(String updateJarURL, Boolean shouldLaunch)
throws IOException { throws IOException {
Response response; Response response;
response = Jsoup.connect(updateJarURL) response = Jsoup.connect(updateJarURL)
@ -190,7 +239,7 @@ public class UpdateUtils {
} else { } else {
logger.info("Hash is good"); logger.info("Hash is good");
} }
if (shouldLaunch) {
// Setup updater script // Setup updater script
final String batchFile, script; final String batchFile, script;
final String[] batchExec; final String[] batchExec;
@ -207,8 +256,7 @@ public class UpdateUtils {
+ "del " + batchPath + "\r\n"; + "del " + batchPath + "\r\n";
batchExec = new String[]{batchPath}; batchExec = new String[]{batchPath};
} } else {
else {
// Mac / Linux // Mac / Linux
batchFile = "update_ripme.sh"; batchFile = "update_ripme.sh";
String batchPath = new File(batchFile).getAbsolutePath(); String batchPath = new File(batchFile).getAbsolutePath();
@ -242,6 +290,10 @@ public class UpdateUtils {
})); }));
logger.info("Exiting older version, should execute update script (" + batchFile + ") during exit"); logger.info("Exiting older version, should execute update script (" + batchFile + ") during exit");
System.exit(0); System.exit(0);
} else {
new File(mainFileName).delete();
new File(updateFileName).renameTo(new File(mainFileName));
}
} }
} }