000001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095096097098099100101102103104105106107108109110111112113114
package br.com.hkp.whatsappwebfix;
import br.com.hkp.whatsappwebfix.gui.ProgressFrame;
import br.com.hkp.whatsappwebfix.util.FileTools;
import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class DownloadPngs
{
private final ProgressFrame frame;
private static final String TARGET_DIR = "png";
public DownloadPngs()
{
frame = new ProgressFrame("Baixando...", 800, 450);
}
private void downloadAll(final Matcher m) throws IOException
{
int count = 0;
while (m.find())
{
String s = m.group();
String url = s.substring(s.indexOf("https:"), s.length());
FileTools.downloadUrl(url, TARGET_DIR);
frame.println(String.format("%04d - %s\n", ++count, url));
}
}
public void downloadPngs(final File emojipediaFile) throws IOException
{
File downloaDir = new File(TARGET_DIR);
if (!downloaDir.exists())
{
if (!downloaDir.mkdirs())
{
System.err.println("Erro ao criar pasta /" + TARGET_DIR);
System.exit(1);
}
}
String contentFile = FileTools.readTextFile(emojipediaFile);
frame.setVisible(true);
Pattern srcSet =
Pattern.compile(" srcset=\"https.+?\\." + TARGET_DIR + "\\b");
Matcher m = srcSet.matcher(contentFile);
downloadAll(m);
Pattern dataSrc =
Pattern.compile("data-src=\"https.+?\\." + TARGET_DIR + "\\b");
m = dataSrc.matcher(contentFile);
downloadAll(m);
frame.setTitle("");
frame.println("Arquivos baixados para a pasta " + TARGET_DIR);
java.awt.Toolkit.getDefaultToolkit().beep();
}
}