forked from j62/ctbrec
1
0
Fork 0

Fix Cam4 unfollow

This commit is contained in:
0xb00bface 2021-04-30 14:15:41 +02:00
parent 0ad5e8ce87
commit 127d555c67
2 changed files with 8 additions and 45 deletions

View File

@ -1,6 +1,7 @@
4.2.0
========================
* App can now be minimized to tray
* Fixed unfollow for Cam4 models
4.1.3
========================

View File

@ -13,14 +13,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.json.JSONObject;
import org.jsoup.nodes.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,14 +36,11 @@ import com.iheartradio.m3u8.data.StreamInfo;
import ctbrec.AbstractModel;
import ctbrec.Config;
import ctbrec.StringUtil;
import ctbrec.io.HtmlParser;
import ctbrec.io.HttpException;
import ctbrec.recorder.download.HttpHeaderFactory;
import ctbrec.recorder.download.HttpHeaderFactoryImpl;
import ctbrec.recorder.download.StreamSource;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class Cam4Model extends AbstractModel {
@ -278,49 +273,16 @@ public class Cam4Model extends AbstractModel {
@Override
public boolean unfollow() throws IOException {
// get model user id
String url = site.getBaseUrl() + '/' + getName();
// send unfollow request
String username = Config.getInstance().getSettings().cam4Username;
String url = site.getBaseUrl() + "/rest/v1.0/favorites/" + username + '/' + getName();
Request req = new Request.Builder()
.url(url)
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
.delete()
.build();
// we have to use a client without any cam4 cookies here, otherwise
// this request is redirected to the login page. no idea why
try (Response response = site.getRecorder().getHttpClient().execute(req)) {
if (response.isSuccessful()) {
String content = response.body().string();
String broadCasterId = null;
try {
Element tag = HtmlParser.getTag(content, "input[name=\"broadcasterId\"]");
broadCasterId = tag.attr("value");
} catch (Exception e) {
LOG.debug(content);
throw new IOException(e);
}
// send unfollow request
String username = Config.getInstance().getSettings().cam4Username;
url = site.getBaseUrl() + '/' + username + "/edit/friends_favorites";
RequestBody body = new FormBody.Builder()
.add("deleteFavorites", broadCasterId)
.add("simpleresult", "true")
.build();
req = new Request.Builder()
.url(url)
.post(body)
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
.build();
try (Response resp = site.getHttpClient().execute(req)) {
if (resp.isSuccessful()) {
return Objects.equals(resp.body().string(), "Ok");
} else {
return false;
}
}
} else {
return false;
}
try (Response resp = site.getHttpClient().execute(req)) {
return resp.isSuccessful();
}
}