Improved resolution requests

This commit is contained in:
0xboobface 2018-07-25 20:21:51 +02:00
parent a9178a2d21
commit f1adead851
5 changed files with 30 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import static ctbrec.ui.Launcher.BASE_URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
@ -26,6 +27,7 @@ public class ModelParser {
model.setPreview(HtmlParser.getTag(cellHtml, "a img").attr("src"));
model.setUrl(BASE_URI + HtmlParser.getTag(cellHtml, "a").attr("href"));
model.setDescription(HtmlParser.getText(cellHtml, "div.details ul.subject"));
model.setOnline(!Objects.equals("offline", HtmlParser.getText(cellHtml, "div.details li.cams")));
Elements tags = HtmlParser.getTags(cellHtml, "div.details ul.subject li a");
if(tags != null) {
for (Element tag : tags) {

View File

@ -7,7 +7,7 @@ import java.util.List;
public class Settings {
public boolean localRecording = true;
public int httpPort = 8080;
public int httpTimeout = 30;
public int httpTimeout = 10;
public String httpServer = "localhost";
public String recordingsDir = System.getProperty("user.home") + File.separator + "ctbrec";
public String mediaPlayer = "/usr/bin/mpv";

View File

@ -2,6 +2,7 @@ package ctbrec.recorder;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -45,6 +46,7 @@ public class Chaturbate {
Moshi moshi = new Moshi.Builder().build();
JsonAdapter<StreamInfo> adapter = moshi.adapter(StreamInfo.class);
StreamInfo streamInfo = adapter.fromJson(content);
model.setOnline(Objects.equals(streamInfo.room_status, "public"));
return streamInfo;
} else {
int code = response.code();

View File

@ -192,7 +192,9 @@ public class LocalRecorder implements Recorder {
private boolean checkIfOnline(Model model) throws IOException {
StreamInfo streamInfo = Chaturbate.getStreamInfo(model, client);
return Objects.equals(streamInfo.room_status, "public");
boolean online = Objects.equals(streamInfo.room_status, "public");
model.setOnline(online);
return online;
}
private void tryRestartRecording(Model model) {

View File

@ -208,7 +208,7 @@ public class ThumbCell extends StackPane {
private void determineResolution() {
if(ThumbOverviewTab.resolutionProcessing.contains(model)) {
LOG.trace("Already fetching resolution for model {}", model.getName());
LOG.debug("Already fetching resolution for model {}. Queue size {}", model.getName(), ThumbOverviewTab.resolutionProcessing.size());
return;
}
@ -254,8 +254,17 @@ public class ThumbCell extends StackPane {
// when we first requested the stream info, so we remove this invalid value from the "cache"
// so that it is requested again
if(model.isOnline() && res[1] == 0) {
LOG.debug("Removing invalid resolution value for {}", model.getName());
resolutions.remove(model.getName());
ThumbOverviewTab.threadPool.submit(() -> {
try {
Chaturbate.getStreamInfo(model, client);
if(model.isOnline()) {
LOG.debug("Removing invalid resolution value for {}", model.getName());
resolutions.remove(model.getName());
}
} catch (IOException e) {
LOG.error("Coulnd't get resolution for model {}", model, e);
}
});
}
}
}
@ -517,7 +526,16 @@ public class ThumbCell extends StackPane {
}
public void setModel(Model model) {
this.model = model;
//this.model = model;
this.model.setName(model.getName());
this.model.setDescription(model.getDescription());
this.model.setOnline(model.isOnline());
this.model.setPreview(model.getPreview());
this.model.setStreamResolution(model.getStreamResolution());
this.model.setStreamUrlIndex(model.getStreamUrlIndex());
this.model.setTags(model.getTags());
this.model.setUrl(model.getUrl());
update();
}