Remove resize param from madame url

This commit is contained in:
Sebastien 2019-01-02 13:03:48 +01:00
parent c1cc670906
commit b454ed8199

View File

@ -17,7 +17,7 @@ import java.io.IOException;
/** /**
* Madame command that return random picture from dites.bonjourmadame.fr * Madame command that return random picture from dites.bonjourmadame.fr
*/ */
@NoDev //@NoDev
public class Madame extends NumberedCommande { public class Madame extends NumberedCommande {
Logger logger = LogManager.getLogger(); Logger logger = LogManager.getLogger();
MessageReceivedEvent event; MessageReceivedEvent event;
@ -52,7 +52,7 @@ public class Madame extends NumberedCommande {
* @throws StringIndexOutOfBoundsException * @throws StringIndexOutOfBoundsException
* @throws IOException * @throws IOException
*/ */
public static boolean scanPageForTipeee(String url, Logger logger) throws StringIndexOutOfBoundsException, IOException { private boolean scanPageForTipeee(String url, Logger logger) throws StringIndexOutOfBoundsException, IOException {
String content = FindContentOnWebPage.getSourceUrl(url); String content = FindContentOnWebPage.getSourceUrl(url);
String imgClickLink = content.substring(content.indexOf("class=\"post-content")); String imgClickLink = content.substring(content.indexOf("class=\"post-content"));
imgClickLink = imgClickLink.substring(imgClickLink.indexOf("<a")); imgClickLink = imgClickLink.substring(imgClickLink.indexOf("<a"));
@ -67,6 +67,14 @@ public class Madame extends NumberedCommande {
return false; return false;
} }
private String removeParams(String url){
int par = url.indexOf('?');
if(par != -1){
url = url.substring(0,par);
}
return url;
}
@Override @Override
public String poll() throws IOException { public String poll() throws IOException {
@ -77,7 +85,10 @@ public class Madame extends NumberedCommande {
checkRandom(); checkRandom();
int randomResult = randomQueue.poll(); int randomResult = randomQueue.poll();
String url = baseURL + randomResult + urlSuffix; String url = baseURL + randomResult + urlSuffix;
logger.debug("URL: " + url); logger.debug("URL: " + url);
if (scanPageForTipeee(url, logger)) { if (scanPageForTipeee(url, logger)) {
logger.debug("Advertisement detected! Retry! (" + url + ")"); logger.debug("Advertisement detected! Retry! (" + url + ")");
} else { } else {
@ -87,6 +98,7 @@ public class Madame extends NumberedCommande {
} }
} }
imgUrl = removeParams(imgUrl);
return imgUrl; return imgUrl;
} }
} }