Set online state in all update services

This commit is contained in:
0xb00bface 2020-08-20 17:14:34 +02:00
parent 6c0fe83816
commit 217b56b88c
5 changed files with 44 additions and 3 deletions

View File

@ -1,9 +1,13 @@
package ctbrec.ui.sites.cam4;
import static ctbrec.Model.State.*;
import static ctbrec.io.HttpConstants.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
@ -64,7 +68,11 @@ public class Cam4UpdateService extends PaginatedScheduledService {
if(loginRequired) {
SiteUiFactory.getUi(site).login();
}
Request request = new Request.Builder().url(url).build();
Request request = new Request.Builder()
.url(url)
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
.build();
try (Response response = site.getHttpClient().execute(request)) {
if (response.isSuccessful()) {
JSONObject json = new JSONObject(response.body().string());
@ -76,11 +84,15 @@ public class Cam4UpdateService extends PaginatedScheduledService {
Element profileLink = HtmlParser.getTag(boxHtml, "a.profile-preview");
String path = profileLink.attr("href");
String slug = path.substring(1);
Cam4Model model = (Cam4Model) site.createModel(slug);
Cam4Model model = site.createModel(slug);
String playlistUrl = profileLink.attr("data-hls-preview-url");
model.setPlaylistUrl(playlistUrl);
model.setPreview("https://snapshots.xcdnpro.com/thumbnails/" + model.getName() + "?s=" + System.currentTimeMillis());
model.setDescription(parseDesription(boxHtml));
model.setOnlineState(ONLINE);
if(boxHtml.contains("In private show")) {
model.setOnlineState(PRIVATE);
}
models.add(model);
}
return models;

View File

@ -1,5 +1,6 @@
package ctbrec.ui.sites.streamate;
import static ctbrec.Model.State.*;
import static ctbrec.io.HttpConstants.*;
import java.io.IOException;
@ -81,6 +82,7 @@ public class StreamateFollowedService extends PaginatedScheduledService {
model.setPreview(p.getString("thumbnail"));
boolean online = p.optBoolean("online") && notPrivateEtc(p);
model.setOnline(online);
model.setOnlineState(online ? ONLINE : OFFLINE);
if (online == showOnline) {
models.add(model);
}

View File

@ -1,5 +1,7 @@
package ctbrec.ui.sites.streamate;
import static ctbrec.Model.State.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -52,6 +54,7 @@ public class StreamateUpdateService extends PaginatedScheduledService {
List<Model> models = new ArrayList<>();
String content = response.body().string();
JSONObject json = new JSONObject(content);
System.err.println(json.toString(2));
JSONArray performers = json.getJSONArray("performers");
for (int i = 0; i < performers.length(); i++) {
JSONObject p = performers.getJSONObject(i);
@ -59,7 +62,9 @@ public class StreamateUpdateService extends PaginatedScheduledService {
StreamateModel model = (StreamateModel) streamate.createModel(nickname);
model.setId(p.getLong("id"));
model.setPreview(p.getString("thumbnail"));
model.setOnline(p.optBoolean("online"));
boolean online = p.optBoolean("online");
model.setOnline(online);
model.setOnlineState(online ? ONLINE : OFFLINE);
// TODO figure out, what all the states mean
// liveState {}
// exclusiveShow false
@ -69,6 +74,11 @@ public class StreamateUpdateService extends PaginatedScheduledService {
// preGoldShow true
// privateChat false
// specialShow false
if (p.optBoolean("onBreak")) {
model.setOnlineState(AWAY);
} else if (p.optBoolean("goldShow") || p.optBoolean("privateChat") || p.optBoolean("exclusiveShow")) {
model.setOnlineState(PRIVATE);
}
models.add(model);
}
return models;

View File

@ -1,5 +1,6 @@
package ctbrec.ui.sites.stripchat;
import static ctbrec.Model.State.*;
import static ctbrec.io.HttpConstants.*;
import java.io.IOException;
@ -68,6 +69,7 @@ public class StripchatFollowedUpdateService extends PaginatedScheduledService {
try (Response response = stripchat.getHttpClient().execute(request)) {
if (response.isSuccessful()) {
JSONObject json = new JSONObject(response.body().string());
System.err.println(json.toString(2));
if (json.has("models")) {
JSONArray users = json.getJSONArray("models");
for (int i = 0; i < users.length(); i++) {
@ -75,6 +77,7 @@ public class StripchatFollowedUpdateService extends PaginatedScheduledService {
StripchatModel model = stripchat.createModel(user.optString("username"));
model.setDescription(user.optString("description"));
model.setPreview(user.optString("previewUrlThumbBig"));
model.setOnlineState(mapStatus(user.optString("status")));
models.add(model);
}
}
@ -114,4 +117,17 @@ public class StripchatFollowedUpdateService extends PaginatedScheduledService {
}
};
}
protected ctbrec.Model.State mapStatus(String status) {
switch (status) {
case "public":
return ONLINE;
case "idle":
return AWAY;
case "off":
return OFFLINE;
default:
return UNKNOWN;
}
}
}

View File

@ -75,6 +75,7 @@ public class StripchatUpdateService extends PaginatedScheduledService {
model.setDescription("");
model.setPreview(jsonModel.optString("snapshotUrl"));
model.setDisplayName(model.getName());
model.setOnlineState(Model.State.ONLINE);
models.add(model);
} catch (Exception e) {
LOG.warn("Couldn't parse one of the models: {}", jsonModel, e);