Skip to content

Commit

Permalink
Deviantart orders albums sequentially #43
Browse files Browse the repository at this point in the history
  • Loading branch information
4pr0n committed May 17, 2014
1 parent 1aaefcc commit 3148d10
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,16 @@ public void rip() throws IOException {
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;
}
}
Expand All @@ -93,7 +96,26 @@ public void rip() throws IOException {
}
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("/")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@

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;
Expand Down

0 comments on commit 3148d10

Please sign in to comment.