diff --git a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java index dba46e0..520ec40 100644 --- a/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java +++ b/src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java @@ -36,6 +36,7 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; import java.math.BigInteger; +import java.net.URLConnection; import java.util.ArrayList; import java.util.Locale; import java.util.Properties; @@ -596,11 +597,8 @@ public class MainWindowController { * @return true if so, false if not */ private boolean isSupportedFormat(FilmTabelDataType film) { - if (film.getStreamUrl().endsWith(".mp4")) { - return true; - } else { - return false; - } + String mimeType = URLConnection.guessContentTypeFromName(film.getStreamUrl()); + return mimeType != null && mimeType.contains("mp4"); } @FXML @@ -997,9 +995,15 @@ public class MainWindowController { // try loading the omdbAPI key try { InputStream in = getClass().getClassLoader().getResourceAsStream("apiKeys.json"); - BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - JsonObject apiKeys = Json.parse(reader).asObject(); - omdbAPIKey = apiKeys.getString("omdbAPIKey", ""); + if (in != null) { + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + JsonObject apiKeys = Json.parse(reader).asObject(); + omdbAPIKey = apiKeys.getString("omdbAPIKey", ""); + reader.close(); + in.close(); + } else { + LOGGER.warn("Cloud not load apiKeys.json. No such file"); + } } catch (Exception e) { LOGGER.error("Cloud not load the omdbAPI key. Please contact the developer!", e); } diff --git a/src/main/java/kellerkinder/HomeFlix/controller/DBController.java b/src/main/java/kellerkinder/HomeFlix/controller/DBController.java index 803dec9..1d05e7b 100644 --- a/src/main/java/kellerkinder/HomeFlix/controller/DBController.java +++ b/src/main/java/kellerkinder/HomeFlix/controller/DBController.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; +import java.net.URLConnection; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -167,10 +168,9 @@ public class DBController { mainWindowController.addSourceToTable(path, mode); // add source to source-table if (mode.equals("local")) { for (File file : new File(path).listFiles()) { - if (file.isFile()) { - // get all files (films) + if (file.isFile() && isVideoFile(file.getPath())) { filmsStreamURL.add(file.getPath()); - } else { + } else if(file.isDirectory()) { // get all folders (series) for (File season : file.listFiles()) { if (season.isDirectory()) { @@ -272,15 +272,14 @@ public class DBController { LOGGER.info("refreshing the Database ..."); // clean all ArraLists - filmsdbAll.removeAll(filmsdbAll); - filmsdbDir.removeAll(filmsdbDir); - filmsdbStreamURL.removeAll(filmsdbStreamURL); - filmsStreamURL.removeAll(filmsStreamURL); + filmsdbAll.clear(); + filmsdbDir.clear(); + filmsdbStreamURL.clear(); + filmsStreamURL.clear(); loadSources(); // reload all sources loadDatabase(); // reload all films saved in the DB - try { checkAddEntry(); checkRemoveEntry(); @@ -306,8 +305,6 @@ public class DBController { for (String entry : filmsdbStreamURL) { if (!filmsStreamURL.contains(entry)) { - System.out.println(filmsdbStreamURL + "\n"); - System.out.println(filmsStreamURL); stmt.executeUpdate("delete from films where streamUrl = \"" + entry + "\""); connection.commit(); LOGGER.info("removed \"" + entry + "\" from database"); @@ -685,4 +682,14 @@ public class DBController { return str.substring(0, pos); } + /** + * check if a file is a video + * @param path the path to the file + * @return true if the file is a video, else false + */ + public static boolean isVideoFile(String path) { + String mimeType = URLConnection.guessContentTypeFromName(path); + return mimeType != null && mimeType.startsWith("video"); + } + } diff --git a/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java b/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java index e15ad32..4ce8b3f 100644 --- a/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java +++ b/src/main/java/kellerkinder/HomeFlix/player/PlayerController.java @@ -137,7 +137,8 @@ public class PlayerController { @Override public void changed(ObservableValue observable, Duration oldValue, Duration newValue) { currentTime = newValue.toMillis(); - int episode = Integer.parseInt(film.getEpisode()); + int episode = 0; + if (film.getEpisode().length() != 0) episode = Integer.parseInt(film.getEpisode()); if ((duration - currentTime) < 10000 && episode != 0 && autoplay) { autoplay = false;