Browse Source

use try with resourcess

* rename package kellerkinder.HomeFlix to org.mosad.homeflix
dev
Jannik 2 years ago
parent
commit
5e0fd8063d
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 6
      pom.xml
  2. 39
      src/main/java/org/mosad/homeflix/application/FilmDetailView.java
  3. 2
      src/main/java/org/mosad/homeflix/application/JavaFX11Main.java
  4. 14
      src/main/java/org/mosad/homeflix/application/Main.java
  5. 14
      src/main/java/org/mosad/homeflix/application/MainWindowController.java
  6. 29
      src/main/java/org/mosad/homeflix/application/SeriesDetailView.java
  7. 10
      src/main/java/org/mosad/homeflix/application/SettingsView.java
  8. 465
      src/main/java/org/mosad/homeflix/controller/DBController.java
  9. 7
      src/main/java/org/mosad/homeflix/controller/OMDbAPIController.java
  10. 9
      src/main/java/org/mosad/homeflix/controller/SourcesController.java
  11. 5
      src/main/java/org/mosad/homeflix/controller/UpdateController.java
  12. 2
      src/main/java/org/mosad/homeflix/controller/XMLController.java
  13. 2
      src/main/java/org/mosad/homeflix/datatypes/DatabaseDataType.java
  14. 2
      src/main/java/org/mosad/homeflix/datatypes/FilmTabelDataType.java
  15. 88
      src/main/java/org/mosad/homeflix/datatypes/OMDbAPIResponseDataType.java
  16. 2
      src/main/java/org/mosad/homeflix/datatypes/PosterModeElement.java
  17. 5
      src/main/java/org/mosad/homeflix/datatypes/SeriresDVEpisode.java
  18. 2
      src/main/java/org/mosad/homeflix/datatypes/SourceDataType.java
  19. 2
      src/main/java/org/mosad/homeflix/player/HFMediaPlayerEventListener.java
  20. 4
      src/main/java/org/mosad/homeflix/player/Player.java
  21. 9
      src/main/java/org/mosad/homeflix/player/PlayerController.java
  22. 2
      src/main/resources/fxml/FilmDetailView.fxml
  23. 2
      src/main/resources/fxml/MainWindow.fxml
  24. 2
      src/main/resources/fxml/SeriesDetailView.fxml
  25. 2
      src/main/resources/fxml/SettingsView.fxml

6
pom.xml

@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.kellerkinder</groupId>
<groupId>org.mosad</groupId>
<artifactId>Project-HomeFlix</artifactId>
<version>0.8.0</version>
<packaging>jar</packaging>
@ -113,7 +113,7 @@
</execution>
</executions>
<configuration>
<mainClass>kellerkinder.HomeFlix.application.Main</mainClass>
<mainClass>org.mosad.homeflix.application.Main</mainClass>
</configuration>
</plugin>
@ -127,7 +127,7 @@
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>kellerkinder.HomeFlix.application.JavaFX11Main</mainClass>
<mainClass>org.mosad.homeflix.application.JavaFX11Main</mainClass>
</transformer>
</transformers>
</configuration>

39
src/main/java/kellerkinder/HomeFlix/application/FilmDetailView.java → src/main/java/org/mosad/homeflix/application/FilmDetailView.java

@ -20,7 +20,7 @@
*
*/
package kellerkinder.HomeFlix.application;
package org.mosad.homeflix.application;
import java.awt.Desktop;
import java.io.File;
@ -28,6 +28,10 @@ import java.io.IOException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mosad.homeflix.controller.DBController;
import org.mosad.homeflix.controller.XMLController;
import org.mosad.homeflix.datatypes.OMDbAPIResponseDataType;
import org.mosad.homeflix.player.Player;
import com.jfoenix.controls.JFXButton;
@ -39,9 +43,6 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.util.Duration;
import kellerkinder.HomeFlix.controller.DBController;
import kellerkinder.HomeFlix.controller.XMLController;
import kellerkinder.HomeFlix.player.Player;
public class FilmDetailView {
@ -136,29 +137,29 @@ public class FilmDetailView {
*/
public void setFilm(String streamURL) {
currentStreamURL = streamURL;
String[] cacheInfo = dbController.readCache(streamURL); // get the cache data from the database
OMDbAPIResponseDataType cacheInfo = dbController.readCache(streamURL); // get the cache data from the database
// add the cache data to the GUI
lblTitle.setText(cacheInfo[0]);
lblYear.setText("(" + cacheInfo[1] + ")");
lblScore.setText(XMLController.getLocalBundle().getString("score") + ": " + cacheInfo[15] + "%");
lblTitle.setText(cacheInfo.getTitle());
lblYear.setText("(" + cacheInfo.getYear() + ")");
lblScore.setText(XMLController.getLocalBundle().getString("score") + ": " + cacheInfo.getMetascore() + "%");
textPlot.setText(cacheInfo[11]);
textPlot.setText(cacheInfo.getPlot());
lblDirectors.setText(cacheInfo[8]);
lblWriters.setText(cacheInfo[9]);
lblActors.setText(cacheInfo[10]);
lblDirectors.setText(cacheInfo.getDirector());
lblWriters.setText(cacheInfo.getWriter());
lblActors.setText(cacheInfo.getActors());
lblRuntime.setText(cacheInfo[6]);
lblLanguage.setText(cacheInfo[12]);
lblRevenue.setText(cacheInfo[18]);
lblRating.setText(cacheInfo[2]);
lblRuntime.setText(cacheInfo.getRuntime());
lblLanguage.setText(cacheInfo.getLanguage());
lblRevenue.setText(cacheInfo.getBoxOffice());
lblRating.setText(cacheInfo.getRated());
try {
if (new File(cacheInfo[20]).isFile()) {
imgPoster.setImage(new Image(new File(cacheInfo[20]).toURI().toString()));
if (new File(cacheInfo.getPoster()).isFile()) {
imgPoster.setImage(new Image(new File(cacheInfo.getPoster()).toURI().toString()));
} else {
imgPoster.setImage(new Image(cacheInfo[20]));
imgPoster.setImage(new Image(cacheInfo.getPoster()));
}
} catch (Exception e) {
imgPoster.setImage(new Image("icons/Homeflix_Poster.png"));

2
src/main/java/kellerkinder/HomeFlix/application/JavaFX11Main.java → src/main/java/org/mosad/homeflix/application/JavaFX11Main.java

@ -1,4 +1,4 @@
package kellerkinder.HomeFlix.application;
package org.mosad.homeflix.application;
public class JavaFX11Main {

14
src/main/java/kellerkinder/HomeFlix/application/Main.java → src/main/java/org/mosad/homeflix/application/Main.java

@ -20,13 +20,15 @@
*
*/
package kellerkinder.HomeFlix.application;
package org.mosad.homeflix.application;
import java.io.File;
import java.io.IOException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mosad.homeflix.controller.DBController;
import org.mosad.homeflix.controller.XMLController;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
@ -34,7 +36,6 @@ import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import kellerkinder.HomeFlix.controller.XMLController;
public class Main extends Application {
@ -62,7 +63,10 @@ public class Main extends Application {
//primaryStage.setResizable(false);
primaryStage.setTitle("Project HomeFlix");
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png"))); //adds application icon
primaryStage.setOnCloseRequest(event -> System.exit(0));
primaryStage.setOnCloseRequest(event -> {
DBController.getInstance().closeDBConnection();
System.exit(0);
});
// generate window
scene = new Scene(pane); // create new scene, append pane to scene
@ -100,7 +104,9 @@ public class Main extends Application {
LOGGER.info("Java: " + XMLController.getJavaVend() + " " + XMLController.getJavaVers());
LOGGER.info("User: " + XMLController.getUserName() + " " + XMLController.getUserHome());
xmlController = new XMLController();
xmlController = new XMLController(); // Initialize the XMLController
// TODO run Migrations
if (!XMLController.getConfigFile().exists()) {
xmlController.saveSettings(); // save the settings file with default values if it doesn't exist

14
src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java → src/main/java/org/mosad/homeflix/application/MainWindowController.java

@ -20,7 +20,7 @@
*
*/
package kellerkinder.HomeFlix.application;
package org.mosad.homeflix.application;
import java.io.File;
import java.io.FileReader;
@ -39,6 +39,12 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.kellerkinder.Alerts.JFX2BtnCancelAlert;
import org.kellerkinder.Alerts.JFXInfoAlert;
import org.mosad.homeflix.controller.DBController;
import org.mosad.homeflix.controller.OMDbAPIController;
import org.mosad.homeflix.controller.UpdateController;
import org.mosad.homeflix.controller.XMLController;
import org.mosad.homeflix.datatypes.FilmTabelDataType;
import org.mosad.homeflix.datatypes.PosterModeElement;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
@ -63,12 +69,6 @@ import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.util.Duration;
import kellerkinder.HomeFlix.controller.DBController;
import kellerkinder.HomeFlix.controller.OMDbAPIController;
import kellerkinder.HomeFlix.controller.UpdateController;
import kellerkinder.HomeFlix.controller.XMLController;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
import kellerkinder.HomeFlix.datatypes.PosterModeElement;
public class MainWindowController {

29
src/main/java/kellerkinder/HomeFlix/application/SeriesDetailView.java → src/main/java/org/mosad/homeflix/application/SeriesDetailView.java

@ -20,7 +20,7 @@
*
*/
package kellerkinder.HomeFlix.application;
package org.mosad.homeflix.application;
import java.awt.Desktop;
import java.io.File;
@ -28,6 +28,11 @@ import java.io.IOException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mosad.homeflix.controller.DBController;
import org.mosad.homeflix.controller.XMLController;
import org.mosad.homeflix.datatypes.OMDbAPIResponseDataType;
import org.mosad.homeflix.datatypes.SeriresDVEpisode;
import org.mosad.homeflix.player.Player;
import com.jfoenix.controls.JFXButton;
@ -45,10 +50,6 @@ import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.util.Duration;
import kellerkinder.HomeFlix.controller.DBController;
import kellerkinder.HomeFlix.controller.XMLController;
import kellerkinder.HomeFlix.datatypes.SeriresDVEpisode;
import kellerkinder.HomeFlix.player.Player;
public class SeriesDetailView {
@ -144,21 +145,21 @@ public class SeriesDetailView {
*/
public void setSeries(String streamURL) {
currentStreamURL = streamURL;
String[] cacheInfo = dbController.readCache(streamURL); // get the cache data from the database
OMDbAPIResponseDataType cacheInfo = dbController.readCache(streamURL); // get the cache data from the database
// add the cache data to the GUI
lblTitle.setText(cacheInfo[0]);
lblYear.setText("(" + cacheInfo[1] + ")");
lblScore.setText(XMLController.getLocalBundle().getString("score") + ": " + cacheInfo[15] + "%");
lblTitle.setText(cacheInfo.getTitle());
lblYear.setText("(" + cacheInfo.getYear() + ")");
lblScore.setText(XMLController.getLocalBundle().getString("score") + ": " + cacheInfo.getMetascore() + "%");
textPlot.setText(cacheInfo[11]);
textPlot.setText(cacheInfo.getPlot());
lblDirectors.setText(cacheInfo[8]);
lblWriters.setText(cacheInfo[9]);
lblActors.setText(cacheInfo[10]);
lblDirectors.setText(cacheInfo.getDirector());
lblWriters.setText(cacheInfo.getWriter());
lblActors.setText(cacheInfo.getActors());
try {
imgPoster.setImage(new Image(new File(cacheInfo[20]).toURI().toString()));
imgPoster.setImage(new Image(new File(cacheInfo.getPoster()).toURI().toString()));
} catch (Exception e) {
imgPoster.setImage(new Image("icons/Homeflix_Poster.png"));
LOGGER.error("No Poster found, useing default.");

10
src/main/java/kellerkinder/HomeFlix/application/SettingsView.java → src/main/java/org/mosad/homeflix/application/SettingsView.java

@ -20,7 +20,7 @@
*
*/
package kellerkinder.HomeFlix.application;
package org.mosad.homeflix.application;
import java.io.File;
import java.io.FileReader;
@ -30,6 +30,10 @@ import java.io.Writer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mosad.homeflix.controller.DBController;
import org.mosad.homeflix.controller.UpdateController;
import org.mosad.homeflix.controller.XMLController;
import org.mosad.homeflix.datatypes.SourceDataType;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
@ -54,10 +58,6 @@ import javafx.scene.layout.AnchorPane;
import javafx.scene.paint.Color;
import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser;
import kellerkinder.HomeFlix.controller.DBController;
import kellerkinder.HomeFlix.controller.UpdateController;
import kellerkinder.HomeFlix.controller.XMLController;
import kellerkinder.HomeFlix.datatypes.SourceDataType;
public class SettingsView {

465
src/main/java/kellerkinder/HomeFlix/controller/DBController.java → src/main/java/org/mosad/homeflix/controller/DBController.java

@ -19,7 +19,7 @@
* MA 02110-1301, USA.
*/
package kellerkinder.HomeFlix.controller;
package org.mosad.homeflix.controller;
import java.io.File;
import java.io.FileNotFoundException;
@ -38,14 +38,14 @@ import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mosad.homeflix.datatypes.DatabaseDataType;
import org.mosad.homeflix.datatypes.FilmTabelDataType;
import org.mosad.homeflix.datatypes.OMDbAPIResponseDataType;
import org.mosad.homeflix.datatypes.PosterModeElement;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.image.Image;
import kellerkinder.HomeFlix.datatypes.DatabaseDataType;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
import kellerkinder.HomeFlix.datatypes.OMDbAPIResponseDataType;
import kellerkinder.HomeFlix.datatypes.PosterModeElement;
public class DBController {
@ -103,15 +103,13 @@ public class DBController {
* cache table: streamUrl is primary key
*/
private void createDatabase() {
try {
Statement stmt = connection.createStatement();
try (Statement stmt = connection.createStatement();) {
stmt.executeUpdate("create table if not exists films (streamUrl, title, season, episode, favorite, cached, currentTime)");
stmt.executeUpdate("create table if not exists cache ("
+ "streamUrl, Title, Year, Rated, Released, Season, Episode ,Runtime, Genre, Director, Writer,"
+ " Actors, Plot, Language, Country, Awards, Poster, Metascore, imdbRating, imdbVotes,"
+ " imdbID, Type, dvd, BoxOffice, Website, Response)");
connection.commit();
stmt.close();
} catch (SQLException e) {
LOGGER.error(e);
}
@ -122,16 +120,16 @@ public class DBController {
*/
private void loadDatabase() {
// get all entries from the table
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM films");
while (rs.next()) {
databaseStreams.add(new DatabaseDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getString("season"), rs.getString("episode"),
rs.getInt("favorite"), rs.getDouble("currentTime")));
try (Statement stmt = connection.createStatement();) {
try (ResultSet rs = stmt.executeQuery("SELECT * FROM films");) {
while (rs.next()) {
databaseStreams.add(new DatabaseDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getString("season"), rs.getString("episode"),
rs.getInt("favorite"), rs.getDouble("currentTime")));
}
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("Ups! an error occured!", e);
}
@ -145,6 +143,18 @@ public class DBController {
sourceStreams = sourcesController.loadSources();
}
/**
* try to close the databse connection
*/
public void closeDBConnection( ) {
try {
connection.commit();
connection.close();
} catch (SQLException e) {
LOGGER.error("Error while trying to close the databse connection", e);
}
}
/**
* load all streams from the database to a ObservableList, order entries by title
* @return a ObservableList that contains all streams from the database
@ -152,17 +162,17 @@ public class DBController {
public ObservableList<FilmTabelDataType> getStreamsList() {
ObservableList<FilmTabelDataType> filmsList = FXCollections.observableArrayList();
LOGGER.info("loading data from database ...");
try {
//load local Data
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM films ORDER BY title");
//load local Data
try (Statement stmt = connection.createStatement(); ) {
while (rs.next()) {
filmsList.add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getString("season"), rs.getString("episode")));
try (ResultSet rs = stmt.executeQuery("SELECT * FROM films ORDER BY title");) {
while (rs.next()) {
filmsList.add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getString("season"), rs.getString("episode")));
}
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("Ups! an error occured!", e);
}
@ -178,17 +188,16 @@ public class DBController {
public FilmTabelDataType getStream(String streamUrl) {
FilmTabelDataType film = null;
LOGGER.info("refresh data for " + streamUrl);
try {
PreparedStatement ps = connection.prepareStatement("SELECT * FROM films WHERE streamUrl = ?");
try (PreparedStatement ps = connection.prepareStatement("SELECT * FROM films WHERE streamUrl = ?");) {
ps.setString(1, streamUrl);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
film = new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getString("season"), rs.getString("episode"));
try (ResultSet rs = ps.executeQuery();) {
while (rs.next()) {
film = new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getString("season"), rs.getString("episode"));
}
}
rs.close();
ps.close();
} catch (Exception e) {
LOGGER.error("Ups! error while refreshing mwc!", e);
}
@ -201,25 +210,24 @@ public class DBController {
* @return a ObservableList of PosterModeElements
*/
public ObservableList<PosterModeElement> getPosterElementsList() {
ObservableList<PosterModeElement> posterElementsList = FXCollections.observableArrayList();
LOGGER.info("loading data from database ...");
try {
//load local Data
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE season = '' OR season = '0' ORDER BY title");
//load local Data
try (Statement stmt = connection.createStatement();) {
while (rs.next()) {
String[] cacheData = readCache(rs.getString("streamUrl")); // get from the cache table
if(cacheData[20] != null && cacheData[20].length() > 0) {
posterElementsList.add(new PosterModeElement(rs.getString("streamUrl"), cacheData[0], new Image(new File(cacheData[20]).toURI().toString())));
} else {
posterElementsList.add(new PosterModeElement(rs.getString("streamUrl"), cacheData[0], new Image("icons/Homeflix_Poster.png")));
try (ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE season = '' OR season = '0' ORDER BY title");) {
while (rs.next()) {
String[] cacheData = readCacheLegacy(rs.getString("streamUrl")); // get from the cache table
if(cacheData[20] != null && cacheData[20].length() > 0) {
posterElementsList.add(new PosterModeElement(rs.getString("streamUrl"), cacheData[0], new Image(new File(cacheData[20]).toURI().toString())));
} else {
posterElementsList.add(new PosterModeElement(rs.getString("streamUrl"), cacheData[0], new Image("icons/Homeflix_Poster.png")));
}
}
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("An error occured while getting all PosterElements!", e);
}
@ -256,69 +264,71 @@ public class DBController {
* check if there are any entries that have been removed from the film-directory
* @throws SQLException
*/
private void checkRemoveEntry() throws SQLException {
PreparedStatement ps = connection.prepareStatement("DELETE FROM films WHERE streamUrl = ?");
private void checkRemoveEntry() {
LOGGER.info("checking for entrys to remove to DB ...");
for (DatabaseDataType dbStreamEntry : databaseStreams) {
// if the directory doen't contain the entry form the database, remove it
// if sourceStreams has a item where StreamUrl equals dbStreamEntry.getStreamUrl() return it, else null
DatabaseDataType result = sourceStreams.stream()
.filter(x -> dbStreamEntry.getStreamUrl().equals(x.getStreamUrl()))
.findAny()
.orElse(null);
// if the result is null, the file is missing, remove it from the database
if (result == null) {
ps.setString(1, dbStreamEntry.getStreamUrl());
ps.addBatch();
LOGGER.info("removed \"" + dbStreamEntry.getTitle() + "\" from database");
try (PreparedStatement ps = connection.prepareStatement("DELETE FROM films WHERE streamUrl = ?");) {
for (DatabaseDataType dbStreamEntry : databaseStreams) {
// if the directory doen't contain the entry form the database, remove it
// if sourceStreams has a item where StreamUrl equals dbStreamEntry.getStreamUrl() return it, else null
DatabaseDataType result = sourceStreams.stream()
.filter(x -> dbStreamEntry.getStreamUrl().equals(x.getStreamUrl()))
.findAny()
.orElse(null);
// if the result is null, the file is missing, remove it from the database
if (result == null) {
ps.setString(1, dbStreamEntry.getStreamUrl());
ps.addBatch();
LOGGER.info("removed \"" + dbStreamEntry.getTitle() + "\" from database");
}
}
ps.executeBatch();
connection.commit();
} catch (SQLException e) {
LOGGER.error("An error occured, while cheking for media to remove", e);
}
ps.executeBatch();
connection.commit();
ps.close();
}
/**
* check if there are new films in the film-directory
* @throws SQLException
* check for new media in the source directories
* @throws FileNotFoundException
* @throws IOException
*/
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException {
PreparedStatement ps = connection.prepareStatement("insert into films values (?, ?, ?, ?, ?, ?, ?)");
private void checkAddEntry() throws FileNotFoundException, IOException {
LOGGER.info("checking for entrys to add to DB ...");
// new
for (DatabaseDataType sourceStreamEntry : sourceStreams) {
// if databaseStream has a item where StreamUrl equals sourceStreamEntry.getStreamUrl() return it, else null
DatabaseDataType result = databaseStreams.stream()
.filter(x -> sourceStreamEntry.getStreamUrl().equals(x.getStreamUrl()))
.findAny()
.orElse(null);
// if the result is null, the entry is missing, add it to the database
if (result == null) {
ps.setString(1, sourceStreamEntry.getStreamUrl());
ps.setString(2, sourceStreamEntry.getTitle());
ps.setString(3, sourceStreamEntry.getSeason());
ps.setString(4, sourceStreamEntry.getEpisode());
ps.setInt(5, sourceStreamEntry.getFavorite());
ps.setDate(6, new Date(0));
ps.setDouble(7, sourceStreamEntry.getCurrentTime());
ps.addBatch(); // adds the entry
LOGGER.info("Added \"" + sourceStreamEntry.getTitle() + "\" to database");
databaseStreams.add(sourceStreamEntry);
try (PreparedStatement ps = connection.prepareStatement("insert into films values (?, ?, ?, ?, ?, ?, ?)");) {
for (DatabaseDataType sourceStreamEntry : sourceStreams) {
// if databaseStream has a item where StreamUrl equals sourceStreamEntry.getStreamUrl() return it, else null
DatabaseDataType result = databaseStreams.stream()
.filter(x -> sourceStreamEntry.getStreamUrl().equals(x.getStreamUrl()))
.findAny()
.orElse(null);
// if the result is null, the entry is missing, add it to the database
if (result == null) {
ps.setString(1, sourceStreamEntry.getStreamUrl());
ps.setString(2, sourceStreamEntry.getTitle());
ps.setString(3, sourceStreamEntry.getSeason());
ps.setString(4, sourceStreamEntry.getEpisode());
ps.setInt(5, sourceStreamEntry.getFavorite());
ps.setDate(6, new Date(0));
ps.setDouble(7, sourceStreamEntry.getCurrentTime());
ps.addBatch(); // adds the entry
LOGGER.info("Added \"" + sourceStreamEntry.getTitle() + "\" to database");
databaseStreams.add(sourceStreamEntry);
}
}
ps.executeBatch();
connection.commit();
} catch (SQLException e) {
LOGGER.error("An error occured, while cheking for new media", e);
}
ps.executeBatch();
connection.commit();
ps.close();
}
/**
@ -327,44 +337,42 @@ public class DBController {
*/
public void printAllDBEntriesDEBUG() {
System.out.println("Outputting all entries ... \n");
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM films");
while (rs.next()) {
System.out.println(rs.getString("streamUrl"));
System.out.println(rs.getString("title"));
System.out.println(rs.getString("season"));
System.out.println(rs.getString("episode"));
System.out.println(rs.getString("rating"));
System.out.println(rs.getString("cached"));
System.out.println(rs.getString("currentTime") + "\n");
try (Statement stmt = connection.createStatement();) {
try (ResultSet rs = stmt.executeQuery("SELECT * FROM films");) {
while (rs.next()) {
System.out.println(rs.getString("streamUrl"));
System.out.println(rs.getString("title"));
System.out.println(rs.getString("season"));
System.out.println(rs.getString("episode"));
System.out.println(rs.getString("rating"));
System.out.println(rs.getString("cached"));
System.out.println(rs.getString("currentTime") + "\n");
}
}
rs.close();
stmt.close();
} catch (SQLException e) {
LOGGER.error("An error occured, while printing all entries", e);
}
}
/**
* return the favorite state for a stream
* @param streamURL URL of the stream
* return the favorite status of a media entry
* @param mediaURL URL of the media
* @return 0 if it's not a favorite, else 1
*/
public int getFavoriteState(String streamURL) {
public int getFavoriteState(String mediaURL) {
int favoriteState = 0;
PreparedStatement ps;
try {
ps = connection.prepareStatement("SELECT favorite FROM films WHERE streamUrl = ?");
ps.setString(1, streamURL);
ResultSet rs = ps.executeQuery();
try (PreparedStatement ps = connection.prepareStatement("SELECT favorite FROM films WHERE streamUrl = ?");) {
ps.setString(1, mediaURL);
while (rs.next()) {
favoriteState = rs.getInt("favorite");
try (ResultSet rs = ps.executeQuery();) {
while (rs.next()) {
favoriteState = rs.getInt("favorite");
}
}
rs.close();
ps.close();
} catch (SQLException e) {
LOGGER.error("Ups! an error occured!", e);
}
@ -373,18 +381,13 @@ public class DBController {
}
public void toggleFavoriteState(String streamURL) {
PreparedStatement ps;
try {
if (getFavoriteState(streamURL) == 0) {
ps = connection.prepareStatement("UPDATE films SET favorite = 1 WHERE streamUrl = ?");
} else {
ps = connection.prepareStatement("UPDATE films SET favorite = 0 WHERE streamUrl = ?");
}
ps.setString(1, streamURL);
int fav = getFavoriteState(streamURL) == 0 ? 1 : 0;
try (PreparedStatement ps = connection.prepareStatement("UPDATE films SET favorite = ? WHERE streamUrl = ?");) {
ps.setInt(1, fav);
ps.setString(2, streamURL);
ps.executeUpdate();
connection.commit();
ps.close();
} catch (SQLException e) {
LOGGER.error("Ups! an error occured!", e);
}
@ -396,12 +399,11 @@ public class DBController {
*/
public void dislike(String streamUrl) {
LOGGER.info("dislike " + streamUrl);
try {
PreparedStatement ps = connection.prepareStatement("UPDATE films SET favorite = 0 WHERE streamUrl = ?");
try (PreparedStatement ps = connection.prepareStatement("UPDATE films SET favorite = 0 WHERE streamUrl = ?");){
ps.setString(1, streamUrl);
ps.executeUpdate();
connection.commit();
ps.close();
} catch (SQLException e) {
LOGGER.error("Ups! an error occured!", e);
}
@ -413,12 +415,11 @@ public class DBController {
*/
public void like(String streamUrl) {
LOGGER.info("like " + streamUrl);
try {
PreparedStatement ps = connection.prepareStatement("UPDATE films SET favorite = 1 WHERE streamUrl = ?");
try (PreparedStatement ps = connection.prepareStatement("UPDATE films SET favorite = 1 WHERE streamUrl = ?");) {
ps.setString(1, streamUrl);
ps.executeUpdate();
connection.commit();
ps.close();
} catch (SQLException e) {
LOGGER.error("Ups! An error occured!", e);
}
@ -429,13 +430,11 @@ public class DBController {
* @param streamUrl URL of the film
*/
public void setCached(String streamUrl) {
try {
PreparedStatement ps = connection.prepareStatement("UPDATE films SET cached = ? WHERE streamUrl = ?");
try (PreparedStatement ps = connection.prepareStatement("UPDATE films SET cached = ? WHERE streamUrl = ?");) {
ps.setDate(1, new Date(System.currentTimeMillis()));
ps.setString(2, streamUrl);
ps.executeUpdate();
connection.commit();
ps.close();
} catch (SQLException e) {
LOGGER.error("Ups! An error occured, while setting cached = DATE for {}.", streamUrl, e);
}
@ -447,17 +446,16 @@ public class DBController {
*/
public LocalDate getCacheDate(String streamUrl) {
LocalDate cacheDate = LocalDate.now().minusDays(31);
try {
PreparedStatement ps = connection.prepareStatement("SELECT cached FROM films WHERE streamUrl = ?");
try (PreparedStatement ps = connection.prepareStatement("SELECT cached FROM films WHERE streamUrl = ?");){
ps.setString(1, streamUrl);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
cacheDate = rs.getDate("cached").toLocalDate();
try (ResultSet rs = ps.executeQuery();) {
while (rs.next()) {
cacheDate = rs.getDate("cached").toLocalDate();
}
}
rs.close();
ps.close();
} catch (SQLException e) {
LOGGER.error("Ups! An error occured, while rerading the cached date for {}.", streamUrl, e);
}
@ -471,10 +469,9 @@ public class DBController {
* @param omdbResponse the response data from omdbAPI
*/
public void addCache(String streamUrl, OMDbAPIResponseDataType omdbResponse) {
try {
PreparedStatement ps = connection.prepareStatement("insert into cache values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
LOGGER.info("adding cache for: " + streamUrl);
LOGGER.info("adding cache for: " + streamUrl);
try (PreparedStatement ps = connection.prepareStatement("insert into cache values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");){
ps.setString(1,streamUrl);
ps.setString(2,omdbResponse.getTitle());
ps.setString(3,omdbResponse.getYear());
@ -505,7 +502,6 @@ public class DBController {
ps.addBatch();
ps.executeBatch();
connection.commit();
ps.close();
} catch (Exception e) {
LOGGER.error("Ups! An error while adding cache data for {}.", streamUrl, e);
}
@ -518,13 +514,13 @@ public class DBController {
*/
public boolean searchCacheByURL(String streamUrl) {
boolean retValue = false;
try {
PreparedStatement ps = connection.prepareStatement("SELECT * FROM cache WHERE streamUrl = ?");
try (PreparedStatement ps = connection.prepareStatement("SELECT * FROM cache WHERE streamUrl = ?");) {
ps.setString(1, streamUrl);
ResultSet rs = ps.executeQuery();
retValue = rs.next();
rs.close();
ps.close();
try (ResultSet rs = ps.executeQuery();) {
retValue = rs.next();
}
} catch (Exception e) {
LOGGER.error("Ups! An error while searching for {} in the cache.", streamUrl, e);
}
@ -537,40 +533,38 @@ public class DBController {
* @param streamUrl URL of the film
* @return a String array (length = 21) with all cached data
*/
public String[] readCache(String streamUrl) {
public String[] readCacheLegacy(String streamUrl) {
String[] cacheData = new String[21];
try {
PreparedStatement ps = connection.prepareStatement("SELECT * FROM cache WHERE streamUrl = ?");
try (PreparedStatement ps = connection.prepareStatement("SELECT * FROM cache WHERE streamUrl = ?");) {
ps.setString(1, streamUrl);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
cacheData[0] = rs.getString("Title");
cacheData[1] = rs.getString("Year");
cacheData[2] = rs.getString("Rated");
cacheData[3] = rs.getString("Released");
cacheData[4] = rs.getString("Season");
cacheData[5] = rs.getString("Episode");
cacheData[6] = rs.getString("Runtime");
cacheData[7] = rs.getString("Genre");
cacheData[8] = rs.getString("Director");
cacheData[9] = rs.getString("Writer");
cacheData[10] = rs.getString("Actors");
cacheData[11] = rs.getString("Plot");
cacheData[12] = rs.getString("Language");
cacheData[13] = rs.getString("Country");
cacheData[14] = rs.getString("Awards");
cacheData[15] = rs.getString("metascore");
cacheData[16] = rs.getString("imdbRating");
cacheData[17] = rs.getString("Type");
cacheData[18] = rs.getString("BoxOffice");
cacheData[19] = rs.getString("Website");
cacheData[20] = rs.getString("Poster");
try (ResultSet rs = ps.executeQuery();) {
while (rs.next()) {
cacheData[0] = rs.getString("Title");
cacheData[1] = rs.getString("Year");
cacheData[2] = rs.getString("Rated");
cacheData[3] = rs.getString("Released");
cacheData[4] = rs.getString("Season");
cacheData[5] = rs.getString("Episode");
cacheData[6] = rs.getString("Runtime");
cacheData[7] = rs.getString("Genre");
cacheData[8] = rs.getString("Director");
cacheData[9] = rs.getString("Writer");
cacheData[10] = rs.getString("Actors");
cacheData[11] = rs.getString("Plot");
cacheData[12] = rs.getString("Language");
cacheData[13] = rs.getString("Country");
cacheData[14] = rs.getString("Awards");
cacheData[15] = rs.getString("metascore");
cacheData[16] = rs.getString("imdbRating");
cacheData[17] = rs.getString("Type");
cacheData[18] = rs.getString("BoxOffice");
cacheData[19] = rs.getString("Website");
cacheData[20] = rs.getString("Poster");
}
}
rs.close();
ps.close();
} catch (SQLException e) {
LOGGER.error("Ups! error while getting the current time for {}.", streamUrl, e);
}
@ -578,6 +572,50 @@ public class DBController {
return cacheData;
}
public OMDbAPIResponseDataType readCache(String streamUrl) {
OMDbAPIResponseDataType omdbResponse = new OMDbAPIResponseDataType();
try (PreparedStatement ps = connection.prepareStatement("SELECT * FROM cache WHERE streamUrl = ?");) {
ps.setString(1, streamUrl);
try (ResultSet rs = ps.executeQuery();) {
while (rs.next()) {
omdbResponse.setTitle(rs.getString("Title"));
omdbResponse.setYear(rs.getString("Year"));
omdbResponse.setRated(rs.getString("Rated"));
omdbResponse.setReleased(rs.getString("Released"));
omdbResponse.setSeason(rs.getString("Season"));
omdbResponse.setEpisode(rs.getString("Episode"));
omdbResponse.setRuntime(rs.getString("Runtime"));
omdbResponse.setGenre(rs.getString("Genre"));
omdbResponse.setDirector(rs.getString("Director"));
omdbResponse.setWriter(rs.getString("Writer"));
omdbResponse.setActors(rs.getString("Actors"));
omdbResponse.setPlot(rs.getString("Plot"));
omdbResponse.setLanguage(rs.getString("Language"));
omdbResponse.setCountry(rs.getString("Country"));
omdbResponse.setAwards(rs.getString("Awards"));
omdbResponse.setMetascore(rs.getString("metascore"));
omdbResponse.setImdbRating(rs.getString("imdbRating"));
omdbResponse.setImdbVotes(rs.getString("imdbVotes"));
omdbResponse.setImdbID(rs.getString("imdbID"));
omdbResponse.setType(rs.getString("Type"));
omdbResponse.setDvd(rs.getString("dvd"));
omdbResponse.setBoxOffice(rs.getString("BoxOffice"));
//omdbResponse.setProduction(object.getString("Production", ""));
omdbResponse.setWebsite(rs.getString("Website"));
omdbResponse.setResponse(rs.getString("Response"));
omdbResponse.setPoster(rs.getString("Poster"));
}
}
} catch (SQLException e) {
LOGGER.error("Ups! error while getting the current time for {}.", streamUrl, e);
}
return omdbResponse;
}
/**
* get all NOT cached entries
* @return a {@link ArrayList} of all NOT cached entries
@ -585,15 +623,15 @@ public class DBController {
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")));
try (Statement stmt = connection.createStatement();) {
try (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")));
}
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("An error occured, while getting all NOT cached entries", e);
}
@ -610,13 +648,14 @@ public class DBController {
public double getCurrentTime(String streamUrl) {
LOGGER.info("get currentTime for " + streamUrl);
double currentTime = 0;
try {
PreparedStatement ps = connection.prepareStatement("SELECT * FROM films WHERE streamUrl = ?");
try (PreparedStatement ps = connection.prepareStatement("SELECT * FROM films WHERE streamUrl = ?");) {
ps.setString(1, streamUrl);
ResultSet rs = ps.executeQuery();
currentTime = rs.getDouble("currentTime");
rs.close();
ps.close();
try (ResultSet rs = ps.executeQuery();) {
currentTime = rs.getDouble("currentTime");
}
} catch (Exception e) {
LOGGER.error("Ups! error while getting the current time!", e);
}
@ -631,13 +670,12 @@ public class DBController {
*/
public void setCurrentTime(String streamUrl, double currentTime) {
LOGGER.info("set currentTime = " + currentTime + " for " + streamUrl);
try {
PreparedStatement ps = connection.prepareStatement("UPDATE films SET currentTime = ? WHERE streamUrl = ?");
try (PreparedStatement ps = connection.prepareStatement("UPDATE films SET currentTime = ? WHERE streamUrl = ?");) {
ps.setDouble(1, currentTime);
ps.setString(2, streamUrl);
ps.executeUpdate();
connection.commit();
ps.close();
} catch (SQLException e) {
LOGGER.error("Ups! error while updateing the current time!", e);
}
@ -651,18 +689,19 @@ public class DBController {
*/
public ArrayList<String[]> getEpisodes(String title, int season) {
ArrayList<String[]> episodePosters =new ArrayList<>();
try {
// try to get a all episode of one season
PreparedStatement ps = connection.prepareStatement("SELECT streamUrl, episode FROM films WHERE title = ? AND season = ?");
// try to get a all episode of one season
try (PreparedStatement ps = connection.prepareStatement("SELECT streamUrl, episode FROM films WHERE title = ? AND season = ?");) {
ps.setString(1, title);
ps.setString(2, Integer.toString(season));
ResultSet rs = ps.executeQuery();
// for each episode load cache data
while (rs.next()) {
String[] cacheData = readCache(rs.getString("streamUrl"));
String[] ret = {rs.getString("streamUrl"), rs.getString("episode"), cacheData[20]};
episodePosters.add(ret);
try (ResultSet rs = ps.executeQuery();) {
// for each episode load cache data
while (rs.next()) {
String[] cacheData = readCacheLegacy(rs.getString("streamUrl"));
String[] ret = {rs.getString("streamUrl"), rs.getString("episode"), cacheData[20]};
episodePosters.add(ret);
}
}
} catch(Exception e) {
LOGGER.error("Ups! error while getting episodes of a season!", e);

7
src/main/java/kellerkinder/HomeFlix/controller/OMDbAPIController.java → src/main/java/org/mosad/homeflix/controller/OMDbAPIController.java

@ -20,7 +20,7 @@
*
*/
package kellerkinder.HomeFlix.controller;
package org.mosad.homeflix.controller;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
@ -32,14 +32,13 @@ import javax.imageio.ImageIO;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mosad.homeflix.datatypes.FilmTabelDataType;
import org.mosad.homeflix.datatypes.OMDbAPIResponseDataType;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
import kellerkinder.HomeFlix.datatypes.OMDbAPIResponseDataType;
public class OMDbAPIController implements Runnable {
private DBController dbController;

9
src/main/java/kellerkinder/HomeFlix/controller/SourcesController.java → src/main/java/org/mosad/homeflix/controller/SourcesController.java

@ -20,7 +20,7 @@
*
*/
package kellerkinder.HomeFlix.controller;
package org.mosad.homeflix.controller;
import java.io.File;
import java.io.FileReader;
@ -31,14 +31,13 @@ import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mosad.homeflix.datatypes.DatabaseDataType;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;
import kellerkinder.HomeFlix.datatypes.DatabaseDataType;
public class SourcesController {
private List<DatabaseDataType> sourceStreams = new ArrayList<DatabaseDataType>();
@ -85,10 +84,10 @@ public class SourcesController {
for (File file : new File(path).listFiles()) {
// if it's valid file add it to the sourceStreams
if (isValidFile(file)) {
sourceStreams.add(new DatabaseDataType(file.getPath(), cutOffEnd(file.getName()), "", "", 0, 0.0));
sourceStreams.add(new DatabaseDataType(file.getPath(), cutOffEnd(file.getName().replace("_", " ")), "", "", 0, 0.0));
} else if(isValidSeriesRoot(file)) {
// get all directories (series), root and season must be directories
sourceStreams.add(new DatabaseDataType(file.getPath(), file.getName(), "0", "0", 0, 0.0)); // add the series root node
sourceStreams.add(new DatabaseDataType(file.getPath(), file.getName().replace("_", " "), "0", "0", 0, 0.0)); // add the series root node
int sn = 1;
for (File season : file.listFiles()) {
if (season.isDirectory()) {

5
src/main/java/kellerkinder/HomeFlix/controller/UpdateController.java → src/main/java/org/mosad/homeflix/controller/UpdateController.java

@ -19,7 +19,7 @@
* MA 02110-1301, USA.
*/
package kellerkinder.HomeFlix.controller;
package org.mosad.homeflix.controller;
import java.io.BufferedReader;
import java.io.File;
@ -34,14 +34,13 @@ import javax.swing.ProgressMonitorInputStream;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mosad.homeflix.application.Main;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.eclipsesource.json.JsonValue;
import kellerkinder.HomeFlix.application.Main;
public class UpdateController {
private static int updateBuildNumber; // tag_name from gitea

2
src/main/java/kellerkinder/HomeFlix/controller/XMLController.java → src/main/java/org/mosad/homeflix/controller/XMLController.java

@ -20,7 +20,7 @@
*
*/
package kellerkinder.HomeFlix.controller;
package org.mosad.homeflix.controller;
import java.io.BufferedReader;
import java.io.File;

2
src/main/java/kellerkinder/HomeFlix/datatypes/DatabaseDataType.java → src/main/java/org/mosad/homeflix/datatypes/DatabaseDataType.java

@ -20,7 +20,7 @@
*
*/
package kellerkinder.HomeFlix.datatypes;
package org.mosad.homeflix.datatypes;
public class DatabaseDataType {

2
src/main/java/kellerkinder/HomeFlix/datatypes/FilmTabelDataType.java → src/main/java/org/mosad/homeflix/datatypes/FilmTabelDataType.java

@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package kellerkinder.HomeFlix.datatypes;
package org.mosad.homeflix.datatypes;
public class FilmTabelDataType {
private String streamUrl;

88
src/main/java/kellerkinder/HomeFlix/datatypes/OMDbAPIResponseDataType.java → src/main/java/org/mosad/homeflix/datatypes/OMDbAPIResponseDataType.java

@ -20,36 +20,36 @@
*
*/
package kellerkinder.HomeFlix.datatypes;
package org.mosad.homeflix.datatypes;
public class OMDbAPIResponseDataType {
private String title;
private String year;
private String rated;
private String released;
private String season;
private String episode;
private String runtime;
private String genre;
private String director;
private String writer;
private String actors;
private String plot;
private String language;
private String country;
private String awards;
private String poster;
private String metascore;
private String imdbRating;
private String imdbVotes;
private String imdbID;
private String type;
private String dvd;
private String boxOffice;
private String production;
private String website;
private String response;
private String title = "";
private String year = "";
private String rated = "";
private String released = "";
private String season = "";
private String episode = "";
private String runtime = "";
private String genre = "";
private String director = "";
private String writer = "";
private String actors = "";
private String plot = "";
private String language = "";
private String country = "";
private String awards = "";
private String poster = "";
private String metascore = "";
private String imdbRating = "";
private String imdbVotes = "";
private String imdbID = "";
private String type = "";
private String dvd = "";
private String boxOffice = "";
private String production = "";
private String website = "";
private String response = "";
/**
* OMDbAPIResponseDataType is the data-type for the omdbAPI response
@ -71,7 +71,7 @@ public class OMDbAPIResponseDataType {
}
public void setYear(String year) {
this.year = year;
this.year = year == null ? "N/A" : year;
}
public String getRated() {
@ -79,7 +79,7 @@ public class OMDbAPIResponseDataType {
}
public void setRated(String rated) {
this.rated = rated;
this.rated = rated == null ? "N/A" : rated;
}
public String getReleased() {
@ -87,7 +87,7 @@ public class OMDbAPIResponseDataType {
}