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.json.JSONObject;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
|
@ -28,6 +30,8 @@ import okhttp3.Response;
|
||||||
|
|
||||||
public class MVLive extends AbstractSite {
|
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 APP_HOST = "app-v1.live.manyvids.com";
|
||||||
public static final String WS_URL = "wss://" + APP_HOST;
|
public static final String WS_URL = "wss://" + APP_HOST;
|
||||||
public static final String WS_ORIGIN = "https://live.manyvids.com";
|
public static final String WS_ORIGIN = "https://live.manyvids.com";
|
||||||
|
@ -123,46 +127,51 @@ public class MVLive extends AbstractSite {
|
||||||
.build();
|
.build();
|
||||||
try (Response response = getHttpClient().execute(request)) {
|
try (Response response = getHttpClient().execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
List<Model> models = new ArrayList<>();
|
|
||||||
String content = response.body().string();
|
String content = response.body().string();
|
||||||
Elements cards = HtmlParser.getTags(content, "div[class*=-model]");
|
Elements cards = HtmlParser.getTags(content, "div[class*=-model]");
|
||||||
for (Element card : cards) {
|
return parseModelCards(cards);
|
||||||
try {
|
|
||||||
String cardHtml = card.html();
|
|
||||||
Element link = HtmlParser.getTag(cardHtml, "a");
|
|
||||||
link.setBaseUri(getBaseUrl());
|
|
||||||
String name = HtmlParser.getText(cardHtml, "h4 a");
|
|
||||||
MVLiveModel model = createModel(name);
|
|
||||||
model.setUrl(link.absUrl("href"));
|
|
||||||
Element thumb = HtmlParser.getTag(cardHtml, "a img.b-lazy");
|
|
||||||
thumb.setBaseUri(getBaseUrl());
|
|
||||||
model.setPreview(thumb.absUrl("data-src"));
|
|
||||||
|
|
||||||
Element status = HtmlParser.getTag(cardHtml, "h4[class~=profile-pic-name]");
|
|
||||||
String cssClass = status.attr("class");
|
|
||||||
if(cssClass.contains("live")) {
|
|
||||||
model.setOnlineState(Model.State.ONLINE);
|
|
||||||
} else if(cssClass.contains("private")) {
|
|
||||||
model.setOnlineState(Model.State.PRIVATE);
|
|
||||||
} else {
|
|
||||||
model.setOnlineState(Model.State.UNKNOWN);
|
|
||||||
}
|
|
||||||
models.add(model);
|
|
||||||
} catch(RuntimeException e) {
|
|
||||||
if(e.getMessage().contains("No element selected by")) {
|
|
||||||
// ignore
|
|
||||||
} else {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return models;
|
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message());
|
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();
|
||||||
|
Element link = HtmlParser.getTag(cardHtml, "a");
|
||||||
|
link.setBaseUri(getBaseUrl());
|
||||||
|
String name = HtmlParser.getText(cardHtml, "h4 a");
|
||||||
|
MVLiveModel model = createModel(name);
|
||||||
|
model.setUrl(link.absUrl("href"));
|
||||||
|
Element thumb = HtmlParser.getTag(cardHtml, "a img.b-lazy");
|
||||||
|
thumb.setBaseUri(getBaseUrl());
|
||||||
|
model.setPreview(thumb.absUrl("data-src"));
|
||||||
|
|
||||||
|
Element status = HtmlParser.getTag(cardHtml, "h4[class~=profile-pic-name]");
|
||||||
|
String cssClass = status.attr("class");
|
||||||
|
if(cssClass.contains("live")) {
|
||||||
|
model.setOnlineState(Model.State.ONLINE);
|
||||||
|
} 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);
|
||||||
|
} catch(RuntimeException e) {
|
||||||
|
if(e.getMessage().contains("No element selected by")) {
|
||||||
|
// ignore
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return models;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean supportsSearch() {
|
public boolean supportsSearch() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -213,29 +222,7 @@ public class MVLive extends AbstractSite {
|
||||||
try (Response response = getHttpClient().execute(request)) {
|
try (Response response = getHttpClient().execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String responseBody = response.body().string();
|
String responseBody = response.body().string();
|
||||||
JSONObject json = new JSONObject(responseBody);
|
parseSearchResult(result, responseBody);
|
||||||
if(json.has("stars")) {
|
|
||||||
JSONArray stars = json.getJSONArray("stars");
|
|
||||||
for (int i = 0; i < stars.length(); i++) {
|
|
||||||
JSONObject star = stars.getJSONObject(i);
|
|
||||||
String name = star.getString("label");
|
|
||||||
MVLiveModel model = createModel(name);
|
|
||||||
long id = star.getLong("id");
|
|
||||||
String url = "https://www.manyvids.com/MVLive/" + model.getDisplayName() + '/' + id + '/';
|
|
||||||
model.setUrl(url);
|
|
||||||
model.setPreview(star.getString("img"));
|
|
||||||
if (star.optString("is_live").equals("1")) {
|
|
||||||
if (star.optString("is_private").equals("1")) {
|
|
||||||
model.setOnlineState(State.PRIVATE);
|
|
||||||
} else {
|
|
||||||
model.setOnlineState(State.ONLINE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
model.setOnlineState(State.OFFLINE);
|
|
||||||
}
|
|
||||||
result.add(model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message());
|
throw new HttpException(response.code(), response.message());
|
||||||
}
|
}
|
||||||
|
@ -243,6 +230,32 @@ public class MVLive extends AbstractSite {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void parseSearchResult(List<Model> result, String responseBody) {
|
||||||
|
JSONObject json = new JSONObject(responseBody);
|
||||||
|
if(json.has("stars")) {
|
||||||
|
JSONArray stars = json.getJSONArray("stars");
|
||||||
|
for (int i = 0; i < stars.length(); i++) {
|
||||||
|
JSONObject star = stars.getJSONObject(i);
|
||||||
|
String name = star.getString("label");
|
||||||
|
MVLiveModel model = createModel(name);
|
||||||
|
long id = star.getLong("id");
|
||||||
|
String url = "https://www.manyvids.com/MVLive/" + model.getDisplayName() + '/' + id + '/';
|
||||||
|
model.setUrl(url);
|
||||||
|
model.setPreview(star.getString("img"));
|
||||||
|
if (star.optString("is_live").equals("1")) {
|
||||||
|
if (star.optString("is_private").equals("1")) {
|
||||||
|
model.setOnlineState(State.PRIVATE);
|
||||||
|
} else {
|
||||||
|
model.setOnlineState(State.ONLINE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
model.setOnlineState(State.OFFLINE);
|
||||||
|
}
|
||||||
|
result.add(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Model createModelFromUrl(String url) {
|
public Model createModelFromUrl(String url) {
|
||||||
Matcher m = Pattern.compile("https://live.manyvids.com/(?:stream/)?(.*?)(?:/.*?)?").matcher(url.trim());
|
Matcher m = Pattern.compile("https://live.manyvids.com/(?:stream/)?(.*?)(?:/.*?)?").matcher(url.trim());
|
||||||
|
|
|
@ -31,10 +31,12 @@ import com.iheartradio.m3u8.data.PlaylistData;
|
||||||
import ctbrec.AbstractModel;
|
import ctbrec.AbstractModel;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
|
import ctbrec.NotImplementedExcetion;
|
||||||
import ctbrec.StringUtil;
|
import ctbrec.StringUtil;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
import ctbrec.recorder.download.Download;
|
import ctbrec.recorder.download.Download;
|
||||||
import ctbrec.recorder.download.StreamSource;
|
import ctbrec.recorder.download.StreamSource;
|
||||||
|
import ctbrec.sites.ModelOfflineException;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
@ -42,8 +44,8 @@ public class MVLiveModel extends AbstractModel {
|
||||||
|
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(MVLiveModel.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(MVLiveModel.class);
|
||||||
|
|
||||||
private MVLiveHttpClient httpClient;
|
private transient MVLiveHttpClient httpClient;
|
||||||
private MVLiveClient client;
|
private transient MVLiveClient client;
|
||||||
private String roomNumber;
|
private String roomNumber;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -138,7 +140,7 @@ public class MVLiveModel extends AbstractModel {
|
||||||
roomNumber = json.getString("floorId");
|
roomNumber = json.getString("floorId");
|
||||||
} else {
|
} else {
|
||||||
LOG.debug("Room number response: {}", json.toString(2));
|
LOG.debug("Room number response: {}", json.toString(2));
|
||||||
throw new RuntimeException(getName() + " is offline");
|
throw new ModelOfflineException(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return roomNumber;
|
return roomNumber;
|
||||||
|
@ -194,6 +196,7 @@ public class MVLiveModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveTip(Double tokens) throws IOException {
|
public void receiveTip(Double tokens) throws IOException {
|
||||||
|
throw new NotImplementedExcetion("Sending tips is not implemeted for MVLive");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue