forked from j62/ctbrec
Implement follow/unfollow for BongaCams
This commit is contained in:
parent
d4f5249777
commit
6e58dd6be5
|
@ -0,0 +1,14 @@
|
|||
package ctbrec.ui.sites.bonga;
|
||||
|
||||
import ctbrec.sites.Site;
|
||||
import ctbrec.ui.FollowedTab;
|
||||
import ctbrec.ui.PaginatedScheduledService;
|
||||
import ctbrec.ui.ThumbOverviewTab;
|
||||
|
||||
public class BongaCamsFriendsTab extends ThumbOverviewTab implements FollowedTab {
|
||||
|
||||
public BongaCamsFriendsTab(String title, PaginatedScheduledService updateService, Site site) {
|
||||
super(title, updateService, site);
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,7 @@ public class BongaCamsTabProvider extends TabProvider {
|
|||
|
||||
private BongaCams bongaCams;
|
||||
private Recorder recorder;
|
||||
private Tab friendsTab;
|
||||
private BongaCamsFriendsTab friendsTab;
|
||||
|
||||
public BongaCamsTabProvider(BongaCams bongaCams) {
|
||||
this.bongaCams = bongaCams;
|
||||
|
@ -54,7 +54,8 @@ public class BongaCamsTabProvider extends TabProvider {
|
|||
// friends
|
||||
url = BongaCams.BASE_URL + "/tools/listing_v3.php?livetab=friends&online_only=true&offset=";
|
||||
updateService = new BongaCamsUpdateService(bongaCams, url);
|
||||
friendsTab = createTab("Friends", updateService);
|
||||
friendsTab = new BongaCamsFriendsTab("Friends", updateService, bongaCams);
|
||||
friendsTab.setRecorder(recorder);
|
||||
tabs.add(friendsTab);
|
||||
|
||||
return tabs;
|
||||
|
|
|
@ -124,7 +124,7 @@ public class BongaCams extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean supportsFollow() {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -26,6 +27,7 @@ import com.iheartradio.m3u8.data.StreamInfo;
|
|||
|
||||
import ctbrec.AbstractModel;
|
||||
import ctbrec.Config;
|
||||
import ctbrec.io.HtmlParser;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import okhttp3.FormBody;
|
||||
|
@ -211,15 +213,105 @@ public class BongaCamsModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public boolean follow() throws IOException {
|
||||
return false;
|
||||
if(!getSite().login()) {
|
||||
throw new IOException("Not logged in");
|
||||
}
|
||||
|
||||
String url = getSite().getBaseUrl() + "/friend/add/" + getName();
|
||||
LOG.debug("Calling {}", url);
|
||||
RequestBody body = new FormBody.Builder()
|
||||
.add("src", "public-chat")
|
||||
.add("_csrf_token", getCsrfToken())
|
||||
.build();
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.method("POST", body)
|
||||
.header("Accept", "*/*")
|
||||
.header("Accept-Language", "en-US,en;q=0.5")
|
||||
.header("Referer", getUrl())
|
||||
.header("User-Agent", Config.getInstance().getSettings().httpUserAgent)
|
||||
.header("X-Requested-With", "XMLHttpRequest")
|
||||
.build();
|
||||
try(Response resp = site.getHttpClient().execute(req)) {
|
||||
if(resp.isSuccessful()) {
|
||||
String msg = resp.body().string();
|
||||
JSONObject json = new JSONObject(msg);
|
||||
if(json.optBoolean("success")) {
|
||||
LOG.debug("Follow/Unfollow -> {}", msg);
|
||||
return true;
|
||||
} else {
|
||||
LOG.debug(msg);
|
||||
throw new IOException("Response was " + msg);
|
||||
}
|
||||
} else {
|
||||
throw new HttpException(resp.code(), resp.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getCsrfToken() throws IOException {
|
||||
Request req = new Request.Builder()
|
||||
.url(getUrl())
|
||||
.header("Accept", "*/*")
|
||||
.header("Accept-Language", "en-US,en;q=0.5")
|
||||
.header("Referer", BongaCams.BASE_URL)
|
||||
.header("User-Agent", Config.getInstance().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try(Response resp = site.getHttpClient().execute(req)) {
|
||||
if(resp.isSuccessful()) {
|
||||
String content = resp.body().string();
|
||||
Element html = HtmlParser.getTag(content, "html");
|
||||
String csrfToken = html.attr("data-csrf_value");
|
||||
LOG.debug("CSRF-Token {}", csrfToken);
|
||||
return csrfToken;
|
||||
} else {
|
||||
throw new HttpException(resp.code(), resp.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unfollow() throws IOException {
|
||||
return false;
|
||||
if (!getSite().login()) {
|
||||
throw new IOException("Not logged in");
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
String url = getSite().getBaseUrl() + "/friend/ajax/remove/" + getName() + '/' + getUserId();
|
||||
LOG.debug("Calling {}", url);
|
||||
RequestBody body = new FormBody.Builder()
|
||||
.add("_csrf_token", getCsrfToken())
|
||||
.build();
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.method("POST", body)
|
||||
.header("Accept", "*/*")
|
||||
.header("Accept-Language", "en-US,en;q=0.5")
|
||||
.header("Referer", getUrl())
|
||||
.header("User-Agent", Config.getInstance().getSettings().httpUserAgent)
|
||||
.header("X-Requested-With", "XMLHttpRequest")
|
||||
.build();
|
||||
try (Response resp = site.getHttpClient().execute(req)) {
|
||||
if (resp.isSuccessful()) {
|
||||
String msg = resp.body().string();
|
||||
JSONObject json = new JSONObject(msg);
|
||||
if (json.optString("status").equals("success")) {
|
||||
LOG.debug("Follow/Unfollow -> {}", msg);
|
||||
return true;
|
||||
} else {
|
||||
LOG.debug(msg);
|
||||
throw new IOException("Response was " + msg);
|
||||
}
|
||||
} else {
|
||||
throw new HttpException(resp.code(), resp.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getUserId() throws IOException {
|
||||
if (userId == 0) {
|
||||
JSONObject roomData = getRoomData();
|
||||
userId = roomData.getJSONObject("performerData").getInt("userId");
|
||||
}
|
||||
return userId;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue