Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.genuineminecraft.phapit;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.net.URL;
- import java.nio.channels.Channels;
- import java.nio.channels.ReadableByteChannel;
- import java.util.ArrayList;
- import java.util.List;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- public class Main {
- private static File currentDir;
- private static List<Runnable> runners = new ArrayList<>();
- public static void main(String[] args) {
- currentDir = new File("downloads");
- currentDir.mkdirs();
- // 149790 is currently the highest pic.
- for (int i = 0; i < 150000; i++)
- runners.add(createRunner(i));
- runners.stream().parallel().forEach(Runnable::run);
- }
- public static Runnable createRunner(int i) {
- return () -> {
- File file = new File(currentDir, i + ".jpg");
- if (file.exists())
- return;
- try {
- Document doc = Jsoup.connect("http://phapit.com/image/phap" + i).get();
- Elements imgs = doc.select("img");
- String image = "";
- String tags = "";
- for (Element element : imgs) {
- if (!element.attr("src").contains("http://images.phapit.com/pic/"))
- continue;
- image = element.attr("src");
- tags = element.attr("alt");
- break;
- }
- if (image.isEmpty() || tags.toLowerCase().contains("child") || tags.toLowerCase().contains("delete"))
- return;
- saveFile(i, image);
- }
- catch (IOException e) {}
- };
- }
- public static void saveFile(int i, String url) {
- File file = new File(currentDir, i + ".jpg");
- if (file.exists())
- return;
- try (ReadableByteChannel rbc = Channels.newChannel(new URL(url).openStream()); FileOutputStream fos = new FileOutputStream(file);) {
- file.createNewFile();
- fos.getChannel().transferFrom(rbc, 0, 1 << 24);
- }
- catch (Exception e) {}
- }
- }