minor player fixes and no more other files than videos in the db

* fixed episode = ""resulting in many exceptons
* only add video files to the database (and GUI)
* check the videos mimetype to decide which player is used
This commit is contained in:
Jannik 2018-04-05 12:09:39 +02:00
parent 2c3e9fd5e7
commit d6554b9acd
3 changed files with 31 additions and 19 deletions

View File

@ -36,6 +36,7 @@ import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer; import java.io.Writer;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URLConnection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import java.util.Properties; import java.util.Properties;
@ -596,11 +597,8 @@ public class MainWindowController {
* @return true if so, false if not * @return true if so, false if not
*/ */
private boolean isSupportedFormat(FilmTabelDataType film) { private boolean isSupportedFormat(FilmTabelDataType film) {
if (film.getStreamUrl().endsWith(".mp4")) { String mimeType = URLConnection.guessContentTypeFromName(film.getStreamUrl());
return true; return mimeType != null && mimeType.contains("mp4");
} else {
return false;
}
} }
@FXML @FXML
@ -997,9 +995,15 @@ public class MainWindowController {
// try loading the omdbAPI key // try loading the omdbAPI key
try { try {
InputStream in = getClass().getClassLoader().getResourceAsStream("apiKeys.json"); InputStream in = getClass().getClassLoader().getResourceAsStream("apiKeys.json");
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); if (in != null) {
JsonObject apiKeys = Json.parse(reader).asObject(); BufferedReader reader = new BufferedReader(new InputStreamReader(in));
omdbAPIKey = apiKeys.getString("omdbAPIKey", ""); 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) { } catch (Exception e) {
LOGGER.error("Cloud not load the omdbAPI key. Please contact the developer!", e); LOGGER.error("Cloud not load the omdbAPI key. Please contact the developer!", e);
} }

View File

@ -24,6 +24,7 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.net.URLConnection;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -167,10 +168,9 @@ public class DBController {
mainWindowController.addSourceToTable(path, mode); // add source to source-table mainWindowController.addSourceToTable(path, mode); // add source to source-table
if (mode.equals("local")) { if (mode.equals("local")) {
for (File file : new File(path).listFiles()) { for (File file : new File(path).listFiles()) {
if (file.isFile()) { if (file.isFile() && isVideoFile(file.getPath())) {
// get all files (films)
filmsStreamURL.add(file.getPath()); filmsStreamURL.add(file.getPath());
} else { } else if(file.isDirectory()) {
// get all folders (series) // get all folders (series)
for (File season : file.listFiles()) { for (File season : file.listFiles()) {
if (season.isDirectory()) { if (season.isDirectory()) {
@ -272,15 +272,14 @@ public class DBController {
LOGGER.info("refreshing the Database ..."); LOGGER.info("refreshing the Database ...");
// clean all ArraLists // clean all ArraLists
filmsdbAll.removeAll(filmsdbAll); filmsdbAll.clear();
filmsdbDir.removeAll(filmsdbDir); filmsdbDir.clear();
filmsdbStreamURL.removeAll(filmsdbStreamURL); filmsdbStreamURL.clear();
filmsStreamURL.removeAll(filmsStreamURL); filmsStreamURL.clear();
loadSources(); // reload all sources loadSources(); // reload all sources
loadDatabase(); // reload all films saved in the DB loadDatabase(); // reload all films saved in the DB
try { try {
checkAddEntry(); checkAddEntry();
checkRemoveEntry(); checkRemoveEntry();
@ -306,8 +305,6 @@ public class DBController {
for (String entry : filmsdbStreamURL) { for (String entry : filmsdbStreamURL) {
if (!filmsStreamURL.contains(entry)) { if (!filmsStreamURL.contains(entry)) {
System.out.println(filmsdbStreamURL + "\n");
System.out.println(filmsStreamURL);
stmt.executeUpdate("delete from films where streamUrl = \"" + entry + "\""); stmt.executeUpdate("delete from films where streamUrl = \"" + entry + "\"");
connection.commit(); connection.commit();
LOGGER.info("removed \"" + entry + "\" from database"); LOGGER.info("removed \"" + entry + "\" from database");
@ -685,4 +682,14 @@ public class DBController {
return str.substring(0, pos); 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");
}
} }

View File

@ -137,7 +137,8 @@ public class PlayerController {
@Override @Override
public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) { public void changed(ObservableValue<? extends Duration> observable, Duration oldValue, Duration newValue) {
currentTime = newValue.toMillis(); 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) { if ((duration - currentTime) < 10000 && episode != 0 && autoplay) {
autoplay = false; autoplay = false;