forked from j62/ctbrec
Fix favorites page for Streamate
The URL and JSON response for favorites had changed
This commit is contained in:
parent
8935dd8185
commit
7319b6251a
|
@ -3,6 +3,7 @@ package ctbrec.ui.sites.streamate;
|
|||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
|
@ -28,7 +29,7 @@ public class StreamateFollowedService extends PaginatedScheduledService {
|
|||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(StreamateFollowedService.class);
|
||||
|
||||
private static final int MODELS_PER_PAGE = 48;
|
||||
private static final int MODELS_PER_PAGE = 16;
|
||||
private Streamate streamate;
|
||||
private StreamateHttpClient httpClient;
|
||||
private String url;
|
||||
|
@ -37,7 +38,7 @@ public class StreamateFollowedService extends PaginatedScheduledService {
|
|||
public StreamateFollowedService(Streamate streamate) {
|
||||
this.streamate = streamate;
|
||||
this.httpClient = (StreamateHttpClient) streamate.getHttpClient();
|
||||
this.url = streamate.getBaseUrl() + "/api/search/v1/favorites?host=streamate.com&domain=streamate.com";
|
||||
this.url = "https://member.naiadsystems.com/search/favorites?domain=streamate.com&skipXmentSelection=true";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -47,37 +48,42 @@ public class StreamateFollowedService extends PaginatedScheduledService {
|
|||
public List<Model> call() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
|
||||
httpClient.login();
|
||||
String saKey = httpClient.getSaKey();
|
||||
Long userId = httpClient.getUserId();
|
||||
String _url = url + "&page_number=" + page + "&results_per_page=" + MODELS_PER_PAGE + "&sakey=" + saKey + "&userid=" + userId;
|
||||
String _url = url + "&from=" + ((page - 1) * MODELS_PER_PAGE) + "&size=" + MODELS_PER_PAGE;
|
||||
LOG.debug("Fetching page {}", _url);
|
||||
Request request = new Request.Builder()
|
||||
.url(_url)
|
||||
.addHeader("User-Agent", Config.getInstance().getSettings().httpUserAgent)
|
||||
.addHeader("Accept", "application/json, */*")
|
||||
.addHeader("Accept-Language", "en")
|
||||
.addHeader("Referer", streamate.getBaseUrl())
|
||||
.header("User-Agent", Config.getInstance().getSettings().httpUserAgent)
|
||||
.header("Accept", "application/json, */*")
|
||||
.header("Accept-Language", "en")
|
||||
.header("Origin", streamate.getBaseUrl())
|
||||
.header("Referer", streamate.getBaseUrl() + "/view/favorites")
|
||||
.header("sakey", saKey)
|
||||
.header("platform", "SCP")
|
||||
.header("smtid", UUID.randomUUID().toString() + "G0211569057409")
|
||||
.header("smeid", UUID.randomUUID().toString() + "G0211569057409")
|
||||
.header("smvid", UUID.randomUUID().toString() + "G0211569057409")
|
||||
.build();
|
||||
try(Response response = streamate.getHttpClient().execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
List<Model> models = new ArrayList<>();
|
||||
String content = response.body().string();
|
||||
JSONObject json = new JSONObject(content);
|
||||
if(json.optString("status").equals("SM_OK")) {
|
||||
JSONArray performers = json.getJSONArray("Results");
|
||||
if (json.has("totalResultCount")) {
|
||||
JSONArray performers = json.getJSONArray("performers");
|
||||
for (int i = 0; i < performers.length(); i++) {
|
||||
JSONObject p = performers.getJSONObject(i);
|
||||
String nickname = p.getString("Nickname");
|
||||
String nickname = p.getString("nickname");
|
||||
StreamateModel model = (StreamateModel) streamate.createModel(nickname);
|
||||
model.setId(p.getLong("PerformerId"));
|
||||
model.setPreview("https://m1.nsimg.net/biopic/320x240/" + model.getId());
|
||||
boolean online = p.optString("LiveStatus").equals("live");
|
||||
model.setId(p.getLong("id"));
|
||||
model.setPreview(p.getString("thumbnail"));
|
||||
boolean online = p.optBoolean("online");
|
||||
model.setOnline(online);
|
||||
if(online == showOnline) {
|
||||
if (online == showOnline) {
|
||||
models.add(model);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IOException("Status: " + json.optString("status"));
|
||||
throw new IOException("Response: " + json.optString("message"));
|
||||
}
|
||||
return models;
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue