Use a different URL to fetch the stream info for Chaturbate
This commit is contained in:
parent
4946d0161a
commit
9c8fe1f89c
|
@ -81,7 +81,7 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
|||
|
||||
try {
|
||||
resolution = getResolution();
|
||||
} catch(Exception e) {
|
||||
} catch (Exception e) {
|
||||
throw new ExecutionException(e);
|
||||
}
|
||||
return resolution;
|
||||
|
@ -164,31 +164,26 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
|||
|
||||
@Override
|
||||
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
|
||||
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);
|
||||
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('?'));
|
||||
}
|
||||
LOG.trace("Media playlist {}", src.mediaPlaylistUrl);
|
||||
sources.add(src);
|
||||
}
|
||||
return sources;
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new ExecutionException(e);
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -245,12 +240,12 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
|||
}
|
||||
}
|
||||
|
||||
private StreamInfo getStreamInfo() throws IOException, InterruptedException {
|
||||
private StreamInfo getStreamInfo() throws IOException {
|
||||
return getStreamInfo(false);
|
||||
}
|
||||
|
||||
private StreamInfo getStreamInfo(boolean failFast) throws IOException, InterruptedException {
|
||||
if(failFast) {
|
||||
private StreamInfo getStreamInfo(boolean failFast) throws IOException {
|
||||
if (failFast) {
|
||||
return streamInfo;
|
||||
} else {
|
||||
return Optional.ofNullable(streamInfo).orElse(loadStreamInfo());
|
||||
|
@ -261,13 +256,8 @@ 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() + "/get_edge_hls_url_ajax/")
|
||||
.post(body)
|
||||
.url(getSite().getBaseUrl() + "/api/chatvideocontext/" + getName() + '/')
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
.build();
|
||||
|
@ -288,9 +278,10 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
|||
}
|
||||
}
|
||||
|
||||
private int[] getResolution() throws IOException, ParseException, PlaylistException, InterruptedException {
|
||||
private int[] getResolution() throws IOException, ParseException, PlaylistException {
|
||||
int[] res = new int[2];
|
||||
if(!getStreamInfo().url.startsWith("http")) {
|
||||
String url = Optional.ofNullable(getStreamInfo().hls_source).orElse("");
|
||||
if(!url.startsWith("http")) {
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -324,14 +315,14 @@ public class ChaturbateModel extends AbstractModel { // NOSONAR
|
|||
return res;
|
||||
}
|
||||
|
||||
public MasterPlaylist getMasterPlaylist() throws IOException, ParseException, PlaylistException, InterruptedException {
|
||||
public MasterPlaylist getMasterPlaylist() throws IOException, ParseException, PlaylistException {
|
||||
return getMasterPlaylist(getStreamInfo());
|
||||
}
|
||||
|
||||
private MasterPlaylist getMasterPlaylist(StreamInfo streamInfo) throws IOException, ParseException, PlaylistException {
|
||||
LOG.trace("Loading master playlist {}", streamInfo.url);
|
||||
LOG.trace("Loading master playlist {}", streamInfo.hls_source);
|
||||
Request req = new Request.Builder()
|
||||
.url(streamInfo.url)
|
||||
.url(streamInfo.hls_source)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response response = getSite().getHttpClient().execute(req)) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package ctbrec.sites.chaturbate;
|
||||
|
||||
public class StreamInfo {
|
||||
public String url;
|
||||
public String hls_source;
|
||||
public String room_status;
|
||||
public String hidden_message;
|
||||
public boolean success;
|
||||
|
|
Loading…
Reference in New Issue