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

View File

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