Browse Source

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
pull/24/head
Jannik 4 years ago
parent
commit
d6554b9acd
  1. 20
      src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java
  2. 27
      src/main/java/kellerkinder/HomeFlix/controller/DBController.java
  3. 3
      src/main/java/kellerkinder/HomeFlix/player/PlayerController.java

20
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);
}

27
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");
}
}

3
src/main/java/kellerkinder/HomeFlix/player/PlayerController.java

@ -137,7 +137,8 @@ public class PlayerController {
@Override
public void changed(ObservableValue<? extends Duration> 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;

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