Deviantart orders albums sequentially #43

This commit is contained in:
4pr0n 2014-05-16 22:20:06 -07:00
parent 1aaefcccc8
commit 3148d10be3
2 changed files with 34 additions and 5 deletions

View File

@ -64,13 +64,16 @@ public class DeviantartRipper extends AlbumRipper {
continue; // a.thumbs to other albums are invisible
}
String fullSizePage = thumbToFull(thumb.attr("src"));
String fullSize = thumbToFull(thumb.attr("src"));
try {
URL fullsizePageURL = new URL(fullSizePage);
URL fullsizeURL = new URL(fullSize);
String imageId = fullSize.substring(fullSize.lastIndexOf('-') + 1);
imageId = imageId.substring(0, imageId.indexOf('.'));
long imageIdLong = alphaToLong(imageId);
index++;
addURLToDownload(fullsizePageURL, String.format("%03d_", index));
addURLToDownload(fullsizeURL, String.format("%010d_", imageIdLong));
} catch (MalformedURLException e) {
logger.error("[!] Invalid thumbnail image: " + thumbToFull(fullSizePage));
logger.error("[!] Invalid thumbnail image: " + thumbToFull(fullSize));
continue;
}
}
@ -94,6 +97,25 @@ public class DeviantartRipper extends AlbumRipper {
waitForThreads();
}
public static long alphaToLong(String alpha) {
long result = 0;
for (int i = 0; i < alpha.length(); i++) {
result += charToInt(alpha, i);
System.err.println("\t result: " + result);
}
return result;
}
private static int charToInt(String text, int index) {
char c = text.charAt(text.length() - index - 1);
c = Character.toLowerCase(c);
System.err.print(" " + c + ": ");
int number = "0123456789abcdefghijklmnopqrstuvwxyz".indexOf(c);
number *= Math.pow(36, index);
System.err.print(number);
return number;
}
public static String thumbToFull(String thumb) {
thumb = thumb.replace("http://th", "http://fc");
List<String> fields = new ArrayList<String>(Arrays.asList(thumb.split("/")));

View File

@ -9,6 +9,13 @@ import com.rarchives.ripme.ripper.rippers.DeviantartRipper;
public class DeviantartRipperTest extends RippersTest {
public void testAlphaSorting() {
String[] strings = new String[]{"a", "aa", "aaa", "d6hg2dz", "d6fspba", "d6fcvvr"};
for (String string : strings) {
System.err.println(string + ": " + DeviantartRipper.alphaToLong(string));
}
}
public void testDeviantartAlbums() throws IOException {
if (!DOWNLOAD_CONTENT) {
return;