forked from j62/ctbrec
Merge branch 'dev' into fc2
# Conflicts: # common/src/main/java/ctbrec/sites/jasmin/LiveJasminHttpClient.java
This commit is contained in:
commit
16752b892c
|
@ -17,13 +17,16 @@ import java.util.concurrent.TimeUnit;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.squareup.moshi.JsonAdapter;
|
import com.squareup.moshi.JsonAdapter;
|
||||||
import com.squareup.moshi.Moshi;
|
import com.squareup.moshi.Moshi;
|
||||||
import com.squareup.moshi.Types;
|
import com.squareup.moshi.Types;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
|
import ctbrec.Model;
|
||||||
import ctbrec.StringUtil;
|
import ctbrec.StringUtil;
|
||||||
import ctbrec.Version;
|
import ctbrec.Version;
|
||||||
|
import ctbrec.event.Event;
|
||||||
import ctbrec.event.EventBusHolder;
|
import ctbrec.event.EventBusHolder;
|
||||||
import ctbrec.event.EventHandler;
|
import ctbrec.event.EventHandler;
|
||||||
import ctbrec.event.EventHandlerConfiguration;
|
import ctbrec.event.EventHandlerConfiguration;
|
||||||
|
@ -70,9 +73,11 @@ public class CamrecApplication extends Application {
|
||||||
private List<Site> sites = new ArrayList<>();
|
private List<Site> sites = new ArrayList<>();
|
||||||
public static HttpClient httpClient;
|
public static HttpClient httpClient;
|
||||||
public static String title;
|
public static String title;
|
||||||
|
private Stage primaryStage;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws Exception {
|
public void start(Stage primaryStage) throws Exception {
|
||||||
|
this.primaryStage = primaryStage;
|
||||||
logEnvironment();
|
logEnvironment();
|
||||||
sites.add(new BongaCams());
|
sites.add(new BongaCams());
|
||||||
sites.add(new Cam4());
|
sites.add(new Cam4());
|
||||||
|
@ -84,6 +89,7 @@ public class CamrecApplication extends Application {
|
||||||
sites.add(new Streamate());
|
sites.add(new Streamate());
|
||||||
loadConfig();
|
loadConfig();
|
||||||
registerAlertSystem();
|
registerAlertSystem();
|
||||||
|
registerActiveRecordingsCounter();
|
||||||
createHttpClient();
|
createHttpClient();
|
||||||
hostServices = getHostServices();
|
hostServices = getHostServices();
|
||||||
createRecorder();
|
createRecorder();
|
||||||
|
@ -240,6 +246,24 @@ public class CamrecApplication extends Application {
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerActiveRecordingsCounter() {
|
||||||
|
EventBusHolder.BUS.register(new Object() {
|
||||||
|
@Subscribe
|
||||||
|
public void handleEvent(Event evt) {
|
||||||
|
if(evt.getType() == Event.Type.MODEL_STATUS_CHANGED || evt.getType() == Event.Type.RECORDING_STATUS_CHANGED) {
|
||||||
|
try {
|
||||||
|
List<Model> models = recorder.getOnlineModels();
|
||||||
|
long count = models.stream().filter(m -> !recorder.isSuspended(m)).count();
|
||||||
|
String _title = count > 0 ? "(" + count + ") " + title : title;
|
||||||
|
Platform.runLater(() -> primaryStage.setTitle(_title));
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Couldn't update window title", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void writeColorSchemeStyleSheet(Stage primaryStage) {
|
private void writeColorSchemeStyleSheet(Stage primaryStage) {
|
||||||
File colorCss = new File(Config.getInstance().getConfigDir(), "color.css");
|
File colorCss = new File(Config.getInstance().getConfigDir(), "color.css");
|
||||||
try(FileOutputStream fos = new FileOutputStream(colorCss)) {
|
try(FileOutputStream fos = new FileOutputStream(colorCss)) {
|
||||||
|
|
|
@ -38,6 +38,10 @@ public class LiveJasminFollowedUpdateService extends PaginatedScheduledService {
|
||||||
return new Task<List<Model>>() {
|
return new Task<List<Model>>() {
|
||||||
@Override
|
@Override
|
||||||
public List<Model> call() throws IOException {
|
public List<Model> call() throws IOException {
|
||||||
|
if(!liveJasmin.credentialsAvailable()) {
|
||||||
|
throw new RuntimeException("Credentials missing");
|
||||||
|
}
|
||||||
|
|
||||||
boolean loggedIn = SiteUiFactory.getUi(liveJasmin).login();
|
boolean loggedIn = SiteUiFactory.getUi(liveJasmin).login();
|
||||||
if(!loggedIn) {
|
if(!loggedIn) {
|
||||||
throw new RuntimeException("Couldn't login to livejasmin");
|
throw new RuntimeException("Couldn't login to livejasmin");
|
||||||
|
|
|
@ -33,6 +33,7 @@ public class Config {
|
||||||
private String filename;
|
private String filename;
|
||||||
private List<Site> sites;
|
private List<Site> sites;
|
||||||
private File configDir;
|
private File configDir;
|
||||||
|
public static final String RECORDING_DATE_FORMAT = "yyyy-MM-dd_HH-mm-ss_SSS";
|
||||||
|
|
||||||
private Config(List<Site> sites) throws FileNotFoundException, IOException {
|
private Config(List<Site> sites) throws FileNotFoundException, IOException {
|
||||||
this.sites = sites;
|
this.sites = sites;
|
||||||
|
@ -134,7 +135,7 @@ public class Config {
|
||||||
|
|
||||||
public File getFileForRecording(Model model) {
|
public File getFileForRecording(Model model) {
|
||||||
File dirForRecording = getDirForRecording(model);
|
File dirForRecording = getDirForRecording(model);
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
SimpleDateFormat sdf = new SimpleDateFormat(RECORDING_DATE_FORMAT);
|
||||||
String startTime = sdf.format(new Date());
|
String startTime = sdf.format(new Date());
|
||||||
File targetFile = new File(dirForRecording, model.getName() + '_' + startTime + ".ts");
|
File targetFile = new File(dirForRecording, model.getName() + '_' + startTime + ".ts");
|
||||||
return targetFile;
|
return targetFile;
|
||||||
|
@ -146,7 +147,7 @@ public class Config {
|
||||||
return new File(getSettings().recordingsDir, model.getName());
|
return new File(getSettings().recordingsDir, model.getName());
|
||||||
case ONE_PER_RECORDING:
|
case ONE_PER_RECORDING:
|
||||||
File modelDir = new File(getSettings().recordingsDir, model.getName());
|
File modelDir = new File(getSettings().recordingsDir, model.getName());
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
SimpleDateFormat sdf = new SimpleDateFormat(RECORDING_DATE_FORMAT);
|
||||||
String startTime = sdf.format(new Date());
|
String startTime = sdf.format(new Date());
|
||||||
return new File(modelDir, startTime);
|
return new File(modelDir, startTime);
|
||||||
case FLAT:
|
case FLAT:
|
||||||
|
|
|
@ -66,7 +66,6 @@ public class LocalRecorder implements Recorder {
|
||||||
|
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(LocalRecorder.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(LocalRecorder.class);
|
||||||
private static final boolean IGNORE_CACHE = true;
|
private static final boolean IGNORE_CACHE = true;
|
||||||
private static final String DATE_FORMAT = "yyyy-MM-dd_HH-mm";
|
|
||||||
|
|
||||||
private List<Model> models = Collections.synchronizedList(new ArrayList<>());
|
private List<Model> models = Collections.synchronizedList(new ArrayList<>());
|
||||||
private Map<Model, Download> recordingProcesses = Collections.synchronizedMap(new HashMap<>());
|
private Map<Model, Download> recordingProcesses = Collections.synchronizedMap(new HashMap<>());
|
||||||
|
@ -466,17 +465,17 @@ public class LocalRecorder implements Recorder {
|
||||||
private List<Recording> listMergedRecordings() {
|
private List<Recording> listMergedRecordings() {
|
||||||
File recordingsDir = new File(config.getSettings().recordingsDir);
|
File recordingsDir = new File(config.getSettings().recordingsDir);
|
||||||
List<File> possibleRecordings = new LinkedList<>();
|
List<File> possibleRecordings = new LinkedList<>();
|
||||||
listRecursively(recordingsDir, possibleRecordings, (dir, name) -> name.matches(".*?_\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}\\.(ts|mp4)"));
|
listRecursively(recordingsDir, possibleRecordings, (dir, name) -> name.matches(".*?_\\d{4}-\\d{2}-\\d{2}_\\d{2}-\\d{2}-\\d{2}_\\d{3}\\.(ts|mp4)"));
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
|
SimpleDateFormat sdf = new SimpleDateFormat(Config.RECORDING_DATE_FORMAT);
|
||||||
List<Recording> recordings = new ArrayList<>();
|
List<Recording> recordings = new ArrayList<>();
|
||||||
for (File ts: possibleRecordings) {
|
for (File ts: possibleRecordings) {
|
||||||
try {
|
try {
|
||||||
String filename = ts.getName();
|
String filename = ts.getName();
|
||||||
int extLength = filename.length() - filename.lastIndexOf('.');
|
int extLength = filename.length() - filename.lastIndexOf('.');
|
||||||
String dateString = filename.substring(filename.length() - extLength - DATE_FORMAT.length(), filename.length() - extLength);
|
String dateString = filename.substring(filename.length() - extLength - Config.RECORDING_DATE_FORMAT.length(), filename.length() - extLength);
|
||||||
Date startDate = sdf.parse(dateString);
|
Date startDate = sdf.parse(dateString);
|
||||||
Recording recording = new Recording();
|
Recording recording = new Recording();
|
||||||
recording.setModelName(filename.substring(0, filename.length() - extLength - 1 - DATE_FORMAT.length()));
|
recording.setModelName(filename.substring(0, filename.length() - extLength - 1 - Config.RECORDING_DATE_FORMAT.length()));
|
||||||
recording.setStartDate(Instant.ofEpochMilli(startDate.getTime()));
|
recording.setStartDate(Instant.ofEpochMilli(startDate.getTime()));
|
||||||
String path = ts.getAbsolutePath().replace(config.getSettings().recordingsDir, "");
|
String path = ts.getAbsolutePath().replace(config.getSettings().recordingsDir, "");
|
||||||
if(!path.startsWith("/")) {
|
if(!path.startsWith("/")) {
|
||||||
|
@ -541,11 +540,11 @@ public class LocalRecorder implements Recorder {
|
||||||
|
|
||||||
// start going over valid directories
|
// start going over valid directories
|
||||||
for (File rec : recordingsDirs) {
|
for (File rec : recordingsDirs) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
|
SimpleDateFormat sdf = new SimpleDateFormat(Config.RECORDING_DATE_FORMAT);
|
||||||
if (rec.isDirectory()) {
|
if (rec.isDirectory()) {
|
||||||
try {
|
try {
|
||||||
// ignore directories, which are probably not created by ctbrec
|
// ignore directories, which are probably not created by ctbrec
|
||||||
if (rec.getName().length() != DATE_FORMAT.length()) {
|
if (rec.getName().length() != Config.RECORDING_DATE_FORMAT.length()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// ignore empty directories
|
// ignore empty directories
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class HlsDownload extends AbstractHlsDownload {
|
||||||
running = true;
|
running = true;
|
||||||
startTime = Instant.now();
|
startTime = Instant.now();
|
||||||
super.model = model;
|
super.model = model;
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm");
|
SimpleDateFormat sdf = new SimpleDateFormat(Config.RECORDING_DATE_FORMAT);
|
||||||
String startTime = sdf.format(new Date());
|
String startTime = sdf.format(new Date());
|
||||||
Path modelDir = FileSystems.getDefault().getPath(config.getSettings().recordingsDir, model.getName());
|
Path modelDir = FileSystems.getDefault().getPath(config.getSettings().recordingsDir, model.getName());
|
||||||
downloadDir = FileSystems.getDefault().getPath(modelDir.toString(), startTime);
|
downloadDir = FileSystems.getDefault().getPath(modelDir.toString(), startTime);
|
||||||
|
|
|
@ -21,16 +21,10 @@ public class LiveJasminHttpClient extends HttpClient {
|
||||||
protected LiveJasminHttpClient() {
|
protected LiveJasminHttpClient() {
|
||||||
super("livejasmin");
|
super("livejasmin");
|
||||||
|
|
||||||
// delete session, if we are guests, because old guest sessions cause
|
// delete all cookies, if we are guests, because old guest sessions cause
|
||||||
// endless redirects
|
// endless redirects
|
||||||
if(Config.getInstance().getSettings().livejasminUsername.isEmpty()) {
|
if(Config.getInstance().getSettings().livejasminUsername.isEmpty()) {
|
||||||
HttpUrl url = HttpUrl.parse("https://" + LiveJasmin.baseDomain);
|
getCookieJar().clear();
|
||||||
try {
|
|
||||||
getCookieJar().deleteCookie(url, "session");
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
LOG.debug("Session cookie not found -> let's go!");
|
|
||||||
// fine, no session cookie means we are good to go
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue