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

Refactor for D.R.Y.

This commit is contained in:
William Hinchman
2024-10-05 11:10:33 -04:00
committed by soloturn
parent 2ace43b5ae
commit 91aeb37553

View File

@@ -1,7 +1,5 @@
package com.rarchives.ripme.ripper.rippers; package com.rarchives.ripme.ripper.rippers;
import com.rarchives.ripme.ripper.AbstractJSONRipper; import com.rarchives.ripme.ripper.AbstractJSONRipper;
import com.rarchives.ripme.ripper.rippers.ArtStationRipper.URL_TYPE;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
import com.rarchives.ripme.utils.Utils; import com.rarchives.ripme.utils.Utils;
@@ -13,7 +11,6 @@ import org.json.JSONObject;
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.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@@ -40,15 +37,21 @@ public class CoomerPartyRipper extends AbstractJSONRipper {
private static final String KEY_PATH = "path"; private static final String KEY_PATH = "path";
private static final String KEY_ATTACHMENTS = "attachments"; private static final String KEY_ATTACHMENTS = "attachments";
// Posts Request Endpoint
private static final String POSTS_ENDPOINT = "https://coomer.su/api/v1/%s/user/%s?o=%d";
// Pagination is strictly 50 posts per page, per API schema.
private Integer pageCount = 0; private Integer pageCount = 0;
private static final Integer postCount = 50;
// "Service" of the page to be ripped: Onlyfans, Fansly, Candfans
// One of "onlyfans" or "fansly", but might have others in future?
private final String service; private final String service;
// Username of the page to be ripped // Username of the page to be ripped
private final String user; private final String user;
public CoomerPartyRipper(URL url) throws IOException { public CoomerPartyRipper(URL url) throws IOException {
super(url); super(url);
List<String> pathElements = Arrays.stream(url.getPath().split("/")) List<String> pathElements = Arrays.stream(url.getPath().split("/"))
@@ -86,9 +89,9 @@ public class CoomerPartyRipper extends AbstractJSONRipper {
return Utils.filesystemSafe(String.format("%s_%s", service, user)); return Utils.filesystemSafe(String.format("%s_%s", service, user));
} }
@Override private JSONObject getJsonPostsForOffset(Integer offset) throws IOException {
protected JSONObject getFirstPage() throws IOException { String apiUrl = String.format(POSTS_ENDPOINT, service, user, offset);
String apiUrl = String.format("https://coomer.su/api/v1/%s/user/%s", service, user);
String jsonArrayString = Http.url(apiUrl) String jsonArrayString = Http.url(apiUrl)
.ignoreContentType() .ignoreContentType()
.response() .response()
@@ -102,20 +105,15 @@ public class CoomerPartyRipper extends AbstractJSONRipper {
} }
@Override @Override
protected JSONObject getNextPage(JSONObject doc) throws IOException, URISyntaxException { protected JSONObject getFirstPage() throws IOException {
pageCount = pageCount + 1; return getJsonPostsForOffset(0);
Integer offset = 50 * pageCount; }
String apiUrl = String.format("https://coomer.su/api/v1/%s/user/%s?o=%d", service, user, offset);
String jsonArrayString = Http.url(apiUrl)
.ignoreContentType()
.response()
.body();
JSONArray jsonArray = new JSONArray(jsonArrayString);
// Ideally we'd just return the JSONArray from here, but we have to wrap it in a JSONObject @Override
JSONObject wrapperObject = new JSONObject(); protected JSONObject getNextPage(JSONObject doc) throws IOException, URISyntaxException {
wrapperObject.put(KEY_WRAPPER_JSON_ARRAY, jsonArray); pageCount++;
return wrapperObject; Integer offset = postCount * pageCount;
return getJsonPostsForOffset(offset);
} }
@@ -153,6 +151,7 @@ public class CoomerPartyRipper extends AbstractJSONRipper {
} }
} catch (JSONException e) { } catch (JSONException e) {
/* No-op */ /* No-op */
LOGGER.error("Unable to Parse FileURL " + e.getMessage());
} }
} }
@@ -164,7 +163,8 @@ public class CoomerPartyRipper extends AbstractJSONRipper {
pullFileUrl(attachment, results); pullFileUrl(attachment, results);
} }
} catch (JSONException e) { } catch (JSONException e) {
/* No-op */ /* No-op */
LOGGER.error("Unable to Parse AttachmentURL " + e.getMessage());
} }
} }