From 4b2e17d0b10100934728c19ca447d8bd875183fc Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Thu, 16 Jul 2020 19:51:14 +0200 Subject: [PATCH] Fix Cam4 favorites tab --- CHANGELOG.md | 7 +++ .../sites/cam4/Cam4FollowedUpdateService.java | 55 +++++-------------- .../src/main/java/ctbrec/sites/cam4/Cam4.java | 2 +- .../java/ctbrec/sites/cam4/Cam4Model.java | 2 +- 4 files changed, 24 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2928127a..5fae3e6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +3.8.3 +======================== +* Fixed Streamate +* Fixed favorites tab for Cam4; kind of, because only the online tab works. I currently don't see + a way to retrieve the offline favorites + + 3.8.2 ======================== * Fixed misconfiguration in global connection pool, which caused a lot of diff --git a/client/src/main/java/ctbrec/ui/sites/cam4/Cam4FollowedUpdateService.java b/client/src/main/java/ctbrec/ui/sites/cam4/Cam4FollowedUpdateService.java index 05144d23..e96b8b64 100644 --- a/client/src/main/java/ctbrec/ui/sites/cam4/Cam4FollowedUpdateService.java +++ b/client/src/main/java/ctbrec/ui/sites/cam4/Cam4FollowedUpdateService.java @@ -3,19 +3,13 @@ package ctbrec.ui.sites.cam4; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.stream.Collectors; -import org.jsoup.nodes.Element; -import org.jsoup.select.Elements; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.json.JSONArray; +import org.json.JSONObject; -import ctbrec.Config; import ctbrec.Model; -import ctbrec.io.HtmlParser; import ctbrec.io.HttpException; import ctbrec.sites.cam4.Cam4; import ctbrec.sites.cam4.Cam4Model; @@ -27,7 +21,6 @@ import okhttp3.Response; public class Cam4FollowedUpdateService extends PaginatedScheduledService { - private static final Logger LOG = LoggerFactory.getLogger(Cam4FollowedUpdateService.class); private Cam4 site; private boolean showOnline = true; @@ -50,46 +43,28 @@ public class Cam4FollowedUpdateService extends PaginatedScheduledService { // login first SiteUiFactory.getUi(site).login(); List models = new ArrayList<>(); - String username = Config.getInstance().getSettings().cam4Username; - String url = site.getBaseUrl() + '/' + username + "/edit/friends_favorites"; + String url = site.getBaseUrl() + "/directoryCams?directoryJson=true&online=" + showOnline + "&url=true&friends=true&favorites=true&resultsPerPage=90"; Request req = new Request.Builder().url(url).build(); - try(Response response = site.getHttpClient().execute(req)) { - if(response.isSuccessful()) { + try (Response response = site.getHttpClient().execute(req)) { + if (response.isSuccessful()) { String content = response.body().string(); - Elements cells = HtmlParser.getTags(content, "div#favorites div.ff_thumb"); - for (Element cell : cells) { - String cellHtml = cell.html(); - Element link = HtmlParser.getTag(cellHtml, "div.ff_img a"); - String path = link.attr("href"); - String modelName = path.substring(1); - Cam4Model model = (Cam4Model) site.createModel(modelName); - model.setPreview("https://snapshots.xcdnpro.com/thumbnails/"+model.getName()+"?s=" + System.currentTimeMillis()); - model.setOnlineStateByShowType(parseOnlineState(cellHtml)); + JSONObject json = new JSONObject(content); + JSONArray users = json.getJSONArray("users"); + for (int i = 0; i < users.length(); i++) { + JSONObject modelJson = users.getJSONObject(i); + String username = modelJson.optString("username"); + Cam4Model model = site.createModel(username); + model.setPreview(modelJson.optString("snapshotImageLink")); + model.setOnlineStateByShowType(modelJson.optString("showType")); + model.setDescription(modelJson.optString("statusMessage")); models.add(model); } - return models.stream() - .filter(m -> { - try { - return m.isOnline() == showOnline; - } catch (IOException | ExecutionException e) { - LOG.error("Couldn't determine online state", e); - return false; - } catch(InterruptedException e) { - Thread.currentThread().interrupt(); - LOG.error("Couldn't determine online state", e); - return false; - } - }).collect(Collectors.toList()); + return models; } else { throw new HttpException(response.code(), response.message()); } } } - - private String parseOnlineState(String cellHtml) { - Element state = HtmlParser.getTag(cellHtml, "div.ff_name div"); - return state.attr("class").equals("online") ? "NORMAL" : "OFFLINE"; - } }; } diff --git a/common/src/main/java/ctbrec/sites/cam4/Cam4.java b/common/src/main/java/ctbrec/sites/cam4/Cam4.java index f099bfcd..6a8b7562 100644 --- a/common/src/main/java/ctbrec/sites/cam4/Cam4.java +++ b/common/src/main/java/ctbrec/sites/cam4/Cam4.java @@ -44,7 +44,7 @@ public class Cam4 extends AbstractSite { } @Override - public Model createModel(String name) { + public Cam4Model createModel(String name) { Cam4Model m = new Cam4Model(); m.setSite(this); m.setName(name); diff --git a/common/src/main/java/ctbrec/sites/cam4/Cam4Model.java b/common/src/main/java/ctbrec/sites/cam4/Cam4Model.java index 5272b78b..63cf1afc 100644 --- a/common/src/main/java/ctbrec/sites/cam4/Cam4Model.java +++ b/common/src/main/java/ctbrec/sites/cam4/Cam4Model.java @@ -103,7 +103,7 @@ public class Cam4Model extends AbstractModel { onlineState = OFFLINE; break; default: - LOG.debug("Unknown show type {}", showType); + LOG.debug("Unknown show type [{}]", showType); onlineState = UNKNOWN; }