Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package jezaraf;
- import org.apache.commons.io.FileUtils;
- import org.apache.commons.io.IOUtils;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.DefaultHttpClient;
- import org.apache.log4j.Logger;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.nio.charset.StandardCharsets;
- import java.util.ArrayList;
- import java.util.Base64;
- import java.util.List;
- public class Downloader {
- private final static Logger log = Logger.getLogger(Downloader.class);
- private static String username = "";
- private static String password = "";
- private static String baseUrl = "";
- private static String desktopVideo = "C:\\Users\\...\\Desktop\\video\\";
- public static void main(String[] args) throws IOException {
- List<String> subPages = getSubPages();
- for(int i = 0 ; i < subPages.size() ; i++){
- String subPage = subPages.get(i);
- String subFolderName = (i+1) + "_"+ subFolderName(subPage) + "\\";
- //log.info(subPage);
- if(subPage.startsWith("movie")){
- log.info(subFolderName);
- List<String> subSubPages = getSubSubPages(subPages.get(i));
- for(String subSubPage: subSubPages){
- log.info(subSubPage);
- downloadFile(subFolderName, subSubPage);
- }
- }else{
- log.info(subFolderName);
- downloadFile(subFolderName, subPage);
- }
- }
- }
- private static void downloadFile(String subFolderName, String subSubPage) throws IOException {
- String fileName = getFileAdress(subSubPage);
- String fileUri = baseUrl + fileName;
- log.info(fileUri);
- File targetFile = new File(desktopVideo+subFolderName+fileName);
- if(!targetFile.exists()){
- FileUtils.copyInputStreamToFile(getFile(fileUri), targetFile);
- }
- }
- private static String subFolderName(String subUrl){
- return subUrl.substring(6, subUrl.length() - 4);
- }
- private static InputStream getFile(String mpgAdress) throws IOException {
- String encoding = Base64.getEncoder().encodeToString((username+":"+password).getBytes());
- HttpPost httppost = new HttpPost(mpgAdress);
- httppost.setHeader("Authorization", "Basic " + encoding);
- log.info("executing request " + httppost.getRequestLine());
- DefaultHttpClient httpclient = new DefaultHttpClient();
- HttpResponse response = httpclient.execute(httppost);
- HttpEntity entity = response.getEntity();
- return entity.getContent();
- }
- private static String getFileAdress(String subSubPage) throws IOException {
- String uri = baseUrl + subSubPage;
- String encoding = Base64.getEncoder().encodeToString((username+":"+password).getBytes());
- HttpPost httppost = new HttpPost(uri);
- httppost.setHeader("Authorization", "Basic " + encoding);
- log.info("executing request " + httppost.getRequestLine());
- DefaultHttpClient httpclient = new DefaultHttpClient();
- HttpResponse response = httpclient.execute(httppost);
- HttpEntity entity = response.getEntity();
- String result = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
- //log.info(result);
- Document doc = Jsoup.parse(result);
- Elements elements = doc.select("a[id=player]");
- //log.info(elements);
- return elements.get(0).attr("href");
- }
- private static List<String> getSubPages() throws IOException {
- String uri = baseUrl + "GT_video.php";
- String encoding = Base64.getEncoder().encodeToString((username+":"+password).getBytes());
- HttpPost httppost = new HttpPost(uri);
- httppost.setHeader("Authorization", "Basic " + encoding);
- log.info("executing request " + httppost.getRequestLine());
- DefaultHttpClient httpclient = new DefaultHttpClient();
- HttpResponse response = httpclient.execute(httppost);
- HttpEntity entity = response.getEntity();
- String result = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
- //log.info(result);
- Document doc = Jsoup.parse(result);
- Elements elements = doc.select("a[href$=.php]").select("a[href^=movie], a[href^=video]");
- List<String> subPages = new ArrayList<>();
- for(Element e:elements){
- if(e.firstElementSibling() == null){
- //log.info(e);
- subPages.add(e.attr("href"));
- }
- }
- return subPages;
- }
- private static List<String> getSubSubPages(String subSiteName) throws IOException {
- String uri = baseUrl + subSiteName;
- String encoding = Base64.getEncoder().encodeToString((username+":"+password).getBytes());
- HttpPost httppost = new HttpPost(uri);
- httppost.setHeader("Authorization", "Basic " + encoding);
- DefaultHttpClient httpclient = new DefaultHttpClient();
- HttpResponse response = httpclient.execute(httppost);
- HttpEntity entity = response.getEntity();
- String result = IOUtils.toString(entity.getContent(), StandardCharsets.UTF_8);
- //log.info(result);
- Document doc = Jsoup.parse(result);
- Elements elements = doc.select("a[href$=.php]").select("a[href^=video]");
- List<String> subPages = new ArrayList<>();
- for(Element e:elements){
- if(e.firstElementSibling() == null && e.getElementsByTag("img").size() > 0){
- //log.info(e);
- subPages.add(e.attr("href"));
- }
- }
- return subPages;
- }
- }
Add Comment
Please, Sign In to add comment