Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Programmed by Julian. Happy fapping.
- import java.io.*;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.ArrayList;
- import java.util.List;
- public class Main {
- public static void main(String[] args) throws IOException {
- saveAllImages("s", 16015671);
- }
- public static void saveAllImages(String board, long thread) {
- for (String s : getImageLinks(board, thread)){
- System.out.println(s);
- saveImage(s, thread + "/" + s.replaceFirst("http://i.4cdn.org/" + board + "/", ""));
- }
- }
- public static List<String> getImageLinks(String board, long thread) {
- List<String> list = new ArrayList<String>();
- for (String s : getUrlSource("http://boards.4chan.org/" + board + "/thread/" + (thread)).split(" ")){
- if (s.startsWith("src=\"//i.4cdn.org/" + board + "/")){
- String st = s.replaceFirst("src=\"//", "");
- list.add("http://" + st.substring(0, st.length() - 6) + ".jpg");
- }
- }
- return list;
- }
- private static String getUrlSource(String url){
- try {
- URL yahoo = new URL(url);
- URLConnection yc = yahoo.openConnection();
- BufferedReader in = new BufferedReader(new InputStreamReader(
- yc.getInputStream(), "UTF-8"));
- String inputLine;
- StringBuilder a = new StringBuilder();
- while ((inputLine = in.readLine()) != null)
- a.append(inputLine);
- in.close();
- return a.toString();
- } catch (IOException ex){
- return null;
- }
- }
- public static void saveImage(String imageUrl, String destinationFile){
- File f2 = new File(destinationFile.split("/")[0]);
- if (!f2.exists()){
- f2.mkdir();
- }
- try {
- URL url = new URL(imageUrl);
- InputStream is = url.openStream();
- OutputStream os = new FileOutputStream(destinationFile);
- byte[] b = new byte[2048];
- int length;
- while ((length = is.read(b)) != -1) {
- os.write(b, 0, length);
- }
- is.close();
- os.close();
- } catch (IOException ex){}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement