More improvements for unit tests
This commit is contained in:
parent
c524d20ccb
commit
9967332057
@ -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);
|
.ignoreContentType()
|
||||||
String jsonString = null;
|
.response()
|
||||||
while(jsonString == null && attempts++ < 3) {
|
.body();
|
||||||
try {
|
|
||||||
jsonString = Http.url(url)
|
|
||||||
.ignoreContentType()
|
|
||||||
.response()
|
|
||||||
.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();
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,8 +74,8 @@ public class SeeniveRipper extends AlbumRipper {
|
|||||||
|
|
||||||
logger.info("[ ] Retrieving " + baseURL + "/next/" + lastID);
|
logger.info("[ ] Retrieving " + baseURL + "/next/" + lastID);
|
||||||
JSONObject json = Http.url(baseURL + "/next/" + lastID)
|
JSONObject json = Http.url(baseURL + "/next/" + lastID)
|
||||||
.referrer(baseURL)
|
.referrer(baseURL)
|
||||||
.getJSON();
|
.getJSON();
|
||||||
String html = json.getString("Html");
|
String html = json.getString("Html");
|
||||||
if (html.equals("")) {
|
if (html.equals("")) {
|
||||||
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");
|
||||||
|
@ -155,7 +155,7 @@ public class VkRipper extends AlbumRipper {
|
|||||||
}
|
}
|
||||||
offset += elements.size();
|
offset += elements.size();
|
||||||
|
|
||||||
if (isThisATest()) {
|
if (isStopped() || isThisATest()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user