Merge pull request #377 from kevin51jiang/GfycatFixAndTest

Gfycat fix and test
This commit is contained in:
cyian-1756 2018-01-06 14:06:48 -05:00 committed by GitHub
commit ae7ea5f8e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 0 deletions

View File

@ -32,6 +32,8 @@ public class GfycatRipper extends VideoRipper {
@Override
public URL sanitizeURL(URL url) throws MalformedURLException {
url = new URL(url.toExternalForm().replace("/gifs/detail", ""));
return url;
}
@ -64,6 +66,10 @@ public class GfycatRipper extends VideoRipper {
*/
public static String getVideoURL(URL url) throws IOException {
logger.info("Retrieving " + url.toExternalForm());
//Sanitize the URL first
url = new URL(url.toExternalForm().replace("/gifs/detail", ""));
Document doc = Http.url(url).get();
Elements videos = doc.select("source#mp4Source");
if (videos.size() == 0) {

View File

@ -0,0 +1,26 @@
package com.rarchives.ripme.tst.ripper.rippers;
import com.rarchives.ripme.ripper.rippers.video.GfycatRipper;
import java.io.IOException;
import java.net.URL;
public class GfycatRipperTest extends RippersTest {
/**
* Rips correctly formatted URL directly from Gfycat
* @throws IOException
*/
public void GfycatGoodURL() throws IOException{
GfycatRipper ripper = new GfycatRipper(new URL("https://gfycat.com/TemptingExcellentIchthyosaurs"));
testRipper(ripper);
}
/**
* Rips badly formatted URL directly from Gfycat
* @throws IOException
*/
public void GfycatBadURL() throws IOException {
GfycatRipper ripper = new GfycatRipper(new URL("https://gfycat.com/gifs/detail/limitedtestyamericancrow"));
testRipper(ripper);
}
}

View File

@ -5,6 +5,7 @@ import java.io.IOException;
import java.net.URL;
import com.rarchives.ripme.ripper.rippers.RedditRipper;
import com.rarchives.ripme.ripper.rippers.video.GfycatRipper;
public class RedditRipperTest extends RippersTest {
// https://github.com/RipMeApp/ripme/issues/253 - Disabled tests: RedditRipperTest#testRedditSubreddit*Rip is flaky
@ -22,4 +23,25 @@ public class RedditRipperTest extends RippersTest {
RedditRipper ripper = new RedditRipper(new URL("http://www.reddit.com/r/UnrealGirls/comments/1ziuhl/in_class_veronique_popa/"));
testRipper(ripper);
}
/**
* GFYCAT TEST
* Tests a good GfycatURL (no "/gifs/detail")
* @throws IOException
*/
public void testRedditGfyGoodURL() throws IOException {
RedditRipper ripper = new RedditRipper(new URL("https://www.reddit.com/r/bottesting/comments/7msozf/good_link/"));
testRipper(ripper);
}
/**
* GFYCAT TEST
* Tests a Bad URL with the "/gifs/detail" inside.
* @throws IOException
*/
public void testRedditGfyBadURL() throws IOException {
RedditRipper ripper = new RedditRipper(new URL("https://www.reddit.com/r/bottesting/comments/7msmhi/bad_link/"));
testRipper(ripper);
}
}