saving the progress you mad on series by now
* added a function to save the progress you made watching a series * fixed a bug where refreshing the data element didn't work * added a searchCache methode to search if a film has been added to cach but the chace flag hasn't been set
This commit is contained in:
parent
913513a237
commit
94e32b938a
|
@ -475,7 +475,7 @@ public class MainWindowController {
|
|||
last = indexTable - 1;
|
||||
next = indexTable + 1;
|
||||
|
||||
if (currentTableFilm.getCached()) {
|
||||
if (currentTableFilm.getCached() || dbController.searchCache(getCurrentStreamUrl())) {
|
||||
LOGGER.info("loading from cache: " + getCurrentTitle());
|
||||
dbController.readCache(getCurrentStreamUrl());
|
||||
} else {
|
||||
|
@ -515,11 +515,15 @@ public class MainWindowController {
|
|||
|
||||
@FXML
|
||||
private void playbtnclicked() {
|
||||
if (currentTableFilm.getStreamUrl().contains("_rootNode")) {
|
||||
LOGGER.info("rootNode found, getting last watched episode");
|
||||
currentTableFilm = dbController.getLastWatchedEpisode(currentTableFilm.getTitle());
|
||||
}
|
||||
|
||||
if (isSupportedFormat(currentTableFilm)) {
|
||||
new Player(mainWindowController);
|
||||
} else {
|
||||
LOGGER.error("using fallback player!");
|
||||
|
||||
if (System.getProperty("os.name").contains("Linux")) {
|
||||
String line;
|
||||
String output = "";
|
||||
|
@ -558,7 +562,7 @@ public class MainWindowController {
|
|||
}
|
||||
}
|
||||
|
||||
/** TODO add all other supported mime types
|
||||
/**
|
||||
* check if a film is supported by the HomeFlixPlayer or not
|
||||
* this is the case if the mime type is mp4
|
||||
* @param entry the film you want to check
|
||||
|
@ -566,7 +570,7 @@ public class MainWindowController {
|
|||
*/
|
||||
private boolean isSupportedFormat(FilmTabelDataType film) {
|
||||
String mimeType = URLConnection.guessContentTypeFromName(film.getStreamUrl());
|
||||
return mimeType != null && mimeType.contains("mp4");
|
||||
return mimeType != null && (mimeType.contains("mp4") || mimeType.contains("vp6"));
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -694,21 +698,15 @@ public class MainWindowController {
|
|||
for (int i = 0; i < filmRoot.getChildren().size(); i++) {
|
||||
if (filmRoot.getChildren().get(i).getValue().getTitle().equals(element.getTitle())) {
|
||||
// if a root node exists, add element as child
|
||||
// System.out.println("Found a root node to add child");
|
||||
// System.out.println("Adding: " + element.getStreamUrl());
|
||||
TreeItem<FilmTabelDataType> episodeNode = new TreeItem<>(new FilmTabelDataType(
|
||||
element.getStreamUrl(), element.getTitle(), element.getSeason(), element.getEpisode(),
|
||||
element.getFavorite(), element.getCached(), element.getImage()));
|
||||
filmRoot.getChildren().get(i).getChildren().add(episodeNode);
|
||||
} else if (filmRoot.getChildren().get(i).nextSibling() == null) {
|
||||
// if no root node exists, create one and add element as child
|
||||
// System.out.println("Create a root node to add child");
|
||||
// System.out.println("Adding: " + element.getStreamUrl());
|
||||
// TODO set episode and season
|
||||
// FIXME if the streamUrl hasen't been cached we get an exception
|
||||
TreeItem<FilmTabelDataType> seriesRootNode = new TreeItem<>(new FilmTabelDataType(
|
||||
dbController.getLastWatchedEpisode(element.getTitle()),
|
||||
element.getTitle(), "", "", element.getFavorite(), element.getCached(), element.getImage()));
|
||||
element.getTitle() + "_rootNode", element.getTitle(), "", "", element.getFavorite(),
|
||||
false, element.getImage()));
|
||||
filmRoot.getChildren().add(seriesRootNode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -246,16 +246,17 @@ public class DBController {
|
|||
Statement stmt = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE streamUrl = \"" + streamUrl + "\";");
|
||||
|
||||
if (rs.getBoolean("favorite") == true) {
|
||||
mainWindowController.getFilmsList().set(indexList, new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getBoolean("cached"), new ImageView(favorite_black)));
|
||||
} else {
|
||||
mainWindowController.getFilmsList().set(indexList, new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getBoolean("cached"), new ImageView(favorite_border_black)));
|
||||
while (rs.next()) {
|
||||
if (rs.getBoolean("favorite") == true) {
|
||||
mainWindowController.getFilmsList().set(indexList, new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getBoolean("cached"), new ImageView(favorite_black)));
|
||||
} else {
|
||||
mainWindowController.getFilmsList().set(indexList, new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getBoolean("cached"), new ImageView(favorite_border_black)));
|
||||
}
|
||||
}
|
||||
|
||||
rs.close();
|
||||
stmt.close();
|
||||
} catch (Exception e) {
|
||||
|
@ -540,6 +541,21 @@ public class DBController {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean searchCache(String streamUrl) {
|
||||
boolean retValue = false;
|
||||
try {
|
||||
Statement stmt = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT * FROM cache WHERE streamUrl = \"" + streamUrl + "\";");
|
||||
retValue = rs.next();
|
||||
rs.close();
|
||||
stmt.close();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Ups! error while getting the current time!", e);
|
||||
}
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the cached data to mwc's TextFlow
|
||||
* @param streamUrl URL of the film
|
||||
|
@ -675,26 +691,50 @@ public class DBController {
|
|||
return nextFilm;
|
||||
}
|
||||
|
||||
|
||||
public String getLastWatchedEpisode(String title) {
|
||||
/**
|
||||
* get the last watched episode
|
||||
* @param title the title of the series
|
||||
* @return the last watched episode as {@link FilmTabelDataType} object
|
||||
*/
|
||||
public FilmTabelDataType getLastWatchedEpisode(String title) {
|
||||
LOGGER.info("last watched episode of: " + title);
|
||||
String lastEpisodeStreamUrl = "";
|
||||
double lastCurrentTime = -1;
|
||||
FilmTabelDataType nextFilm = null;
|
||||
double lastCurrentTime = 0;
|
||||
|
||||
try {
|
||||
Statement stmt = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE title = \"" + title + "\";");
|
||||
while (rs.next()) {
|
||||
if (rs.getBoolean("favorite") == true) {
|
||||
nextFilm = new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode") ,rs.getBoolean("favorite"),
|
||||
rs.getBoolean("cached"), new ImageView(favorite_black));
|
||||
} else {
|
||||
nextFilm = new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getBoolean("cached"), new ImageView(favorite_border_black));
|
||||
}
|
||||
if (rs.getDouble("currentTime") > lastCurrentTime) {
|
||||
lastCurrentTime = rs.getDouble("currentTime");
|
||||
lastEpisodeStreamUrl = rs.getString("streamUrl");
|
||||
if (rs.getBoolean("favorite") == true) {
|
||||
nextFilm = new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode") ,rs.getBoolean("favorite"),
|
||||
rs.getBoolean("cached"), new ImageView(favorite_black));
|
||||
} else {
|
||||
nextFilm = new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getBoolean("cached"), new ImageView(favorite_border_black));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Ups! error while getting the last watched episode!", e);
|
||||
}
|
||||
|
||||
return lastEpisodeStreamUrl;
|
||||
return nextFilm;
|
||||
}
|
||||
|
||||
// removes the ending
|
||||
|
|
Loading…
Reference in New Issue