Revert "Use a different URL to fetch the stream info for Chaturbate"

This reverts commit 9c8fe1f89c.
This commit is contained in:
0xb00bface 2021-08-21 11:14:59 +02:00
parent 32f930c5c0
commit 4ac1bd4571
2 changed files with 38 additions and 29 deletions

View File

@ -82,7 +82,7 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
try {
resolution = getResolution();
} catch (Exception e) {
} catch(Exception e) {
throw new ExecutionException(e);
}
return resolution;
@ -165,26 +165,31 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
@Override
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
streamInfo = loadStreamInfo();
MasterPlaylist masterPlaylist = getMasterPlaylist();
List<StreamSource> sources = new ArrayList<>();
for (PlaylistData playlist : masterPlaylist.getPlaylists()) {
if (playlist.hasStreamInfo()) {
StreamSource src = new StreamSource();
src.bandwidth = playlist.getStreamInfo().getBandwidth();
src.height = playlist.getStreamInfo().getResolution().height;
String masterUrl = streamInfo.hls_source;
String baseUrl = masterUrl.substring(0, masterUrl.lastIndexOf('/') + 1);
String segmentUri = baseUrl + playlist.getUri();
src.mediaPlaylistUrl = segmentUri;
if(src.mediaPlaylistUrl.contains("?")) {
src.mediaPlaylistUrl = src.mediaPlaylistUrl.substring(0, src.mediaPlaylistUrl.lastIndexOf('?'));
try {
streamInfo = loadStreamInfo();
MasterPlaylist masterPlaylist = getMasterPlaylist();
List<StreamSource> sources = new ArrayList<>();
for (PlaylistData playlist : masterPlaylist.getPlaylists()) {
if (playlist.hasStreamInfo()) {
StreamSource src = new StreamSource();
src.bandwidth = playlist.getStreamInfo().getBandwidth();
src.height = playlist.getStreamInfo().getResolution().height;
String masterUrl = streamInfo.url;
String baseUrl = masterUrl.substring(0, masterUrl.lastIndexOf('/') + 1);
String segmentUri = baseUrl + playlist.getUri();
src.mediaPlaylistUrl = segmentUri;
if(src.mediaPlaylistUrl.contains("?")) {
src.mediaPlaylistUrl = src.mediaPlaylistUrl.substring(0, src.mediaPlaylistUrl.lastIndexOf('?'));
}
LOG.trace("Media playlist {}", src.mediaPlaylistUrl);
sources.add(src);
}
LOG.trace("Media playlist {}", src.mediaPlaylistUrl);
sources.add(src);
}
return sources;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ExecutionException(e);
}
return sources;
}
@Override
@ -241,12 +246,12 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
}
}
private StreamInfo getStreamInfo() throws IOException {
private StreamInfo getStreamInfo() throws IOException, InterruptedException {
return getStreamInfo(false);
}
private StreamInfo getStreamInfo(boolean failFast) throws IOException {
if (failFast) {
private StreamInfo getStreamInfo(boolean failFast) throws IOException, InterruptedException {
if(failFast) {
return streamInfo;
} else {
return Optional.ofNullable(streamInfo).orElse(loadStreamInfo());
@ -257,8 +262,13 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
if (Duration.between(lastStreamInfoRequest, Instant.now()).getSeconds() < 2) {
return streamInfo;
}
RequestBody body = new FormBody.Builder()
.add("room_slug", getName())
.add("bandwidth", "high")
.build();
Request req = new Request.Builder()
.url(getSite().getBaseUrl() + "/api/chatvideocontext/" + getName() + '/')
.url(getSite().getBaseUrl() + "/get_edge_hls_url_ajax/")
.post(body)
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
.build();
@ -279,10 +289,9 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
}
}
private int[] getResolution() throws IOException, ParseException, PlaylistException {
private int[] getResolution() throws IOException, ParseException, PlaylistException, InterruptedException {
int[] res = new int[2];
String url = Optional.ofNullable(getStreamInfo().hls_source).orElse("");
if(!url.startsWith("http")) {
if(!getStreamInfo().url.startsWith("http")) {
return res;
}
@ -316,14 +325,14 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
return res;
}
public MasterPlaylist getMasterPlaylist() throws IOException, ParseException, PlaylistException {
public MasterPlaylist getMasterPlaylist() throws IOException, ParseException, PlaylistException, InterruptedException {
return getMasterPlaylist(getStreamInfo());
}
private MasterPlaylist getMasterPlaylist(StreamInfo streamInfo) throws IOException, ParseException, PlaylistException {
LOG.trace("Loading master playlist {}", streamInfo.hls_source);
LOG.trace("Loading master playlist {}", streamInfo.url);
Request req = new Request.Builder()
.url(streamInfo.hls_source)
.url(streamInfo.url)
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
.build();
try (Response response = getSite().getHttpClient().execute(req)) {

View File

@ -1,7 +1,7 @@
package ctbrec.sites.chaturbate;
public class StreamInfo {
public String hls_source;
public String url;
public String room_status;
public String hidden_message;
public boolean success;