Improve online check for Chaturbate by determining the size of the offline fallback image
This commit is contained in:
parent
0c5a2df61f
commit
a9b1080d2f
|
@ -7,6 +7,7 @@ import com.iheartradio.m3u8.data.Playlist;
|
|||
import com.iheartradio.m3u8.data.PlaylistData;
|
||||
import ctbrec.AbstractModel;
|
||||
import ctbrec.Config;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.io.json.ObjectMapperFactory;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
|
@ -38,6 +39,7 @@ public class ChaturbateModel extends AbstractModel {
|
|||
private int[] resolution = new int[2];
|
||||
private transient StreamInfo streamInfo;
|
||||
private transient Instant lastStreamInfoRequest = Instant.EPOCH;
|
||||
private transient int offlineImageSize = 0;
|
||||
private final transient ObjectMapper mapper = ObjectMapperFactory.getMapper();
|
||||
|
||||
/**
|
||||
|
@ -74,19 +76,43 @@ public class ChaturbateModel extends AbstractModel {
|
|||
private boolean isOffline() {
|
||||
String normalizedName = getName().toLowerCase().trim();
|
||||
String previewUrl = "https://roomimg.stream.highwebmedia.com/ri/" + normalizedName + ".jpg?" + Instant.now().getEpochSecond();
|
||||
if (offlineImageSize == 0) {
|
||||
offlineImageSize = getOfflineImageSize();
|
||||
}
|
||||
return getImageSize(previewUrl) == offlineImageSize;
|
||||
}
|
||||
|
||||
private int getOfflineImageSize() {
|
||||
String randomName = UUID.randomUUID().toString().replace("-", "").substring(0, 10);
|
||||
String previewUrl = "https://roomimg.stream.highwebmedia.com/ri/" + randomName + ".jpg?" + Instant.now().getEpochSecond();
|
||||
int imageSize = getImageSize(previewUrl);
|
||||
if (imageSize == 0) {
|
||||
imageSize = 21971;
|
||||
}
|
||||
return imageSize;
|
||||
}
|
||||
|
||||
private int getImageSize(String url) {
|
||||
int imageSize = 0;
|
||||
Request req = new Request.Builder()
|
||||
.url(previewUrl)
|
||||
.url(url)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.head()
|
||||
.build();
|
||||
try (Response response = getSite().getHttpClient().execute(req)) {
|
||||
if (response.isSuccessful()) {
|
||||
return response.header("Content-Length", "0").equals("21971");
|
||||
imageSize = Integer.parseInt(response.header("Content-Length", "0"));
|
||||
if (StringUtil.isNotBlank(response.header("Cf-Polished"))) {
|
||||
String[] parts = response.header("Cf-Polished").split("=");
|
||||
if (parts.length > 1) {
|
||||
imageSize = Integer.parseInt(parts[1].trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// fail silently
|
||||
}
|
||||
return false;
|
||||
return imageSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue