From 4ac1bd457134f855ca03a2cd66f1544b30a582b8 Mon Sep 17 00:00:00 2001 From: 0xb00bface <0xboobface@gmail.com> Date: Sat, 21 Aug 2021 11:14:59 +0200 Subject: [PATCH] Revert "Use a different URL to fetch the stream info for Chaturbate" This reverts commit 9c8fe1f89c64f7148fa66723cc6c65a449e11f21. --- .../sites/chaturbate/ChaturbateModel.java | 65 +++++++++++-------- .../ctbrec/sites/chaturbate/StreamInfo.java | 2 +- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java b/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java index 611f75ca..ba19cc1c 100644 --- a/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java +++ b/common/src/main/java/ctbrec/sites/chaturbate/ChaturbateModel.java @@ -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 getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException { - streamInfo = loadStreamInfo(); - MasterPlaylist masterPlaylist = getMasterPlaylist(); - List 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 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)) { diff --git a/common/src/main/java/ctbrec/sites/chaturbate/StreamInfo.java b/common/src/main/java/ctbrec/sites/chaturbate/StreamInfo.java index cec16f98..285ea6c2 100644 --- a/common/src/main/java/ctbrec/sites/chaturbate/StreamInfo.java +++ b/common/src/main/java/ctbrec/sites/chaturbate/StreamInfo.java @@ -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;