1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-12 08:54:11 +02:00

Replaced fuzzyExists and Fixed regex in redgifs user and search

- Added a dot in redgifs regex to account for them in usernames and
  search queries
- Replaced fuzzyExists with better library efficient call that check the
  folder for existing file
This commit is contained in:
borderline232
2021-01-16 01:08:05 -05:00
committed by soloturn
parent f1db4300c2
commit 18f141bbef
4 changed files with 21 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
@@ -79,7 +80,7 @@ class DownloadFileThread extends Thread {
return;
}
if (saveAs.exists() && !observer.tryResumeDownload() && !getFileExtFromMIME
|| Utils.fuzzyExists(new File(saveAs.getParent()), saveAs.getName()) && getFileExtFromMIME
|| Utils.fuzzyExistsBetter(Paths.get(saveAs.getParent()), saveAs.getName()) && getFileExtFromMIME
&& !observer.tryResumeDownload()) {
if (Utils.getConfigBoolean("file.overwrite", false)) {
logger.info("[!] " + Utils.getLocalizedString("deleting.existing.file") + prettySaveAs);

View File

@@ -55,12 +55,12 @@ public class RedgifsRipper extends AbstractHTMLRipper {
}
public Matcher isProfile() {
Pattern p = Pattern.compile("^https?://[wm.]*redgifs\\.com/users/([a-zA-Z0-9_-]+).*$");
Pattern p = Pattern.compile("^https?://[wm.]*redgifs\\.com/users/([a-zA-Z0-9_.-]+).*$");
return p.matcher(url.toExternalForm());
}
public Matcher isSearch() {
Pattern p = Pattern.compile("^https?://[wm.]*redgifs\\.com/gifs/browse/([a-zA-Z0-9_-]+).*$");
Pattern p = Pattern.compile("^https?://[wm.]*redgifs\\.com/gifs/browse/([a-zA-Z0-9_.-]+).*$");
return p.matcher(url.toExternalForm());
}
@@ -131,7 +131,7 @@ public class RedgifsRipper extends AbstractHTMLRipper {
.ignoreContentType().get();
return (hasURLs(d).isEmpty()) ? null : d;
} else {
if (cursor.equals("")) {
if (cursor.equals("") || cursor.equals("null")) {
return null;
} else {
Document d = Http.url(new URL("https://napi.redgifs.com/v1/users/" + username + "/gfycats?count=" + count + "&cursor=" + cursor)).ignoreContentType().get();
@@ -170,7 +170,7 @@ public class RedgifsRipper extends AbstractHTMLRipper {
for (int i = 0; i < content.length(); i++) {
result.add(content.getJSONObject(i).getString("mp4Url"));
}
cursor = page.getString("cursor");
cursor = page.get("cursor").toString();
return result;
}

View File

@@ -880,6 +880,10 @@ public class Utils {
return false;
}
public static boolean fuzzyExistsBetter(Path folder, String filename) {
return Files.exists(folder.resolve(filename));
}
public static String sanitizeSaveAs(String fileNameToSan) {
return fileNameToSan.replaceAll("[\\\\/:*?\"<>|]", "_");
}

View File

@@ -60,6 +60,17 @@ public class RedditRipperTest extends RippersTest {
testRipper(ripper);
}
/**
* GFYCAT TEST Tests a gfycat URL with the gifdeliverynetwork/redgifs hosted video
*
* @throws IOException
*/
@Test
public void testRedditGfycatRedirectURL() throws IOException {
RedditRipper ripper = new RedditRipper(
new URL("https://www.reddit.com/r/NSFW_GIF/comments/ennwsa/gorgeous_tits/"));
}
@Test
@Tag("flaky")
public void testRedditGallery() throws IOException{