Merge pull request #645 from cyian-1756/tumblrFix

Looks good
This commit is contained in:
Kevin Jiang 2018-06-01 03:32:18 -04:00 committed by GitHub
commit 39321a8b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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);