Skip to content

Commit

Permalink
Refactor for D.R.Y.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanParsens authored and soloturn committed Nov 3, 2024
1 parent 2ace43b commit 91aeb37
Showing 1 changed file with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.rarchives.ripme.ripper.rippers;

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.Utils;

Expand All @@ -13,7 +11,6 @@

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
Expand All @@ -40,15 +37,21 @@ public class CoomerPartyRipper extends AbstractJSONRipper {
private static final String KEY_PATH = "path";
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 static final Integer postCount = 50;

// One of "onlyfans" or "fansly", but might have others in future?
// "Service" of the page to be ripped: Onlyfans, Fansly, Candfans
private final String service;

// Username of the page to be ripped
private final String user;



public CoomerPartyRipper(URL url) throws IOException {
super(url);
List<String> pathElements = Arrays.stream(url.getPath().split("/"))
Expand Down Expand Up @@ -86,9 +89,9 @@ public String getGID(URL url) {
return Utils.filesystemSafe(String.format("%s_%s", service, user));
}

@Override
protected JSONObject getFirstPage() throws IOException {
String apiUrl = String.format("https://coomer.su/api/v1/%s/user/%s", service, user);
private JSONObject getJsonPostsForOffset(Integer offset) throws IOException {
String apiUrl = String.format(POSTS_ENDPOINT, service, user, offset);

String jsonArrayString = Http.url(apiUrl)
.ignoreContentType()
.response()
Expand All @@ -102,20 +105,15 @@ protected JSONObject getFirstPage() throws IOException {
}

@Override
protected JSONObject getNextPage(JSONObject doc) throws IOException, URISyntaxException {
pageCount = pageCount + 1;
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);
protected JSONObject getFirstPage() throws IOException {
return getJsonPostsForOffset(0);
}

// Ideally we'd just return the JSONArray from here, but we have to wrap it in a JSONObject
JSONObject wrapperObject = new JSONObject();
wrapperObject.put(KEY_WRAPPER_JSON_ARRAY, jsonArray);
return wrapperObject;
@Override
protected JSONObject getNextPage(JSONObject doc) throws IOException, URISyntaxException {
pageCount++;
Integer offset = postCount * pageCount;
return getJsonPostsForOffset(offset);
}


Expand Down Expand Up @@ -153,6 +151,7 @@ private void pullFileUrl(JSONObject post, ArrayList<String> results) {
}
} catch (JSONException e) {
/* No-op */
LOGGER.error("Unable to Parse FileURL " + e.getMessage());
}
}

Expand All @@ -164,7 +163,8 @@ private void pullAttachmentUrls(JSONObject post, ArrayList<String> results) {
pullFileUrl(attachment, results);
}
} catch (JSONException e) {
/* No-op */
/* No-op */
LOGGER.error("Unable to Parse AttachmentURL " + e.getMessage());
}
}

Expand Down

0 comments on commit 91aeb37

Please sign in to comment.