Fix Cam4 stackvaults streams
This commit is contained in:
parent
4e5287c177
commit
dd67df7445
|
@ -1,40 +1,13 @@
|
|||
package ctbrec.sites.cam4;
|
||||
|
||||
import static ctbrec.Model.State.*;
|
||||
import static ctbrec.io.HttpClient.*;
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
import static java.util.regex.Pattern.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.iheartradio.m3u8.Encoding;
|
||||
import com.iheartradio.m3u8.Format;
|
||||
import com.iheartradio.m3u8.ParseException;
|
||||
import com.iheartradio.m3u8.ParsingMode;
|
||||
import com.iheartradio.m3u8.PlaylistException;
|
||||
import com.iheartradio.m3u8.PlaylistParser;
|
||||
import com.iheartradio.m3u8.*;
|
||||
import com.iheartradio.m3u8.data.MasterPlaylist;
|
||||
import com.iheartradio.m3u8.data.Playlist;
|
||||
import com.iheartradio.m3u8.data.PlaylistData;
|
||||
import com.iheartradio.m3u8.data.StreamInfo;
|
||||
|
||||
import ctbrec.AbstractModel;
|
||||
import ctbrec.Config;
|
||||
import ctbrec.NotImplementedExcetion;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.recorder.download.HttpHeaderFactory;
|
||||
|
@ -42,6 +15,22 @@ import ctbrec.recorder.download.HttpHeaderFactoryImpl;
|
|||
import ctbrec.recorder.download.StreamSource;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static ctbrec.Model.State.*;
|
||||
import static ctbrec.io.HttpClient.bodyToJsonObject;
|
||||
import static ctbrec.io.HttpConstants.*;
|
||||
import static java.util.regex.Pattern.DOTALL;
|
||||
import static java.util.regex.Pattern.MULTILINE;
|
||||
|
||||
public class Cam4Model extends AbstractModel {
|
||||
|
||||
|
@ -64,8 +53,8 @@ public class Cam4Model extends AbstractModel {
|
|||
}
|
||||
|
||||
private void loadModelDetails() throws IOException {
|
||||
JSONObject roomState = new Cam4WsClient(Config.getInstance(), (Cam4)getSite(), this).getRoomState();
|
||||
if(LOG.isTraceEnabled()) LOG.trace(roomState.toString(2));
|
||||
JSONObject roomState = new Cam4WsClient(Config.getInstance(), (Cam4) getSite(), this).getRoomState();
|
||||
if (LOG.isTraceEnabled()) LOG.trace(roomState.toString(2));
|
||||
String state = roomState.optString("newShowsState");
|
||||
setOnlineStateByShowType(state);
|
||||
privateRoom = roomState.optBoolean("privateRoom");
|
||||
|
@ -73,32 +62,17 @@ public class Cam4Model extends AbstractModel {
|
|||
}
|
||||
|
||||
public void setOnlineStateByShowType(String showType) {
|
||||
switch(showType) {
|
||||
case "NORMAL":
|
||||
case "ACCEPTING":
|
||||
case "GROUP_SHOW_SELLING_TICKETS":
|
||||
case "GS_SELLING_TICKETS":
|
||||
case "GS_SELLING_TICKETS_UNSUCCESSFUL":
|
||||
case "GS_GOAL_REACHED":
|
||||
onlineState = ONLINE;
|
||||
break;
|
||||
case "PRIVATE_SHOW":
|
||||
case "INSIDE_PS":
|
||||
onlineState = PRIVATE;
|
||||
break;
|
||||
case "INSIDE_GS":
|
||||
case "GROUP_SHOW":
|
||||
onlineState = GROUP;
|
||||
break;
|
||||
case "PAUSED":
|
||||
onlineState = AWAY;
|
||||
break;
|
||||
case "OFFLINE":
|
||||
onlineState = OFFLINE;
|
||||
break;
|
||||
default:
|
||||
LOG.debug("############################## Unknown show type [{} {}]", this, showType);
|
||||
onlineState = UNKNOWN;
|
||||
switch (showType) {
|
||||
case "NORMAL", "ACCEPTING", "GROUP_SHOW_SELLING_TICKETS", "GS_SELLING_TICKETS", "GS_SELLING_TICKETS_UNSUCCESSFUL", "GS_GOAL_REACHED" ->
|
||||
onlineState = ONLINE;
|
||||
case "PRIVATE_SHOW", "INSIDE_PS" -> onlineState = PRIVATE;
|
||||
case "INSIDE_GS", "GROUP_SHOW" -> onlineState = GROUP;
|
||||
case "PAUSED" -> onlineState = AWAY;
|
||||
case "OFFLINE" -> onlineState = OFFLINE;
|
||||
default -> {
|
||||
LOG.debug("############################## Unknown show type [{} {}]", this, showType);
|
||||
onlineState = UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -131,7 +105,7 @@ public class Cam4Model extends AbstractModel {
|
|||
}
|
||||
|
||||
private void getPlaylistUrlFromStreamUrl() throws IOException {
|
||||
String url = getSite().getBaseUrl() + "/_profile/streamURL?username=" + getName();
|
||||
String url = getSite().getBaseUrl() + "/rest/v1.0/profile/" + getName() + "/streamInfo";
|
||||
LOG.trace("Getting playlist url from {}", url);
|
||||
Request req = new Request.Builder() // @formatter:off
|
||||
.url(url)
|
||||
|
@ -228,23 +202,23 @@ public class Cam4Model extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public void receiveTip(Double tokens) throws IOException {
|
||||
throw new RuntimeException("Not implemented for Cam4, yet");
|
||||
throw new NotImplementedExcetion("Tipping is not implemented for Cam4, yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getStreamResolution(boolean failFast) throws ExecutionException {
|
||||
if(resolution == null) {
|
||||
if(failFast) {
|
||||
if (resolution == null) {
|
||||
if (failFast) {
|
||||
return new int[2];
|
||||
}
|
||||
try {
|
||||
if(!isOnline()) {
|
||||
if (!isOnline()) {
|
||||
return new int[2];
|
||||
}
|
||||
List<StreamSource> sources = getStreamSources();
|
||||
Collections.sort(sources);
|
||||
StreamSource best = sources.get(sources.size()-1);
|
||||
resolution = new int[] {best.width, best.height};
|
||||
StreamSource best = sources.get(sources.size() - 1);
|
||||
resolution = new int[]{best.width, best.height};
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
||||
|
@ -253,10 +227,8 @@ public class Cam4Model extends AbstractModel {
|
|||
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
||||
resolution = new int[2];
|
||||
}
|
||||
return resolution;
|
||||
} else {
|
||||
return resolution;
|
||||
}
|
||||
return resolution;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue