More improvements for unit tests

This commit is contained in:
4pr0n 2015-02-06 03:37:24 -08:00
parent c524d20ccb
commit 9967332057
4 changed files with 16 additions and 27 deletions

View File

@ -2,7 +2,6 @@ package com.rarchives.ripme.ripper.rippers;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.SocketTimeoutException;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -59,7 +58,7 @@ public class RedditRipper extends AlbumRipper {
URL jsonURL = getJsonURL(this.url); URL jsonURL = getJsonURL(this.url);
while (true) { while (true) {
jsonURL = getAndParseAndReturnNext(jsonURL); jsonURL = getAndParseAndReturnNext(jsonURL);
if (jsonURL == null) { if (jsonURL == null || isThisATest() || isStopped()) {
break; break;
} }
} }
@ -119,20 +118,10 @@ public class RedditRipper extends AlbumRipper {
} }
lastRequestTime = System.currentTimeMillis(); lastRequestTime = System.currentTimeMillis();
int attempts = 0; String jsonString = Http.url(url)
logger.info(" Retrieving " + url);
String jsonString = null;
while(jsonString == null && attempts++ < 3) {
try {
jsonString = Http.url(url)
.ignoreContentType() .ignoreContentType()
.response() .response()
.body(); .body();
} catch(SocketTimeoutException ex) {
if(attempts >= 3) throw ex;
logger.warn(String.format("[!] Connection timed out (attempt %d)", attempts));
}
}
Object jsonObj = new JSONTokener(jsonString).nextValue(); Object jsonObj = new JSONTokener(jsonString).nextValue();
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();

View File

@ -52,16 +52,16 @@ public class SeeniveRipper extends AlbumRipper {
} }
String lastID = null; String lastID = null;
for (Element element : doc.select("a.facebox")) { for (Element element : doc.select("a.facebox")) {
if (isStopped()) {
break;
}
String card = element.attr("href"); // "/v/<video_id>" String card = element.attr("href"); // "/v/<video_id>"
URL videoURL = new URL("http://seenive.com" + card); URL videoURL = new URL("http://seenive.com" + card);
SeeniveImageThread vit = new SeeniveImageThread(videoURL); SeeniveImageThread vit = new SeeniveImageThread(videoURL);
seeniveThreadPool.addThread(vit); seeniveThreadPool.addThread(vit);
lastID = card.substring(card.lastIndexOf('/') + 1); lastID = card.substring(card.lastIndexOf('/') + 1);
if (isStopped() || isThisATest()) {
break;
} }
if (lastID == null) { }
if (lastID == null || isStopped() || isThisATest()) {
break; break;
} }
@ -116,7 +116,7 @@ public class SeeniveRipper extends AlbumRipper {
public void run() { public void run() {
try { try {
Document doc = Http.url(this.url).get(); Document doc = Http.url(this.url).get();
logger.info("[ ] Retreiving video page " + this.url); logger.info("[ ] Retrieving video page " + this.url);
sendUpdate(STATUS.LOADING_RESOURCE, this.url.toExternalForm()); sendUpdate(STATUS.LOADING_RESOURCE, this.url.toExternalForm());
for (Element element : doc.select("source")) { for (Element element : doc.select("source")) {
String video = element.attr("src"); String video = element.attr("src");

View File

@ -155,7 +155,7 @@ public class VkRipper extends AlbumRipper {
} }
offset += elements.size(); offset += elements.size();
if (isThisATest()) { if (isStopped() || isThisATest()) {
break; break;
} }
} }

View File

@ -15,8 +15,8 @@ public class VkRipperTest extends RippersTest {
} }
List<URL> contentURLs = new ArrayList<URL>(); List<URL> contentURLs = new ArrayList<URL>();
contentURLs.add(new URL("https://vk.com/album45506334_172415053")); contentURLs.add(new URL("https://vk.com/album45506334_172415053"));
contentURLs.add(new URL("https://vk.com/album45506334_0")); //contentURLs.add(new URL("https://vk.com/album45506334_0"));
contentURLs.add(new URL("https://vk.com/photos45506334")); //contentURLs.add(new URL("https://vk.com/photos45506334"));
for (URL url : contentURLs) { for (URL url : contentURLs) {
VkRipper ripper = new VkRipper(url); VkRipper ripper = new VkRipper(url);
testRipper(ripper); testRipper(ripper);