SHOW:
|
|
- or go back to the newest paste.
1 | - | // Programmed by Julian. |
1 | + | // Programmed by Julian. Happy fapping. |
2 | ||
3 | import java.io.*; | |
4 | import java.net.URL; | |
5 | import java.net.URLConnection; | |
6 | import java.util.ArrayList; | |
7 | import java.util.List; | |
8 | ||
9 | public class Main { | |
10 | public static void main(String[] args) throws IOException { | |
11 | saveAllImages("s", 16015671); | |
12 | } | |
13 | ||
14 | public static void saveAllImages(String board, long thread) { | |
15 | for (String s : getImageLinks(board, thread)){ | |
16 | System.out.println(s); | |
17 | saveImage(s, thread + "/" + s.replaceFirst("http://i.4cdn.org/" + board + "/", "")); | |
18 | } | |
19 | } | |
20 | ||
21 | public static List<String> getImageLinks(String board, long thread) { | |
22 | List<String> list = new ArrayList<String>(); | |
23 | for (String s : getUrlSource("http://boards.4chan.org/" + board + "/thread/" + (thread)).split(" ")){ | |
24 | if (s.startsWith("src=\"//i.4cdn.org/" + board + "/")){ | |
25 | String st = s.replaceFirst("src=\"//", ""); | |
26 | list.add("http://" + st.substring(0, st.length() - 6) + ".jpg"); | |
27 | } | |
28 | } | |
29 | return list; | |
30 | } | |
31 | ||
32 | private static String getUrlSource(String url){ | |
33 | try { | |
34 | URL yahoo = new URL(url); | |
35 | URLConnection yc = yahoo.openConnection(); | |
36 | BufferedReader in = new BufferedReader(new InputStreamReader( | |
37 | yc.getInputStream(), "UTF-8")); | |
38 | String inputLine; | |
39 | StringBuilder a = new StringBuilder(); | |
40 | while ((inputLine = in.readLine()) != null) | |
41 | a.append(inputLine); | |
42 | in.close(); | |
43 | return a.toString(); | |
44 | } catch (IOException ex){ | |
45 | return null; | |
46 | } | |
47 | } | |
48 | ||
49 | public static void saveImage(String imageUrl, String destinationFile){ | |
50 | File f2 = new File(destinationFile.split("/")[0]); | |
51 | if (!f2.exists()){ | |
52 | f2.mkdir(); | |
53 | } | |
54 | try { | |
55 | URL url = new URL(imageUrl); | |
56 | InputStream is = url.openStream(); | |
57 | OutputStream os = new FileOutputStream(destinationFile); | |
58 | byte[] b = new byte[2048]; | |
59 | int length; | |
60 | while ((length = is.read(b)) != -1) { | |
61 | os.write(b, 0, length); | |
62 | } | |
63 | is.close(); | |
64 | os.close(); | |
65 | } catch (IOException ex){} | |
66 | } | |
67 | } |