Move getSite and setSite to AbstractModel
This commit is contained in:
parent
6ef67b9385
commit
8fb5eac435
|
@ -8,6 +8,8 @@ import java.util.concurrent.ExecutionException;
|
|||
import com.squareup.moshi.JsonReader;
|
||||
import com.squareup.moshi.JsonWriter;
|
||||
|
||||
import ctbrec.sites.Site;
|
||||
|
||||
public abstract class AbstractModel implements Model {
|
||||
|
||||
private String url;
|
||||
|
@ -17,6 +19,7 @@ public abstract class AbstractModel implements Model {
|
|||
private List<String> tags = new ArrayList<>();
|
||||
private int streamUrlIndex = -1;
|
||||
private boolean suspended = false;
|
||||
protected Site site;
|
||||
|
||||
@Override
|
||||
public boolean isOnline() throws IOException, ExecutionException, InterruptedException {
|
||||
|
@ -139,4 +142,13 @@ public abstract class AbstractModel implements Model {
|
|||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSite(Site site) {
|
||||
this.site = site;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Site getSite() {
|
||||
return site;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import ctbrec.AbstractModel;
|
|||
import ctbrec.Config;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import ctbrec.sites.Site;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
|
@ -35,7 +34,6 @@ public class BongaCamsModel extends AbstractModel {
|
|||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(BongaCamsModel.class);
|
||||
|
||||
private BongaCams site;
|
||||
private int userId;
|
||||
private String onlineState = "n/a";
|
||||
private boolean online = false;
|
||||
|
@ -211,20 +209,6 @@ public class BongaCamsModel extends AbstractModel {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSite(Site site) {
|
||||
if(site instanceof BongaCams) {
|
||||
this.site = (BongaCams) site;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Site has to be an instance of BongaCams");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Site getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import ctbrec.Config;
|
|||
import ctbrec.io.HtmlParser;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import ctbrec.sites.Site;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
|
@ -36,7 +35,6 @@ import okhttp3.Response;
|
|||
public class Cam4Model extends AbstractModel {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(Cam4Model.class);
|
||||
private Cam4 site;
|
||||
private String playlistUrl;
|
||||
private String onlineState = "offline";
|
||||
private int[] resolution = null;
|
||||
|
@ -221,20 +219,6 @@ public class Cam4Model extends AbstractModel {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSite(Site site) {
|
||||
if(site instanceof Cam4) {
|
||||
this.site = (Cam4) site;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Site has to be an instance of Cam4");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Site getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
public void setPlaylistUrl(String playlistUrl) {
|
||||
this.playlistUrl = playlistUrl;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ import ctbrec.AbstractModel;
|
|||
import ctbrec.Config;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import ctbrec.sites.Site;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
|
@ -38,7 +37,6 @@ public class CamsodaModel extends AbstractModel {
|
|||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(CamsodaModel.class);
|
||||
private String streamUrl;
|
||||
private Site site;
|
||||
private List<StreamSource> streamSources = null;
|
||||
private String status = "n/a";
|
||||
private float sortOrder = 0;
|
||||
|
@ -242,20 +240,6 @@ public class CamsodaModel extends AbstractModel {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSite(Site site) {
|
||||
if(site instanceof Camsoda) {
|
||||
this.site = site;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Site has to be an instance of Camsoda");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Site getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
public void setStreamUrl(String streamUrl) {
|
||||
this.streamUrl = streamUrl;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import com.iheartradio.m3u8.data.PlaylistData;
|
|||
import ctbrec.AbstractModel;
|
||||
import ctbrec.Config;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import ctbrec.sites.Site;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
@ -27,7 +26,7 @@ import okhttp3.Response;
|
|||
public class ChaturbateModel extends AbstractModel {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(ChaturbateModel.class);
|
||||
private Chaturbate site;
|
||||
private Chaturbate chaturbate;
|
||||
|
||||
/**
|
||||
* This constructor exists only for deserialization. Please don't call it directly
|
||||
|
@ -37,30 +36,31 @@ public class ChaturbateModel extends AbstractModel {
|
|||
|
||||
ChaturbateModel(Chaturbate site) {
|
||||
this.site = site;
|
||||
this.chaturbate = site;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||
StreamInfo info;
|
||||
if(ignoreCache) {
|
||||
info = site.loadStreamInfo(getName());
|
||||
info = chaturbate.loadStreamInfo(getName());
|
||||
LOG.trace("Model {} room status: {}", getName(), info.room_status);
|
||||
} else {
|
||||
info = site.getStreamInfo(getName());
|
||||
info = chaturbate.getStreamInfo(getName());
|
||||
}
|
||||
return Objects.equals("public", info.room_status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getStreamResolution(boolean failFast) throws ExecutionException {
|
||||
int[] resolution = site.streamResolutionCache.getIfPresent(getName());
|
||||
int[] resolution = chaturbate.streamResolutionCache.getIfPresent(getName());
|
||||
if(resolution != null) {
|
||||
return site.getResolution(getName());
|
||||
return chaturbate.getResolution(getName());
|
||||
} else {
|
||||
if(failFast) {
|
||||
return new int[2];
|
||||
} else {
|
||||
return site.getResolution(getName());
|
||||
return chaturbate.getResolution(getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ public class ChaturbateModel extends AbstractModel {
|
|||
*/
|
||||
@Override
|
||||
public void invalidateCacheEntries() {
|
||||
site.streamInfoCache.invalidate(getName());
|
||||
site.streamResolutionCache.invalidate(getName());
|
||||
chaturbate.streamInfoCache.invalidate(getName());
|
||||
chaturbate.streamResolutionCache.invalidate(getName());
|
||||
}
|
||||
|
||||
public String getOnlineState() throws IOException, ExecutionException {
|
||||
|
@ -81,20 +81,20 @@ public class ChaturbateModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public String getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
||||
StreamInfo info = site.streamInfoCache.getIfPresent(getName());
|
||||
StreamInfo info = chaturbate.streamInfoCache.getIfPresent(getName());
|
||||
return info != null ? info.room_status : "n/a";
|
||||
}
|
||||
|
||||
public StreamInfo getStreamInfo() throws IOException, ExecutionException {
|
||||
return site.getStreamInfo(getName());
|
||||
return chaturbate.getStreamInfo(getName());
|
||||
}
|
||||
public MasterPlaylist getMasterPlaylist() throws IOException, ParseException, PlaylistException, ExecutionException {
|
||||
return site.getMasterPlaylist(getName());
|
||||
return chaturbate.getMasterPlaylist(getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveTip(int tokens) throws IOException {
|
||||
site.sendTip(getName(), tokens);
|
||||
chaturbate.sendTip(getName(), tokens);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -167,18 +167,4 @@ public class ChaturbateModel extends AbstractModel {
|
|||
throw new IOException("HTTP status " + resp.code() + " " + resp.message());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSite(Site site) {
|
||||
if(site instanceof Chaturbate) {
|
||||
this.site = (Chaturbate) site;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Site has to be an instance of Chaturbate");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Site getSite() {
|
||||
return site;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import ctbrec.AbstractModel;
|
|||
import ctbrec.io.HtmlParser;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.recorder.download.StreamSource;
|
||||
import ctbrec.sites.Site;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
|
@ -46,7 +45,6 @@ public class MyFreeCamsModel extends AbstractModel {
|
|||
private int viewerCount;
|
||||
private State state;
|
||||
private int resolution[];
|
||||
private MyFreeCams site;
|
||||
|
||||
/**
|
||||
* This constructor exists only for deserialization. Please don't call it directly
|
||||
|
@ -262,7 +260,7 @@ public class MyFreeCamsModel extends AbstractModel {
|
|||
int userChannel = 100000000 + state.getUid();
|
||||
int camserv = state.getU().getCamserv();
|
||||
String server = Integer.toString(camserv);
|
||||
ServerConfig sc = site.getClient().getServerConfig();
|
||||
ServerConfig sc = ((MyFreeCams)site).getClient().getServerConfig();
|
||||
if(sc.isOnNgServer(state)) {
|
||||
server = sc.ngVideoServers.get(Integer.toString(camserv));
|
||||
camserv = Integer.parseInt(server.replaceAll("[^0-9]+", ""));
|
||||
|
@ -284,12 +282,12 @@ public class MyFreeCamsModel extends AbstractModel {
|
|||
|
||||
@Override
|
||||
public boolean follow() {
|
||||
return site.getClient().follow(getUid());
|
||||
return ((MyFreeCams)site).getClient().follow(getUid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unfollow() {
|
||||
return site.getClient().unfollow(getUid());
|
||||
return ((MyFreeCams)site).getClient().unfollow(getUid());
|
||||
}
|
||||
|
||||
public int getUid() {
|
||||
|
@ -308,20 +306,6 @@ public class MyFreeCamsModel extends AbstractModel {
|
|||
this.viewerCount = viewerCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSite(Site site) {
|
||||
if(site instanceof MyFreeCams) {
|
||||
this.site = (MyFreeCams) site;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Site has to be an instance of MyFreeCams");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Site getSite() {
|
||||
return site;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
||||
reader.nextName();
|
||||
|
|
Loading…
Reference in New Issue