Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.nio.channels.Channels;
- import java.nio.channels.ReadableByteChannel;
- import java.util.Scanner;
- public class DamnDownloader {
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- int damnLOLLinkNumber = 0;
- String theURL = "http://www.damnlol.com/true-friendship-18482.html";
- URL link = new URL(theURL);
- while(1>0){
- ReadableByteChannel rbc = Channels.newChannel(link.openStream());
- FileOutputStream fos = new FileOutputStream("link.html");
- fos.getChannel().transferFrom(rbc, 0, 1 << 24);
- System.out.println("File saved!");
- Scanner sc = new Scanner(new FileReader("link.html"));
- String contents = "";
- while(sc.hasNextLine() || sc.hasNext()){
- contents = contents + sc.nextLine() + "\n"; //Contents is the html page as a string!
- }
- sc.close();
- //This finds the next url to scan!
- Scanner sc2 = new Scanner(contents);
- int counter = 0;
- String nextURL = "";
- while((sc2.hasNext() || sc2.hasNextLine()) && (counter != 8)){
- nextURL = sc2.findWithinHorizon("[h][t][t][p][:][/][/][w][w][w][.][d][a][m][n][l][o][l][.][c][o][m][/].*[.][h][t][m][l]", 0);
- //System.out.println(nextURL);
- counter += 1;
- }
- link = new URL(nextURL);
- //Ends next url!
- //Finds the image to download
- sc2 = new Scanner(contents);
- String theImage = "";
- int counter2 = 0;
- while((sc2.hasNext() || sc2.hasNextLine()) && (counter2 != 2)){
- theImage = sc2.findWithinHorizon("[h][t][t][p][:][/][/][w][w][w][.][d][a][m][n][l][o][l][.][c][o][m][/].*[.][g-p][i-p][f-g]", 0);
- //System.out.println(theImage);
- counter2 += 1;
- }
- //Ends finding image
- //Finds the image type
- Scanner sc3 = new Scanner(theImage);
- String imageType = "";
- if(theImage.matches("[h][t][t][p][:][/][/][w][w][w][.][d][a][m][n][l][o][l][.][c][o][m][/].*[.][j][p][g]")){
- imageType = ".jpg";
- }
- if(theImage.matches("[h][t][t][p][:][/][/][w][w][w][.][d][a][m][n][l][o][l][.][c][o][m][/].*[.][p][n][g]")){
- imageType = ".png";
- }
- if(theImage.matches("[h][t][t][p][:][/][/][w][w][w][.][d][a][m][n][l][o][l][.][c][o][m][/].*[.][g][i][f]")){
- imageType = ".gif";
- }
- /*else{
- imageType = ".jpg";
- System.out.println("Image type not found!");
- }*/
- //Saves the image
- URL link2 = new URL(theImage);
- String damnLOLLink = "damnlolimage-";
- String damnLOLLinkFinal = damnLOLLink + damnLOLLinkNumber + imageType;
- ReadableByteChannel rbc2 = Channels.newChannel(link2.openStream());
- FileOutputStream fos2 = new FileOutputStream(damnLOLLinkFinal);
- fos2.getChannel().transferFrom(rbc2, 0, 1 << 24);
- System.out.println("File saved!");
- damnLOLLinkNumber += 1;
- //Ends saving the image
- }
- //Writing the file
- /*BufferedWriter bw = new BufferedWriter ( new FileWriter("test.txt"));
- bw.write(contents);
- bw.close();*/
- //End Writing the file
- }
- }
Add Comment
Please, Sign In to add comment