added getAllNotCachedEntries()

* added a method to get all not cached entries from the films db
This commit is contained in:
Jannik 2018-08-13 23:56:16 +02:00
parent f68b0c0feb
commit 814bb00158
2 changed files with 42 additions and 1 deletions

View File

@ -213,6 +213,8 @@ public class MainWindowController {
initUI(); initUI();
initActions(); initActions();
dbController.init(); dbController.init();
checkAllPosters(); // TODO testing
} }
// Initialize general UI elements // Initialize general UI elements
@ -801,6 +803,22 @@ public class MainWindowController {
String mimeType = URLConnection.guessContentTypeFromName(film.getStreamUrl()); String mimeType = URLConnection.guessContentTypeFromName(film.getStreamUrl());
return mimeType != null && (mimeType.contains("mp4") || mimeType.contains("vp6")); return mimeType != null && (mimeType.contains("mp4") || mimeType.contains("vp6"));
} }
private void posterModeStartup() {
checkAllPosters();
}
/**
* check if all posters are cached, if not cache the missing ones
*/
private void checkAllPosters() {
// get all not cached entries, none of them should have a cached poster
for (FilmTabelDataType entry : dbController.getAllNotCachedEntries()) {
System.out.println(entry.getStreamUrl() + " is NOT cached!");
// TODO get all needed posters eg cache all not cached entries
// TODO for entries not available show homeflix logo
}
}
// getter and setter // getter and setter

View File

@ -465,7 +465,7 @@ public class DBController {
public void setCached(String streamUrl) { public void setCached(String streamUrl) {
try { try {
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
stmt.executeUpdate("UPDATE films SET cached=1 WHERE streamUrl=\"" + streamUrl + "\";"); stmt.executeUpdate("UPDATE films SET cached = 1 WHERE streamUrl = \"" + streamUrl + "\";");
connection.commit(); connection.commit();
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
@ -623,6 +623,29 @@ public class DBController {
} }
} }
/**
* get all NOT cached entries
* @return a {@link ArrayList} of all NOT cached entries
*/
public ArrayList<FilmTabelDataType> getAllNotCachedEntries() {
ArrayList<FilmTabelDataType> notCachedEntries = new ArrayList<>();
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE cached = 0");
while (rs.next()) {
notCachedEntries.add(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)));
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("An error occured, while getting all NOT cached entries", e);
}
return notCachedEntries;
}
/** /**
* return the currentTime in ms saved in the database * return the currentTime in ms saved in the database
* @param streamUrl URL of the film * @param streamUrl URL of the film