forked from j62/ctbrec
1
0
Fork 0

Remove Fc2WebSocketClient

This is now handled in Fc2Model
This commit is contained in:
0xboobface 2019-01-23 14:12:01 +01:00
parent 64c82748dc
commit 19afa9ce79
1 changed files with 0 additions and 85 deletions

View File

@ -1,85 +0,0 @@
package ctbrec.sites.fc2live;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ctbrec.Config;
import ctbrec.io.HttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okio.ByteString;
public class Fc2WebSocketClient {
private static final transient Logger LOG = LoggerFactory.getLogger(Fc2WebSocketClient.class);
private String url;
private HttpClient client;
public Fc2WebSocketClient(String url, HttpClient client) {
this.url = url;
this.client = client;
}
String playlistUrl = "";
public String getPlaylistUrl() throws InterruptedException {
LOG.debug("Connecting to {}", url);
Object monitor = new Object();
Request request = new Request.Builder()
.url(url)
.header("User-Agent", Config.getInstance().getSettings().httpUserAgent)
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.header("Accept-Language", "de,en-US;q=0.7,en;q=0.3")
.build();
client.newWebSocket(request, new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, Response response) {
response.close();
webSocket.send("{\"name\":\"get_hls_information\",\"arguments\":{},\"id\":1}");
}
@Override
public void onMessage(WebSocket webSocket, String text) {
JSONObject json = new JSONObject(text);
if(json.optString("name").equals("_response_") && json.optInt("id") == 1) {
LOG.debug(json.toString(2));
JSONObject args = json.getJSONObject("arguments");
JSONArray playlists = args.getJSONArray("playlists_high_latency");
JSONObject playlist = playlists.getJSONObject(0);
playlistUrl = playlist.getString("url");
synchronized (monitor) {
monitor.notify();
}
}
}
@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
LOG.debug("ws btxt {}", bytes.toString());
}
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
LOG.debug("ws closed {} - {}", code, reason);
}
@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
LOG.debug("ws failure", t);
response.close();
synchronized (monitor) {
monitor.notify();
}
}
});
synchronized (monitor) {
monitor.wait();
}
return playlistUrl;
}
}