Browse Source

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
pull/24/head
Jannik 4 years ago
parent
commit
94e32b938a
  1. 28
      src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java
  2. 70
      src/main/java/kellerkinder/HomeFlix/controller/DBController.java

28
src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java

@ -475,10 +475,10 @@ 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 {
} else {
omdbAPIController = new OMDbAPIController(mainWindowController, dbController, main);
Thread omdbAPIThread = new Thread(omdbAPIController);
omdbAPIThread.setName("OMDbAPI");
@ -514,12 +514,16 @@ public class MainWindowController {
}
@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)) {
new Player(mainWindowController);
} else {
LOGGER.error("using fallback player!");
if (System.getProperty("os.name").contains("Linux")) {
String line;
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
* this is the case if the mime type is mp4
* @param entry the film you want to check
* @return true if so, false if not
*/
private boolean isSupportedFormat(FilmTabelDataType film) {
String mimeType = URLConnection.guessContentTypeFromName(film.getStreamUrl());
return mimeType != null && mimeType.contains("mp4");
String mimeType = URLConnection.guessContentTypeFromName(film.getStreamUrl());
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);
}
}

70
src/main/java/kellerkinder/HomeFlix/controller/DBController.java

@ -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…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close