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,10 +475,10 @@ public class MainWindowController {
|
||||||
last = indexTable - 1;
|
last = indexTable - 1;
|
||||||
next = indexTable + 1;
|
next = indexTable + 1;
|
||||||
|
|
||||||
if (currentTableFilm.getCached()) {
|
if (currentTableFilm.getCached() || dbController.searchCache(getCurrentStreamUrl())) {
|
||||||
LOGGER.info("loading from cache: " + getCurrentTitle());
|
LOGGER.info("loading from cache: " + getCurrentTitle());
|
||||||
dbController.readCache(getCurrentStreamUrl());
|
dbController.readCache(getCurrentStreamUrl());
|
||||||
} else {
|
} else {
|
||||||
omdbAPIController = new OMDbAPIController(mainWindowController, dbController, main);
|
omdbAPIController = new OMDbAPIController(mainWindowController, dbController, main);
|
||||||
Thread omdbAPIThread = new Thread(omdbAPIController);
|
Thread omdbAPIThread = new Thread(omdbAPIController);
|
||||||
omdbAPIThread.setName("OMDbAPI");
|
omdbAPIThread.setName("OMDbAPI");
|
||||||
|
@ -514,12 +514,16 @@ public class MainWindowController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void playbtnclicked() {
|
private void playbtnclicked() {
|
||||||
|
if (currentTableFilm.getStreamUrl().contains("_rootNode")) {
|
||||||
|
LOGGER.info("rootNode found, getting last watched episode");
|
||||||
|
currentTableFilm = dbController.getLastWatchedEpisode(currentTableFilm.getTitle());
|
||||||
|
}
|
||||||
|
|
||||||
if (isSupportedFormat(currentTableFilm)) {
|
if (isSupportedFormat(currentTableFilm)) {
|
||||||
new Player(mainWindowController);
|
new Player(mainWindowController);
|
||||||
} else {
|
} else {
|
||||||
LOGGER.error("using fallback player!");
|
LOGGER.error("using fallback player!");
|
||||||
|
|
||||||
if (System.getProperty("os.name").contains("Linux")) {
|
if (System.getProperty("os.name").contains("Linux")) {
|
||||||
String line;
|
String line;
|
||||||
String output = "";
|
String output = "";
|
||||||
|
@ -558,15 +562,15 @@ public class MainWindowController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** TODO add all other supported mime types
|
/**
|
||||||
* check if a film is supported by the HomeFlixPlayer or not
|
* check if a film is supported by the HomeFlixPlayer or not
|
||||||
* this is the case if the mime type is mp4
|
* this is the case if the mime type is mp4
|
||||||
* @param entry the film you want to check
|
* @param entry the film you want to check
|
||||||
* @return true if so, false if not
|
* @return true if so, false if not
|
||||||
*/
|
*/
|
||||||
private boolean isSupportedFormat(FilmTabelDataType film) {
|
private boolean isSupportedFormat(FilmTabelDataType film) {
|
||||||
String mimeType = URLConnection.guessContentTypeFromName(film.getStreamUrl());
|
String mimeType = URLConnection.guessContentTypeFromName(film.getStreamUrl());
|
||||||
return mimeType != null && mimeType.contains("mp4");
|
return mimeType != null && (mimeType.contains("mp4") || mimeType.contains("vp6"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -694,21 +698,15 @@ public class MainWindowController {
|
||||||
for (int i = 0; i < filmRoot.getChildren().size(); i++) {
|
for (int i = 0; i < filmRoot.getChildren().size(); i++) {
|
||||||
if (filmRoot.getChildren().get(i).getValue().getTitle().equals(element.getTitle())) {
|
if (filmRoot.getChildren().get(i).getValue().getTitle().equals(element.getTitle())) {
|
||||||
// if a root node exists, add element as child
|
// 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(
|
TreeItem<FilmTabelDataType> episodeNode = new TreeItem<>(new FilmTabelDataType(
|
||||||
element.getStreamUrl(), element.getTitle(), element.getSeason(), element.getEpisode(),
|
element.getStreamUrl(), element.getTitle(), element.getSeason(), element.getEpisode(),
|
||||||
element.getFavorite(), element.getCached(), element.getImage()));
|
element.getFavorite(), element.getCached(), element.getImage()));
|
||||||
filmRoot.getChildren().get(i).getChildren().add(episodeNode);
|
filmRoot.getChildren().get(i).getChildren().add(episodeNode);
|
||||||
} else if (filmRoot.getChildren().get(i).nextSibling() == null) {
|
} else if (filmRoot.getChildren().get(i).nextSibling() == null) {
|
||||||
// if no root node exists, create one and add element as child
|
// 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(
|
TreeItem<FilmTabelDataType> seriesRootNode = new TreeItem<>(new FilmTabelDataType(
|
||||||
dbController.getLastWatchedEpisode(element.getTitle()),
|
element.getTitle() + "_rootNode", element.getTitle(), "", "", element.getFavorite(),
|
||||||
element.getTitle(), "", "", element.getFavorite(), element.getCached(), element.getImage()));
|
false, element.getImage()));
|
||||||
filmRoot.getChildren().add(seriesRootNode);
|
filmRoot.getChildren().add(seriesRootNode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,16 +246,17 @@ public class DBController {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE streamUrl = \"" + streamUrl + "\";");
|
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE streamUrl = \"" + streamUrl + "\";");
|
||||||
|
|
||||||
if (rs.getBoolean("favorite") == true) {
|
while (rs.next()) {
|
||||||
mainWindowController.getFilmsList().set(indexList, new FilmTabelDataType(rs.getString("streamUrl"),
|
if (rs.getBoolean("favorite") == true) {
|
||||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
mainWindowController.getFilmsList().set(indexList, new FilmTabelDataType(rs.getString("streamUrl"),
|
||||||
rs.getBoolean("cached"), new ImageView(favorite_black)));
|
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||||
} else {
|
rs.getBoolean("cached"), new ImageView(favorite_black)));
|
||||||
mainWindowController.getFilmsList().set(indexList, new FilmTabelDataType(rs.getString("streamUrl"),
|
} else {
|
||||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
mainWindowController.getFilmsList().set(indexList, new FilmTabelDataType(rs.getString("streamUrl"),
|
||||||
rs.getBoolean("cached"), new ImageView(favorite_border_black)));
|
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||||
|
rs.getBoolean("cached"), new ImageView(favorite_border_black)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rs.close();
|
rs.close();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (Exception e) {
|
} 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
|
* sets the cached data to mwc's TextFlow
|
||||||
* @param streamUrl URL of the film
|
* @param streamUrl URL of the film
|
||||||
|
@ -675,26 +691,50 @@ public class DBController {
|
||||||
return nextFilm;
|
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);
|
LOGGER.info("last watched episode of: " + title);
|
||||||
String lastEpisodeStreamUrl = "";
|
FilmTabelDataType nextFilm = null;
|
||||||
double lastCurrentTime = -1;
|
double lastCurrentTime = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE title = \"" + title + "\";");
|
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE title = \"" + title + "\";");
|
||||||
while (rs.next()) {
|
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) {
|
if (rs.getDouble("currentTime") > lastCurrentTime) {
|
||||||
lastCurrentTime = rs.getDouble("currentTime");
|
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) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("Ups! error while getting the last watched episode!", e);
|
LOGGER.error("Ups! error while getting the last watched episode!", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return lastEpisodeStreamUrl;
|
return nextFilm;
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes the ending
|
// removes the ending
|
||||||
|
|
Loading…
Reference in New Issue