forked from j62/ctbrec
Let SiteUi launch the player for a model stream
This is done, because there might be some special conditions for the player to work. For example on fc2live a websocket has to be open while the player is running. The SiteUI can handle these cases transparently.
This commit is contained in:
parent
55fc6729f8
commit
3a83943130
|
@ -24,6 +24,10 @@ public class Player {
|
||||||
private static PlayerThread playerThread;
|
private static PlayerThread playerThread;
|
||||||
|
|
||||||
public static boolean play(String url) {
|
public static boolean play(String url) {
|
||||||
|
return play(url, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean play(String url, boolean async) {
|
||||||
boolean singlePlayer = Config.getInstance().getSettings().singlePlayer;
|
boolean singlePlayer = Config.getInstance().getSettings().singlePlayer;
|
||||||
try {
|
try {
|
||||||
if (singlePlayer && playerThread != null && playerThread.isRunning()) {
|
if (singlePlayer && playerThread != null && playerThread.isRunning()) {
|
||||||
|
@ -31,6 +35,9 @@ public class Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
playerThread = new PlayerThread(url);
|
playerThread = new PlayerThread(url);
|
||||||
|
if(!async) {
|
||||||
|
playerThread.join();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
LOG.error("Couldn't start player", e1);
|
LOG.error("Couldn't start player", e1);
|
||||||
|
@ -54,6 +61,10 @@ public class Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean play(Model model) {
|
public static boolean play(Model model) {
|
||||||
|
return play(model, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean play(Model model, boolean async) {
|
||||||
try {
|
try {
|
||||||
if(model.isOnline(true)) {
|
if(model.isOnline(true)) {
|
||||||
boolean singlePlayer = Config.getInstance().getSettings().singlePlayer;
|
boolean singlePlayer = Config.getInstance().getSettings().singlePlayer;
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ctbrec.ui;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import ctbrec.Model;
|
||||||
import ctbrec.sites.ConfigUI;
|
import ctbrec.sites.ConfigUI;
|
||||||
|
|
||||||
public interface SiteUI {
|
public interface SiteUI {
|
||||||
|
@ -9,4 +10,5 @@ public interface SiteUI {
|
||||||
public TabProvider getTabProvider();
|
public TabProvider getTabProvider();
|
||||||
public ConfigUI getConfigUI();
|
public ConfigUI getConfigUI();
|
||||||
public boolean login() throws IOException;
|
public boolean login() throws IOException;
|
||||||
|
public boolean play(Model model);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import ctbrec.ui.sites.bonga.BongaCamsSiteUi;
|
||||||
import ctbrec.ui.sites.cam4.Cam4SiteUi;
|
import ctbrec.ui.sites.cam4.Cam4SiteUi;
|
||||||
import ctbrec.ui.sites.camsoda.CamsodaSiteUi;
|
import ctbrec.ui.sites.camsoda.CamsodaSiteUi;
|
||||||
import ctbrec.ui.sites.chaturbate.ChaturbateSiteUi;
|
import ctbrec.ui.sites.chaturbate.ChaturbateSiteUi;
|
||||||
import ctbrec.ui.sites.fc2live.Fc2LiveUi;
|
import ctbrec.ui.sites.fc2live.Fc2LiveSiteUi;
|
||||||
import ctbrec.ui.sites.jasmin.LiveJasminSiteUi;
|
import ctbrec.ui.sites.jasmin.LiveJasminSiteUi;
|
||||||
import ctbrec.ui.sites.myfreecams.MyFreeCamsSiteUi;
|
import ctbrec.ui.sites.myfreecams.MyFreeCamsSiteUi;
|
||||||
import ctbrec.ui.sites.streamate.StreamateSiteUi;
|
import ctbrec.ui.sites.streamate.StreamateSiteUi;
|
||||||
|
@ -24,7 +24,7 @@ public class SiteUiFactory {
|
||||||
private static Cam4SiteUi cam4SiteUi;
|
private static Cam4SiteUi cam4SiteUi;
|
||||||
private static CamsodaSiteUi camsodaSiteUi;
|
private static CamsodaSiteUi camsodaSiteUi;
|
||||||
private static ChaturbateSiteUi ctbSiteUi;
|
private static ChaturbateSiteUi ctbSiteUi;
|
||||||
private static Fc2LiveUi fc2SiteUi;
|
private static Fc2LiveSiteUi fc2SiteUi;
|
||||||
private static LiveJasminSiteUi jasminSiteUi;
|
private static LiveJasminSiteUi jasminSiteUi;
|
||||||
private static MyFreeCamsSiteUi mfcSiteUi;
|
private static MyFreeCamsSiteUi mfcSiteUi;
|
||||||
private static StreamateSiteUi streamateSiteUi;
|
private static StreamateSiteUi streamateSiteUi;
|
||||||
|
@ -52,7 +52,7 @@ public class SiteUiFactory {
|
||||||
return ctbSiteUi;
|
return ctbSiteUi;
|
||||||
} else if (site instanceof Fc2Live) {
|
} else if (site instanceof Fc2Live) {
|
||||||
if (fc2SiteUi == null) {
|
if (fc2SiteUi == null) {
|
||||||
fc2SiteUi = new Fc2LiveUi((Fc2Live) site);
|
fc2SiteUi = new Fc2LiveSiteUi((Fc2Live) site);
|
||||||
}
|
}
|
||||||
return fc2SiteUi;
|
return fc2SiteUi;
|
||||||
} else if (site instanceof MyFreeCams) {
|
} else if (site instanceof MyFreeCams) {
|
||||||
|
|
|
@ -2,7 +2,8 @@ package ctbrec.ui.action;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.ui.Player;
|
import ctbrec.ui.SiteUI;
|
||||||
|
import ctbrec.ui.SiteUiFactory;
|
||||||
import ctbrec.ui.controls.Toast;
|
import ctbrec.ui.controls.Toast;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.scene.Cursor;
|
import javafx.scene.Cursor;
|
||||||
|
@ -21,7 +22,8 @@ public class PlayAction {
|
||||||
public void execute() {
|
public void execute() {
|
||||||
source.setCursor(Cursor.WAIT);
|
source.setCursor(Cursor.WAIT);
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
boolean started = Player.play(selectedModel);
|
SiteUI siteUI = SiteUiFactory.getUi(selectedModel.getSite());
|
||||||
|
boolean started = siteUI.play(selectedModel);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
if (started && Config.getInstance().getSettings().showPlayerStarting) {
|
if (started && Config.getInstance().getSettings().showPlayerStarting) {
|
||||||
Toast.makeText(source.getScene(), "Starting Player", 2000, 500, 500);
|
Toast.makeText(source.getScene(), "Starting Player", 2000, 500, 500);
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package ctbrec.ui.sites;
|
||||||
|
|
||||||
|
import ctbrec.Model;
|
||||||
|
import ctbrec.ui.Player;
|
||||||
|
import ctbrec.ui.SiteUI;
|
||||||
|
|
||||||
|
public abstract class AbstractSiteUi implements SiteUI {
|
||||||
|
@Override
|
||||||
|
public boolean play(Model model) {
|
||||||
|
return Player.play(model);
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,11 +10,11 @@ import org.slf4j.LoggerFactory;
|
||||||
import ctbrec.sites.ConfigUI;
|
import ctbrec.sites.ConfigUI;
|
||||||
import ctbrec.sites.bonga.BongaCams;
|
import ctbrec.sites.bonga.BongaCams;
|
||||||
import ctbrec.sites.bonga.BongaCamsHttpClient;
|
import ctbrec.sites.bonga.BongaCamsHttpClient;
|
||||||
import ctbrec.ui.SiteUI;
|
|
||||||
import ctbrec.ui.TabProvider;
|
import ctbrec.ui.TabProvider;
|
||||||
import ctbrec.ui.controls.Dialogs;
|
import ctbrec.ui.controls.Dialogs;
|
||||||
|
import ctbrec.ui.sites.AbstractSiteUi;
|
||||||
|
|
||||||
public class BongaCamsSiteUi implements SiteUI {
|
public class BongaCamsSiteUi extends AbstractSiteUi {
|
||||||
|
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(BongaCamsSiteUi.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(BongaCamsSiteUi.class);
|
||||||
private BongaCamsTabProvider tabProvider;
|
private BongaCamsTabProvider tabProvider;
|
||||||
|
|
|
@ -10,12 +10,12 @@ import org.slf4j.LoggerFactory;
|
||||||
import ctbrec.sites.ConfigUI;
|
import ctbrec.sites.ConfigUI;
|
||||||
import ctbrec.sites.cam4.Cam4;
|
import ctbrec.sites.cam4.Cam4;
|
||||||
import ctbrec.sites.cam4.Cam4HttpClient;
|
import ctbrec.sites.cam4.Cam4HttpClient;
|
||||||
import ctbrec.ui.SiteUI;
|
|
||||||
import ctbrec.ui.TabProvider;
|
import ctbrec.ui.TabProvider;
|
||||||
import ctbrec.ui.controls.Dialogs;
|
import ctbrec.ui.controls.Dialogs;
|
||||||
|
import ctbrec.ui.sites.AbstractSiteUi;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
|
||||||
public class Cam4SiteUi implements SiteUI {
|
public class Cam4SiteUi extends AbstractSiteUi {
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(Cam4SiteUi.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(Cam4SiteUi.class);
|
||||||
|
|
||||||
private Cam4TabProvider tabProvider;
|
private Cam4TabProvider tabProvider;
|
||||||
|
|
|
@ -7,10 +7,10 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.sites.ConfigUI;
|
import ctbrec.sites.ConfigUI;
|
||||||
import ctbrec.sites.camsoda.Camsoda;
|
import ctbrec.sites.camsoda.Camsoda;
|
||||||
import ctbrec.ui.SiteUI;
|
|
||||||
import ctbrec.ui.TabProvider;
|
import ctbrec.ui.TabProvider;
|
||||||
|
import ctbrec.ui.sites.AbstractSiteUi;
|
||||||
|
|
||||||
public class CamsodaSiteUi implements SiteUI {
|
public class CamsodaSiteUi extends AbstractSiteUi {
|
||||||
|
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(CamsodaSiteUi.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(CamsodaSiteUi.class);
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,10 @@ import java.io.IOException;
|
||||||
|
|
||||||
import ctbrec.sites.ConfigUI;
|
import ctbrec.sites.ConfigUI;
|
||||||
import ctbrec.sites.chaturbate.Chaturbate;
|
import ctbrec.sites.chaturbate.Chaturbate;
|
||||||
import ctbrec.ui.SiteUI;
|
|
||||||
import ctbrec.ui.TabProvider;
|
import ctbrec.ui.TabProvider;
|
||||||
|
import ctbrec.ui.sites.AbstractSiteUi;
|
||||||
|
|
||||||
public class ChaturbateSiteUi implements SiteUI {
|
public class ChaturbateSiteUi extends AbstractSiteUi {
|
||||||
|
|
||||||
private ChaturbateTabProvider tabProvider;
|
private ChaturbateTabProvider tabProvider;
|
||||||
private ChaturbateConfigUi configUi;
|
private ChaturbateConfigUi configUi;
|
||||||
|
|
|
@ -2,17 +2,19 @@ package ctbrec.ui.sites.fc2live;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import ctbrec.Model;
|
||||||
import ctbrec.sites.ConfigUI;
|
import ctbrec.sites.ConfigUI;
|
||||||
import ctbrec.sites.fc2live.Fc2Live;
|
import ctbrec.sites.fc2live.Fc2Live;
|
||||||
import ctbrec.ui.SiteUI;
|
import ctbrec.ui.Player;
|
||||||
import ctbrec.ui.TabProvider;
|
import ctbrec.ui.TabProvider;
|
||||||
|
import ctbrec.ui.sites.AbstractSiteUi;
|
||||||
|
|
||||||
public class Fc2LiveUi implements SiteUI {
|
public class Fc2LiveSiteUi extends AbstractSiteUi {
|
||||||
|
|
||||||
private Fc2Live fc2live;
|
private Fc2Live fc2live;
|
||||||
private Fc2TabProvider tabProvider;
|
private Fc2TabProvider tabProvider;
|
||||||
|
|
||||||
public Fc2LiveUi(Fc2Live fc2live) {
|
public Fc2LiveSiteUi(Fc2Live fc2live) {
|
||||||
this.fc2live = fc2live;
|
this.fc2live = fc2live;
|
||||||
this.tabProvider = new Fc2TabProvider(fc2live);
|
this.tabProvider = new Fc2TabProvider(fc2live);
|
||||||
}
|
}
|
||||||
|
@ -32,4 +34,15 @@ public class Fc2LiveUi implements SiteUI {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean play(Model model) {
|
||||||
|
new Thread(() -> {
|
||||||
|
// create websocket
|
||||||
|
|
||||||
|
Player.play(model, false);
|
||||||
|
|
||||||
|
// close websocket
|
||||||
|
}).start();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -11,11 +11,11 @@ import org.slf4j.LoggerFactory;
|
||||||
import ctbrec.sites.ConfigUI;
|
import ctbrec.sites.ConfigUI;
|
||||||
import ctbrec.sites.jasmin.LiveJasmin;
|
import ctbrec.sites.jasmin.LiveJasmin;
|
||||||
import ctbrec.sites.jasmin.LiveJasminHttpClient;
|
import ctbrec.sites.jasmin.LiveJasminHttpClient;
|
||||||
import ctbrec.ui.SiteUI;
|
|
||||||
import ctbrec.ui.TabProvider;
|
import ctbrec.ui.TabProvider;
|
||||||
import ctbrec.ui.controls.Dialogs;
|
import ctbrec.ui.controls.Dialogs;
|
||||||
|
import ctbrec.ui.sites.AbstractSiteUi;
|
||||||
|
|
||||||
public class LiveJasminSiteUi implements SiteUI {
|
public class LiveJasminSiteUi extends AbstractSiteUi {
|
||||||
|
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(LiveJasminSiteUi.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(LiveJasminSiteUi.class);
|
||||||
private LiveJasmin liveJasmin;
|
private LiveJasmin liveJasmin;
|
||||||
|
|
|
@ -4,10 +4,10 @@ import java.io.IOException;
|
||||||
|
|
||||||
import ctbrec.sites.ConfigUI;
|
import ctbrec.sites.ConfigUI;
|
||||||
import ctbrec.sites.mfc.MyFreeCams;
|
import ctbrec.sites.mfc.MyFreeCams;
|
||||||
import ctbrec.ui.SiteUI;
|
|
||||||
import ctbrec.ui.TabProvider;
|
import ctbrec.ui.TabProvider;
|
||||||
|
import ctbrec.ui.sites.AbstractSiteUi;
|
||||||
|
|
||||||
public class MyFreeCamsSiteUi implements SiteUI {
|
public class MyFreeCamsSiteUi extends AbstractSiteUi {
|
||||||
|
|
||||||
private MyFreeCamsTabProvider tabProvider;
|
private MyFreeCamsTabProvider tabProvider;
|
||||||
private MyFreeCamsConfigUI configUi;
|
private MyFreeCamsConfigUI configUi;
|
||||||
|
|
|
@ -4,10 +4,10 @@ import java.io.IOException;
|
||||||
|
|
||||||
import ctbrec.sites.ConfigUI;
|
import ctbrec.sites.ConfigUI;
|
||||||
import ctbrec.sites.streamate.Streamate;
|
import ctbrec.sites.streamate.Streamate;
|
||||||
import ctbrec.ui.SiteUI;
|
|
||||||
import ctbrec.ui.TabProvider;
|
import ctbrec.ui.TabProvider;
|
||||||
|
import ctbrec.ui.sites.AbstractSiteUi;
|
||||||
|
|
||||||
public class StreamateSiteUi implements SiteUI {
|
public class StreamateSiteUi extends AbstractSiteUi {
|
||||||
|
|
||||||
private StreamateTabProvider tabProvider;
|
private StreamateTabProvider tabProvider;
|
||||||
private StreamateConfigUI configUi;
|
private StreamateConfigUI configUi;
|
||||||
|
|
Loading…
Reference in New Issue