Skip to content

Instantly share code, notes, and snippets.

@saada2006
Created October 21, 2022 10:12
Show Gist options
  • Save saada2006/5e5c2cfce23913f17a3f0805a7284f60 to your computer and use it in GitHub Desktop.
Save saada2006/5e5c2cfce23913f17a3f0805a7284f60 to your computer and use it in GitHub Desktop.
Since the dudez website didn't have a download button, here is a program to download the stuff for you...
// Basically I couldn't find the download link on the dudez page
// So here is my own downloader
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class DUDEZDownloader {
static String getData(InputStream is) throws IOException {
InputStreamReader r = new InputStreamReader(is);
StringBuilder sb = new StringBuilder();
int c = 0;
while(true) {
c = r.read();
if(c == -1) {
break;
}
sb.append((char)c);
}
return sb.toString();
}
static void downloadPage(String location) throws IOException {
URL url = new URL(location);
URLConnection con = url.openConnection();
String get = getData(con.getInputStream());
String path = location.substring("https://dudez.docking.org/".length());
if(get.startsWith("<!DOCTYPE")) {
// first, ensure our directories are created!
File dir = new File(path);
if(!dir.exists())
dir.mkdirs();
// Then, iterate through the tree to get what we want
Pattern pattern = Pattern.compile("<a href=\"(.*?)\">(.*?)</a>");
Matcher matcher = pattern.matcher(get);
while(matcher.find()) {
String link = matcher.group();
int end = link.indexOf("\">");
String suburl = link.substring("<a href=".length() + 1, end);
if(link.contains("Parent Directory") || link.contains("?")) {
//System.out.println("Skipping " + suburl);
continue;
} else {
System.out.println("Downloading " + suburl);
downloadPage(location + suburl);
}
}
System.out.println("Folder download for " + path + " complete");
} else {
BufferedWriter bw = new BufferedWriter(new FileWriter(path));
bw.write(get);
bw.close();
}
}
public static void main(String[] args) throws Exception {
downloadPage("https://dudez.docking.org/DOCKING_GRIDS_AND_POSES/DRD4/");
}
}
/*
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment