mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-01 19:40:18 +02:00
Set static auth token for redgif
This commit is contained in:
@@ -39,8 +39,13 @@ public class RedgifsRipper extends AbstractJSONRipper {
|
|||||||
private static final Pattern TAGS_PATTERN = Pattern.compile("^https?:\\/\\/[a-zA-Z0-9.]*redgifs\\.com\\/gifs\\/([a-zA-Z0-9_.,-]+).*$");
|
private static final Pattern TAGS_PATTERN = Pattern.compile("^https?:\\/\\/[a-zA-Z0-9.]*redgifs\\.com\\/gifs\\/([a-zA-Z0-9_.,-]+).*$");
|
||||||
private static final Pattern SINGLETON_PATTERN = Pattern.compile("^https?://[a-zA-Z0-9.]*redgifs\\.com/watch/([a-zA-Z0-9_-]+).*$");
|
private static final Pattern SINGLETON_PATTERN = Pattern.compile("^https?://[a-zA-Z0-9.]*redgifs\\.com/watch/([a-zA-Z0-9_-]+).*$");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Keep a single auth token for the complete lifecycle of the app.
|
||||||
|
* This should prevent fetching of multiple tokens.
|
||||||
|
*/
|
||||||
|
private static String authToken = "";
|
||||||
|
|
||||||
String username = "";
|
String username = "";
|
||||||
String authToken = "";
|
|
||||||
int count = 40;
|
int count = 40;
|
||||||
int currentPage = 1;
|
int currentPage = 1;
|
||||||
int maxPages = 1;
|
int maxPages = 1;
|
||||||
@@ -90,8 +95,8 @@ public class RedgifsRipper extends AbstractJSONRipper {
|
|||||||
@Override
|
@Override
|
||||||
public JSONObject getFirstPage() throws IOException {
|
public JSONObject getFirstPage() throws IOException {
|
||||||
try {
|
try {
|
||||||
if (authToken == null || authToken.equals("")) {
|
if (authToken == null || authToken.isBlank()) {
|
||||||
authToken = fetchAuthToken();
|
fetchAuthToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSingleton().matches()) {
|
if (isSingleton().matches()) {
|
||||||
@@ -204,7 +209,7 @@ public class RedgifsRipper extends AbstractJSONRipper {
|
|||||||
} else {
|
} else {
|
||||||
var galleryID = ((JSONObject)gif).getString("gallery");
|
var galleryID = ((JSONObject)gif).getString("gallery");
|
||||||
var gifID = ((JSONObject)gif).getString("id");
|
var gifID = ((JSONObject)gif).getString("id");
|
||||||
result.addAll(getURLsForGallery(galleryID, gifID, authToken));
|
result.addAll(getURLsForGallery(galleryID, gifID));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -215,7 +220,7 @@ public class RedgifsRipper extends AbstractJSONRipper {
|
|||||||
} else {
|
} else {
|
||||||
var galleryID = gif.getString("gallery");
|
var galleryID = gif.getString("gallery");
|
||||||
var gifID = gif.getString("id");
|
var gifID = gif.getString("id");
|
||||||
result.addAll(getURLsForGallery(galleryID, gifID, authToken));
|
result.addAll(getURLsForGallery(galleryID, gifID));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -228,7 +233,7 @@ public class RedgifsRipper extends AbstractJSONRipper {
|
|||||||
* @param gifID gif id with multiple images for logging
|
* @param gifID gif id with multiple images for logging
|
||||||
* @return List<String>
|
* @return List<String>
|
||||||
*/
|
*/
|
||||||
private static List<String> getURLsForGallery(String galleryID, String gifID, String authToken) {
|
private static List<String> getURLsForGallery(String galleryID, String gifID) {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
if (galleryID == null || galleryID.isBlank()) {
|
if (galleryID == null || galleryID.isBlank()) {
|
||||||
return list;
|
return list;
|
||||||
@@ -257,7 +262,9 @@ public class RedgifsRipper extends AbstractJSONRipper {
|
|||||||
if (!m.matches()){
|
if (!m.matches()){
|
||||||
throw new IOException(String.format("Cannot fetch redgif url %s", url.toExternalForm()));
|
throw new IOException(String.format("Cannot fetch redgif url %s", url.toExternalForm()));
|
||||||
}
|
}
|
||||||
var authToken = fetchAuthToken();
|
if (authToken == null || authToken.isBlank()){
|
||||||
|
fetchAuthToken();
|
||||||
|
}
|
||||||
var gid = m.group(1).split("-")[0];
|
var gid = m.group(1).split("-")[0];
|
||||||
var gifDetailsURL = String.format(GIFS_DETAIL_ENDPOINT, gid);
|
var gifDetailsURL = String.format(GIFS_DETAIL_ENDPOINT, gid);
|
||||||
var json = Http.url(gifDetailsURL).header("Authorization", "Bearer " + authToken).getJSON();
|
var json = Http.url(gifDetailsURL).header("Authorization", "Bearer " + authToken).getJSON();
|
||||||
@@ -274,10 +281,11 @@ public class RedgifsRipper extends AbstractJSONRipper {
|
|||||||
* Fetch a temorary auth token for the rip
|
* Fetch a temorary auth token for the rip
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static String fetchAuthToken() throws IOException{
|
private static void fetchAuthToken() throws IOException{
|
||||||
var json = Http.url(TEMPORARY_AUTH_ENDPOINT).getJSON();
|
var json = Http.url(TEMPORARY_AUTH_ENDPOINT).getJSON();
|
||||||
var token = json.getString("token");
|
var token = json.getString("token");
|
||||||
return token;
|
authToken = token;
|
||||||
|
LOGGER.info("Incase of redgif 401 errors, please restart the app to refresh the auth token");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user