Various reformatting.

This commit is contained in:
MetaPrime 2017-05-09 16:13:42 -07:00
parent cd8784ed85
commit b6c925caae
5 changed files with 28 additions and 38 deletions

View File

@ -171,7 +171,7 @@ public class App {
if (!history.contains(url.toExternalForm())) { if (!history.contains(url.toExternalForm())) {
history.add(url.toExternalForm()); history.add(url.toExternalForm());
Utils.setConfigList("download.history", Arrays.asList(history.toArray())); Utils.setConfigList("download.history", Arrays.asList(history.toArray()));
if(saveConfig) { if (saveConfig) {
Utils.saveConfig(); Utils.saveConfig();
} }
} }

View File

@ -62,7 +62,7 @@ public class InstagramRipper extends AbstractJSONRipper {
Pattern p = Pattern.compile("^https?://instagram\\.com/([^/]+)"); Pattern p = Pattern.compile("^https?://instagram\\.com/([^/]+)");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if(m.matches()) { if (m.matches()) {
return m.group(1); return m.group(1);
} }
@ -92,7 +92,7 @@ public class InstagramRipper extends AbstractJSONRipper {
throw new IOException("No additional pages found"); throw new IOException("No additional pages found");
} }
if(nextPageAvailable) { if (nextPageAvailable) {
JSONArray items = json.getJSONArray("items"); JSONArray items = json.getJSONArray("items");
JSONObject last_item = items.getJSONObject(items.length() - 1); JSONObject last_item = items.getJSONObject(items.length() - 1);
String nextMaxID = last_item.getString("id"); String nextMaxID = last_item.getString("id");

View File

@ -2,24 +2,15 @@ package com.rarchives.ripme.ripper.rippers;
import com.rarchives.ripme.ripper.AbstractHTMLRipper; import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
import com.rarchives.ripme.utils.Utils;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class MyhentaicomicsRipper extends AbstractHTMLRipper { public class MyhentaicomicsRipper extends AbstractHTMLRipper {
public static boolean isTag; public static boolean isTag;
@ -109,7 +100,7 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
Element elem = nextAlbumPage.select("a.ui-icon-right").first(); Element elem = nextAlbumPage.select("a.ui-icon-right").first();
String nextPage = elem.attr("href"); String nextPage = elem.attr("href");
pageNumber = pageNumber + 1; pageNumber = pageNumber + 1;
if(nextPage == ""){ if (nextPage == ""){
logger.info("Got " + pageNumber + " pages"); logger.info("Got " + pageNumber + " pages");
break; break;
} }

View File

@ -194,9 +194,9 @@ public class TumblrRipper extends AlbumRipper {
try { try {
fileURL = new URL(photo.getJSONObject("original_size").getString("url")); fileURL = new URL(photo.getJSONObject("original_size").getString("url"));
m = p.matcher(fileURL.toString()); m = p.matcher(fileURL.toString());
if(m.matches()) { if (m.matches()) {
addURLToDownload(fileURL); addURLToDownload(fileURL);
} else{ } else {
URL redirectedURL = Http.url(fileURL).ignoreContentType().response().url(); URL redirectedURL = Http.url(fileURL).ignoreContentType().response().url();
addURLToDownload(redirectedURL); addURLToDownload(redirectedURL);
} }

View File

@ -3,16 +3,15 @@ package com.rarchives.ripme.utils;
/** /**
* Base64 encoder/decoder * Base64 encoder/decoder
* From http://stackoverflow.com/a/4265472 * From http://stackoverflow.com/a/4265472
*
*/ */
public class Base64 { public class Base64 {
private final static char[] ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray(); private final static char[] ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".toCharArray();
private static int[] toInt = new int[128]; private static int[] toInt = new int[128];
static { static {
for(int i=0; i< ALPHABET.length; i++){ for (int i = 0; i < ALPHABET.length; i++) {
toInt[ALPHABET[i]]= i; toInt[ALPHABET[i]] = i;
} }
} }
@ -22,12 +21,12 @@ public class Base64 {
* @param buf the byte array (not null) * @param buf the byte array (not null)
* @return the translated Base64 string (not null) * @return the translated Base64 string (not null)
*/ */
public static String encode(byte[] buf){ public static String encode(byte[] buf) {
int size = buf.length; int size = buf.length;
char[] ar = new char[((size + 2) / 3) * 4]; char[] ar = new char[((size + 2) / 3) * 4];
int a = 0; int a = 0;
int i=0; int i = 0;
while(i < size){ while (i < size) {
byte b0 = buf[i++]; byte b0 = buf[i++];
byte b1 = (i < size) ? buf[i++] : 0; byte b1 = (i < size) ? buf[i++] : 0;
byte b2 = (i < size) ? buf[i++] : 0; byte b2 = (i < size) ? buf[i++] : 0;
@ -38,9 +37,9 @@ public class Base64 {
ar[a++] = ALPHABET[((b1 << 2) | ((b2 & 0xFF) >> 6)) & mask]; ar[a++] = ALPHABET[((b1 << 2) | ((b2 & 0xFF) >> 6)) & mask];
ar[a++] = ALPHABET[b2 & mask]; ar[a++] = ALPHABET[b2 & mask];
} }
switch(size % 3){ switch (size % 3) {
case 1: ar[--a] = '='; case 1: ar[--a] = '=';
case 2: ar[--a] = '='; case 2: ar[--a] = '=';
} }
return new String(ar); return new String(ar);
} }
@ -51,25 +50,25 @@ public class Base64 {
* @param s the Base64 string (not null) * @param s the Base64 string (not null)
* @return the byte array (not null) * @return the byte array (not null)
*/ */
public static byte[] decode(String s){ public static byte[] decode(String s) {
int delta = s.endsWith( "==" ) ? 2 : s.endsWith( "=" ) ? 1 : 0; int delta = s.endsWith("==") ? 2 : s.endsWith("=") ? 1 : 0;
byte[] buffer = new byte[s.length()*3/4 - delta]; byte[] buffer = new byte[s.length() * 3 / 4 - delta];
int mask = 0xFF; int mask = 0xFF;
int index = 0; int index = 0;
for(int i=0; i< s.length(); i+=4){ for (int i = 0; i < s.length(); i += 4) {
int c0 = toInt[s.charAt( i )]; int c0 = toInt[s.charAt(i)];
int c1 = toInt[s.charAt( i + 1)]; int c1 = toInt[s.charAt(i + 1)];
buffer[index++]= (byte)(((c0 << 2) | (c1 >> 4)) & mask); buffer[index++] = (byte) (((c0 << 2) | (c1 >> 4)) & mask);
if(index >= buffer.length){ if (index >= buffer.length) {
return buffer; return buffer;
} }
int c2 = toInt[s.charAt( i + 2)]; int c2 = toInt[s.charAt(i + 2)];
buffer[index++]= (byte)(((c1 << 4) | (c2 >> 2)) & mask); buffer[index++] = (byte) (((c1 << 4) | (c2 >> 2)) & mask);
if(index >= buffer.length){ if (index >= buffer.length) {
return buffer; return buffer;
} }
int c3 = toInt[s.charAt( i + 3 )]; int c3 = toInt[s.charAt(i + 3)];
buffer[index++]= (byte)(((c2 << 6) | c3) & mask); buffer[index++] = (byte) (((c2 << 6) | c3) & mask);
} }
return buffer; return buffer;
} }