forked from j62/ctbrec
Core cleanup
This commit is contained in:
parent
97715aecc5
commit
086e15578f
|
@ -13,6 +13,8 @@ import org.json.JSONArray;
|
|||
import org.json.JSONObject;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
|
@ -28,6 +30,8 @@ import okhttp3.Response;
|
|||
|
||||
public class MVLive extends AbstractSite {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MVLive.class);
|
||||
|
||||
public static final String APP_HOST = "app-v1.live.manyvids.com";
|
||||
public static final String WS_URL = "wss://" + APP_HOST;
|
||||
public static final String WS_ORIGIN = "https://live.manyvids.com";
|
||||
|
@ -123,9 +127,17 @@ public class MVLive extends AbstractSite {
|
|||
.build();
|
||||
try (Response response = getHttpClient().execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
List<Model> models = new ArrayList<>();
|
||||
String content = response.body().string();
|
||||
Elements cards = HtmlParser.getTags(content, "div[class*=-model]");
|
||||
return parseModelCards(cards);
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<Model> parseModelCards(Elements cards) {
|
||||
List<Model> models = new ArrayList<>();
|
||||
for (Element card : cards) {
|
||||
try {
|
||||
String cardHtml = card.html();
|
||||
|
@ -145,6 +157,7 @@ public class MVLive extends AbstractSite {
|
|||
} else if(cssClass.contains("private")) {
|
||||
model.setOnlineState(Model.State.PRIVATE);
|
||||
} else {
|
||||
LOG.debug("Unknown online state {}", cssClass);
|
||||
model.setOnlineState(Model.State.UNKNOWN);
|
||||
}
|
||||
models.add(model);
|
||||
|
@ -157,10 +170,6 @@ public class MVLive extends AbstractSite {
|
|||
}
|
||||
}
|
||||
return models;
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -213,6 +222,15 @@ public class MVLive extends AbstractSite {
|
|||
try (Response response = getHttpClient().execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
String responseBody = response.body().string();
|
||||
parseSearchResult(result, responseBody);
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void parseSearchResult(List<Model> result, String responseBody) {
|
||||
JSONObject json = new JSONObject(responseBody);
|
||||
if(json.has("stars")) {
|
||||
JSONArray stars = json.getJSONArray("stars");
|
||||
|
@ -236,11 +254,6 @@ public class MVLive extends AbstractSite {
|
|||
result.add(model);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,10 +31,12 @@ import com.iheartradio.m3u8.data.PlaylistData;
|
|||
import ctbrec.AbstractModel;
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.NotImplementedExcetion;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.recorder.download.Download;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import ctbrec.sites.ModelOfflineException;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
@ -42,8 +44,8 @@ public class MVLiveModel extends AbstractModel {
|
|||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(MVLiveModel.class);
|
||||
|
||||
private MVLiveHttpClient httpClient;
|
||||
private MVLiveClient client;
|
||||
private transient MVLiveHttpClient httpClient;
|
||||
private transient MVLiveClient client;
|
||||
private String roomNumber;
|
||||
|
||||
@Override
|
||||
|
@ -138,7 +140,7 @@ public class MVLiveModel extends AbstractModel {
|
|||
roomNumber = json.getString("floorId");
|
||||
} else {
|
||||
LOG.debug("Room number response: {}", json.toString(2));
|
||||
throw new RuntimeException(getName() + " is offline");
|
||||
throw new ModelOfflineException(this);
|
||||
}
|
||||
}
|
||||
return roomNumber;
|
||||
|
@ -194,6 +196,7 @@ public class MVLiveModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public void receiveTip(Double tokens) throws IOException {
|
||||
throw new NotImplementedExcetion("Sending tips is not implemeted for MVLive");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue