cemu_UIs updater and code cleanup
* clean up the folder structure for better maintenance * lots of code cleanup
This commit is contained in:
parent
71937540b0
commit
385193f57b
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Project HomeFlix
|
* Project-HomeFlix
|
||||||
*
|
*
|
||||||
* Copyright 2016-2017 <admin@kellerkinder>
|
* Copyright 2016-2018 <@Seil0>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.kellerkinder.Project_HomeFlix;
|
package kellerkinder.HomeFlix.application;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -44,109 +44,104 @@ import javafx.stage.Stage;
|
||||||
|
|
||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
|
|
||||||
Stage primaryStage;
|
private Stage primaryStage;
|
||||||
|
private Scene scene;
|
||||||
|
private AnchorPane pane;
|
||||||
|
private MainWindowController mainWindowController;
|
||||||
|
private static String userHome = System.getProperty("user.home");
|
||||||
|
private static String userName = System.getProperty("user.name");
|
||||||
|
private static String osName = System.getProperty("os.name");
|
||||||
|
private static String osArch = System.getProperty("os.arch");
|
||||||
|
private static String osVers = System.getProperty("os.version");
|
||||||
|
private static String javaVers = System.getProperty("java.version");
|
||||||
|
private static String javaVend= System.getProperty("java.vendor");
|
||||||
|
private String dirWin = System.getProperty("user.home") + "/Documents/HomeFlix"; //Windows: C:/Users/"User"/Documents/HomeFlix
|
||||||
|
private String dirLinux = System.getProperty("user.home") + "/HomeFlix"; //Linux: /home/"User"/HomeFlix
|
||||||
|
private File directory;
|
||||||
|
private File configFile;
|
||||||
|
private File posterCache;
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
String currentWorkingDirectory;
|
|
||||||
private String COLOR = "ee3523";
|
|
||||||
private String FONT_FAMILY = "System";
|
private String FONT_FAMILY = "System";
|
||||||
private String mode = "local"; //local or streaming TODO
|
private String mode = "local"; //local or streaming TODO
|
||||||
private String local = System.getProperty("user.language")+"_"+System.getProperty("user.country");
|
private String local = System.getProperty("user.language")+"_"+System.getProperty("user.country");
|
||||||
private boolean AUTO_UPDATE = false;
|
|
||||||
private double FONT_SIZE = 17;
|
private double FONT_SIZE = 17;
|
||||||
private ResourceBundle bundle;
|
private ResourceBundle bundle;
|
||||||
private MainWindowController mainWindowController;
|
|
||||||
private File directory;
|
|
||||||
private File settingsFile;
|
|
||||||
private File posterCache;
|
|
||||||
private String dirWin = System.getProperty("user.home") + "/Documents/HomeFlix"; //Windows: C:/Users/"User"/Documents/HomeFlix
|
|
||||||
private String dirLinux = System.getProperty("user.home") + "/HomeFlix"; //Linux: /home/"User"/HomeFlix
|
|
||||||
private static Logger LOGGER;
|
private static Logger LOGGER;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) throws IOException {
|
public void start(Stage primaryStage) throws IOException {
|
||||||
currentWorkingDirectory = new java.io.File( "." ).getCanonicalPath();
|
LOGGER.info("OS: " + osName + " " + osVers + " " + osArch);
|
||||||
|
LOGGER.info("Java: " + javaVend + " " + javaVers);
|
||||||
|
LOGGER.info("User: " + userName + " " + userHome);
|
||||||
|
|
||||||
this.primaryStage = primaryStage;
|
this.primaryStage = primaryStage;
|
||||||
mainWindow();
|
mainWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mainWindow(){
|
private void mainWindow(){
|
||||||
|
|
||||||
try {
|
try {
|
||||||
FXMLLoader loader = new FXMLLoader();
|
FXMLLoader loader = new FXMLLoader();
|
||||||
loader.setLocation(ClassLoader.getSystemResource("fxml/MainWindow.fxml"));
|
loader.setLocation(ClassLoader.getSystemResource("fxml/MainWindow.fxml"));
|
||||||
AnchorPane pane = (AnchorPane) loader.load();
|
pane = (AnchorPane) loader.load();
|
||||||
primaryStage.setMinHeight(600.00);
|
primaryStage.setMinHeight(600.00);
|
||||||
primaryStage.setMinWidth(950.00);
|
primaryStage.setMinWidth(950.00);
|
||||||
primaryStage.setResizable(false);
|
primaryStage.setResizable(false);
|
||||||
primaryStage.setTitle("Project HomeFlix");
|
primaryStage.setTitle("Project HomeFlix");
|
||||||
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png"))); //adds application icon
|
primaryStage.getIcons().add(new Image(Main.class.getResourceAsStream("/icons/Homeflix_Icon_64x64.png"))); //adds application icon
|
||||||
|
|
||||||
mainWindowController = loader.getController(); //Link of FXMLController and controller class
|
mainWindowController = loader.getController(); //Link of FXMLController and controller class
|
||||||
mainWindowController.setAutoUpdate(AUTO_UPDATE); //set auto-update
|
|
||||||
mainWindowController.setCurrentWorkingDirectory(currentWorkingDirectory);
|
|
||||||
mainWindowController.setMain(this); //call setMain
|
mainWindowController.setMain(this); //call setMain
|
||||||
|
|
||||||
|
|
||||||
/**Linux else Windows, check if directory & config exist
|
// get OS and the specific paths
|
||||||
* Windows: config file: C:/Users/"User"/Documents/HomeFlix/config.xml
|
if (osName.equals("Linux")) {
|
||||||
* directory: C:/Users/"User"/Documents/HomeFlix
|
|
||||||
* Linux: config file: /home/"User"/HomeFlix/config.xml
|
|
||||||
* directory: /home/"User"/HomeFlix
|
|
||||||
*/
|
|
||||||
if(System.getProperty("os.name").equals("Linux")) {
|
|
||||||
directory = new File(dirLinux);
|
directory = new File(dirLinux);
|
||||||
settingsFile = new File(dirLinux + "/config.xml");
|
configFile = new File(dirLinux + "/config.xml");
|
||||||
|
posterCache = new File(dirLinux + "/posterCache");
|
||||||
} else {
|
} else {
|
||||||
directory = new File(dirWin);
|
directory = new File(dirWin);
|
||||||
settingsFile = new File(dirWin + "/config.xml");
|
configFile = new File(dirWin + "/config.xml");
|
||||||
|
posterCache = new File(dirWin + "/posterCache");
|
||||||
}
|
}
|
||||||
|
|
||||||
posterCache = new File(directory+"/posterCache");
|
// startup checks
|
||||||
|
if (!configFile.exists()) {
|
||||||
if(!settingsFile.exists()){
|
|
||||||
directory.mkdir();
|
directory.mkdir();
|
||||||
mainWindowController.setPath(firstStart());
|
mainWindowController.setPath(firstStart());
|
||||||
mainWindowController.setStreamingPath(directory.getAbsolutePath());
|
mainWindowController.setStreamingPath(directory.getAbsolutePath());
|
||||||
mainWindowController.setColor(COLOR);
|
mainWindowController.setColor("ee3523");
|
||||||
mainWindowController.setSize(FONT_SIZE);
|
mainWindowController.setSize(FONT_SIZE);
|
||||||
mainWindowController.setAutoUpdate(AUTO_UPDATE);
|
mainWindowController.setAutoUpdate(false);
|
||||||
mainWindowController.setLocal(local);
|
mainWindowController.setLocal(local);
|
||||||
mainWindowController.setMode(mode);
|
mainWindowController.setMode(mode);
|
||||||
mainWindowController.saveSettings();
|
mainWindowController.saveSettings();
|
||||||
try {
|
try {
|
||||||
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again (preventing Bugs)
|
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); // start again (preventing Bugs) TODO is this really needed
|
||||||
System.exit(0); //finishes it self
|
System.exit(0); // finishes it self
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error("error while restarting HomeFlix", e);
|
LOGGER.error("error while restarting HomeFlix", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!posterCache.exists()) {
|
if (!posterCache.exists()) {
|
||||||
posterCache.mkdir();
|
posterCache.mkdir();
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindowController.loadSettings();
|
// generate window
|
||||||
mainWindowController.loadStreamingSettings();
|
scene = new Scene(pane); // create new scene, append pane to scene
|
||||||
mainWindowController.initUI();
|
|
||||||
mainWindowController.initActions();
|
|
||||||
mainWindowController.initTabel();
|
|
||||||
mainWindowController.setLocalUI();
|
|
||||||
mainWindowController.applyColor(); //set theme color
|
|
||||||
|
|
||||||
mainWindowController.dbController.main(); //initialize database controller
|
|
||||||
mainWindowController.dbController.createDatabase(); //creating the database
|
|
||||||
mainWindowController.dbController.loadData(); //loading data from database to mainWindowController
|
|
||||||
mainWindowController.addDataUI();
|
|
||||||
|
|
||||||
Scene scene = new Scene(pane); //create new scene, append pane to scene
|
|
||||||
scene.getStylesheets().add(getClass().getResource("/css/MainWindow.css").toExternalForm());
|
scene.getStylesheets().add(getClass().getResource("/css/MainWindow.css").toExternalForm());
|
||||||
primaryStage.setScene(scene); //append scene to stage
|
primaryStage.setScene(scene); // append scene to stage
|
||||||
primaryStage.show(); //show stage
|
primaryStage.show(); // show stage
|
||||||
|
|
||||||
|
// init here as it loads the games to the mwc and the gui, therefore the window must exist
|
||||||
|
mainWindowController.init();
|
||||||
|
mainWindowController.dbController.init();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("", e);
|
LOGGER.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Method for first Start
|
// Method for first Start
|
||||||
private String firstStart(){
|
private String firstStart(){
|
||||||
MainWindowController.firststart = true;
|
MainWindowController.firststart = true;
|
||||||
switch(System.getProperty("user.language")+"_"+System.getProperty("user.country")){
|
switch(System.getProperty("user.language")+"_"+System.getProperty("user.country")){
|
||||||
|
@ -190,6 +185,14 @@ public class Main extends Application {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stage getPrimaryStage() {
|
||||||
|
return primaryStage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrimaryStage(Stage primaryStage) {
|
||||||
|
this.primaryStage = primaryStage;
|
||||||
|
}
|
||||||
|
|
||||||
public String getFONT_FAMILY() {
|
public String getFONT_FAMILY() {
|
||||||
return FONT_FAMILY;
|
return FONT_FAMILY;
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
/**
|
/**
|
||||||
* Project HomeFlix
|
* Project-HomeFlix
|
||||||
*
|
*
|
||||||
* Copyright 2016-2017 <admin@kellerkinder>
|
* Copyright 2018 <@Seil0>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -19,7 +19,8 @@
|
||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.kellerkinder.Project_HomeFlix;
|
|
||||||
|
package kellerkinder.HomeFlix.application;
|
||||||
|
|
||||||
import java.awt.Desktop;
|
import java.awt.Desktop;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
@ -89,6 +90,10 @@ import javafx.scene.text.Font;
|
||||||
import javafx.scene.text.TextFlow;
|
import javafx.scene.text.TextFlow;
|
||||||
import javafx.stage.DirectoryChooser;
|
import javafx.stage.DirectoryChooser;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
|
import kellerkinder.HomeFlix.controller.DBController;
|
||||||
|
import kellerkinder.HomeFlix.controller.UpdateController;
|
||||||
|
import kellerkinder.HomeFlix.controller.apiQuery;
|
||||||
|
import kellerkinder.HomeFlix.datatypes.tableData;
|
||||||
|
|
||||||
public class MainWindowController {
|
public class MainWindowController {
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -106,7 +111,7 @@ public class MainWindowController {
|
||||||
@FXML
|
@FXML
|
||||||
private TableView<tableData> tableViewStreamingdata;
|
private TableView<tableData> tableViewStreamingdata;
|
||||||
@FXML
|
@FXML
|
||||||
TextFlow textFlow;
|
private TextFlow textFlow;
|
||||||
@FXML
|
@FXML
|
||||||
ScrollPane scrollPane;
|
ScrollPane scrollPane;
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -136,7 +141,7 @@ public class MainWindowController {
|
||||||
@FXML
|
@FXML
|
||||||
private JFXHamburger menuHam;
|
private JFXHamburger menuHam;
|
||||||
@FXML
|
@FXML
|
||||||
private JFXToggleButton autoupdateBtn;
|
private JFXToggleButton autoUpdateToggleBtn;
|
||||||
@FXML
|
@FXML
|
||||||
public JFXTextField tfPath;
|
public JFXTextField tfPath;
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -161,8 +166,8 @@ public class MainWindowController {
|
||||||
private Label mainColorLabel;
|
private Label mainColorLabel;
|
||||||
@FXML
|
@FXML
|
||||||
private Label localLabel;
|
private Label localLabel;
|
||||||
@FXML
|
@FXML
|
||||||
ImageView image1;
|
private ImageView image1;
|
||||||
|
|
||||||
private ImageView imv1;
|
private ImageView imv1;
|
||||||
|
|
||||||
|
@ -194,20 +199,22 @@ public class MainWindowController {
|
||||||
private boolean settingsTrue = false;
|
private boolean settingsTrue = false;
|
||||||
private boolean streamingSettingsTrue = false;
|
private boolean streamingSettingsTrue = false;
|
||||||
private boolean autoUpdate = false;
|
private boolean autoUpdate = false;
|
||||||
|
private boolean useBeta = false;
|
||||||
static boolean firststart = false;
|
static boolean firststart = false;
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
|
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
|
||||||
private int hashA = -647380320;
|
private int hashA = -647380320;
|
||||||
private String version = "0.5.2";
|
private String version = "0.5.2";
|
||||||
private String buildNumber = "129";
|
private String buildNumber = "131";
|
||||||
private String versionName = "solidify cow";
|
private String versionName = "solidify cow";
|
||||||
private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix");
|
private File dirWin = new File(System.getProperty("user.home") + "/Documents/HomeFlix");
|
||||||
private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix");
|
private File dirLinux = new File(System.getProperty("user.home") + "/HomeFlix");
|
||||||
private File fileWin = new File(dirWin + "/config.xml");
|
private File fileWin = new File(dirWin + "/config.xml");
|
||||||
private File fileLinux = new File(dirLinux + "/config.xml");
|
private File fileLinux = new File(dirLinux + "/config.xml");
|
||||||
|
|
||||||
String errorUpdateD;
|
public String errorUpdateD;
|
||||||
String errorUpdateV;
|
public String errorUpdateV;
|
||||||
String noFilmFound;
|
public String noFilmFound;
|
||||||
|
|
||||||
private String errorPlay;
|
private String errorPlay;
|
||||||
private String errorOpenStream;
|
private String errorOpenStream;
|
||||||
private String errorMode;
|
private String errorMode;
|
||||||
|
@ -215,7 +222,6 @@ public class MainWindowController {
|
||||||
private String errorSave;
|
private String errorSave;
|
||||||
private String infoText;
|
private String infoText;
|
||||||
private String vlcNotInstalled;
|
private String vlcNotInstalled;
|
||||||
private String currentWorkingDirectory;
|
|
||||||
private String path;
|
private String path;
|
||||||
private String streamingPath;
|
private String streamingPath;
|
||||||
private String color;
|
private String color;
|
||||||
|
@ -224,29 +230,14 @@ public class MainWindowController {
|
||||||
private String mode;
|
private String mode;
|
||||||
private String ratingSortType;
|
private String ratingSortType;
|
||||||
private String local;
|
private String local;
|
||||||
String title;
|
|
||||||
String year;
|
public double size;
|
||||||
String rating;
|
|
||||||
String publishedOn;
|
|
||||||
String duration;
|
|
||||||
String genre;
|
|
||||||
String director;
|
|
||||||
String writer;
|
|
||||||
String actors;
|
|
||||||
String plot;
|
|
||||||
String language;
|
|
||||||
String country;
|
|
||||||
String awards;
|
|
||||||
String metascore;
|
|
||||||
String imdbRating;
|
|
||||||
String type;
|
|
||||||
double size;
|
|
||||||
private int last;
|
private int last;
|
||||||
private int selected;
|
private int selected;
|
||||||
private int next;
|
private int next;
|
||||||
private File selectedFolder;
|
private File selectedFolder;
|
||||||
private File selectedStreamingFolder;
|
private File selectedStreamingFolder;
|
||||||
ResourceBundle bundle;
|
private ResourceBundle bundle;
|
||||||
|
|
||||||
private ObservableList<tableData> filterData = FXCollections.observableArrayList();
|
private ObservableList<tableData> filterData = FXCollections.observableArrayList();
|
||||||
private ObservableList<String> locals = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
|
private ObservableList<String> locals = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
|
||||||
|
@ -266,7 +257,8 @@ public class MainWindowController {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
|
|
||||||
private Main main;
|
private Main main;
|
||||||
private updater Updater;
|
private UpdateController updateController;
|
||||||
|
// private updater Updater;
|
||||||
private apiQuery ApiQuery;
|
private apiQuery ApiQuery;
|
||||||
DBController dbController;
|
DBController dbController;
|
||||||
|
|
||||||
|
@ -354,7 +346,7 @@ public class MainWindowController {
|
||||||
alert.setTitle("Info");
|
alert.setTitle("Info");
|
||||||
alert.setHeaderText("Project HomeFlix");
|
alert.setHeaderText("Project HomeFlix");
|
||||||
alert.setContentText(infoText);
|
alert.setContentText(infoText);
|
||||||
alert.initOwner(main.primaryStage);
|
alert.initOwner(main.getPrimaryStage());
|
||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,18 +443,19 @@ public class MainWindowController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void updateBtnAction(){
|
private void updateBtnAction(){
|
||||||
Thread updateThread = new Thread(Updater);
|
updateController = new UpdateController(this, buildNumber, useBeta);
|
||||||
|
Thread updateThread = new Thread(updateController);
|
||||||
updateThread.setName("Updater");
|
updateThread.setName("Updater");
|
||||||
updateThread.start();
|
updateThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void autoupdateBtnAction(){
|
private void autoUpdateToggleBtnAction(){
|
||||||
if(autoUpdate){
|
if (autoUpdate) {
|
||||||
setAutoUpdate(false);
|
setAutoUpdate(false);
|
||||||
}else{
|
} else {
|
||||||
setAutoUpdate(true);
|
setAutoUpdate(true);
|
||||||
}
|
}
|
||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,13 +488,21 @@ public class MainWindowController {
|
||||||
*/
|
*/
|
||||||
void setMain(Main main) {
|
void setMain(Main main) {
|
||||||
this.main = main;
|
this.main = main;
|
||||||
Updater = new updater(this, buildNumber);
|
dbController = new DBController(this.main, this);
|
||||||
dbController = new DBController(this, this.main);
|
|
||||||
ApiQuery = new apiQuery(this, dbController, this.main);
|
ApiQuery = new apiQuery(this, dbController, this.main);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
loadSettings();
|
||||||
|
loadStreamingSettings();
|
||||||
|
checkAutoUpdate();
|
||||||
|
initTabel();
|
||||||
|
initActions();
|
||||||
|
initUI();
|
||||||
|
}
|
||||||
|
|
||||||
//Initialize the tables (treeTableViewfilm and tableViewStreamingdata)
|
//Initialize the tables (treeTableViewfilm and tableViewStreamingdata)
|
||||||
void initTabel(){
|
void initTabel() {
|
||||||
|
|
||||||
//film Table
|
//film Table
|
||||||
columnRating.setMaxWidth(80);
|
columnRating.setMaxWidth(80);
|
||||||
|
@ -753,32 +754,22 @@ public class MainWindowController {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//initialize UI elements
|
// initialize UI elements
|
||||||
void initUI(){
|
void initUI() {
|
||||||
LOGGER.info("Mode: "+mode); //TODO debugging
|
LOGGER.info("Mode: " + mode); // TODO debugging
|
||||||
debugBtn.setDisable(true); //debugging button for tests
|
debugBtn.setDisable(true); // debugging button for tests
|
||||||
debugBtn.setVisible(false);
|
debugBtn.setVisible(false);
|
||||||
|
|
||||||
tfPath.setText(getPath());
|
tfPath.setText(getPath());
|
||||||
sliderFontSize.setValue(getSize());
|
sliderFontSize.setValue(getSize());
|
||||||
mainColor.setValue(Color.valueOf(getColor()));
|
mainColor.setValue(Color.valueOf(getColor()));
|
||||||
|
|
||||||
|
updateBtn.setFont(Font.font("System", 12));
|
||||||
|
autoUpdateToggleBtn.setSelected(isAutoUpdate());
|
||||||
|
cbLocal.setItems(locals);
|
||||||
|
|
||||||
updateBtn.setFont(Font.font("System", 12));
|
setLocalUI();
|
||||||
cbLocal.setItems(locals);
|
applyColor();
|
||||||
|
|
||||||
if(autoUpdate){
|
|
||||||
autoupdateBtn.setSelected(true);
|
|
||||||
try {
|
|
||||||
Thread updateThread = new Thread(Updater);
|
|
||||||
updateThread.setName("Updater");
|
|
||||||
updateThread.start();
|
|
||||||
updateThread.join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
autoupdateBtn.setSelected(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshTable(){
|
private void refreshTable(){
|
||||||
|
@ -789,7 +780,7 @@ public class MainWindowController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void addDataUI(){
|
public void addDataUI(){
|
||||||
if(mode.equals("local")){
|
if(mode.equals("local")){
|
||||||
for(int i = 0; i < localFilms.size(); i++){
|
for(int i = 0; i < localFilms.size(); i++){
|
||||||
root.getChildren().add(new TreeItem<tableData>(localFilms.get(i))); //add data to root-node
|
root.getChildren().add(new TreeItem<tableData>(localFilms.get(i))); //add data to root-node
|
||||||
|
@ -936,75 +927,58 @@ public class MainWindowController {
|
||||||
void setLocalUI() {
|
void setLocalUI() {
|
||||||
switch (getLocal()) {
|
switch (getLocal()) {
|
||||||
case "en_US":
|
case "en_US":
|
||||||
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_English
|
setBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US)); // us_English
|
||||||
cbLocal.getSelectionModel().select(0);
|
cbLocal.getSelectionModel().select(0);
|
||||||
break;
|
break;
|
||||||
case "de_DE":
|
case "de_DE":
|
||||||
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN); // German
|
setBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN)); // German
|
||||||
cbLocal.getSelectionModel().select(1);
|
cbLocal.getSelectionModel().select(1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // default local
|
setBundle(ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US)); // default local
|
||||||
cbLocal.getSelectionModel().select(0);
|
cbLocal.getSelectionModel().select(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
infoBtn.setText(bundle.getString("info"));
|
infoBtn.setText(getBundle().getString("info"));
|
||||||
settingsBtn.setText(bundle.getString("settings"));
|
settingsBtn.setText(getBundle().getString("settings"));
|
||||||
streamingSettingsBtn.setText(bundle.getString("streamingSettings"));
|
streamingSettingsBtn.setText(getBundle().getString("streamingSettings"));
|
||||||
tfPath.setPromptText(bundle.getString("tfPath"));
|
tfPath.setPromptText(getBundle().getString("tfPath"));
|
||||||
tfStreamingPath.setPromptText(bundle.getString("tfPath"));
|
tfStreamingPath.setPromptText(getBundle().getString("tfPath"));
|
||||||
tfsearch.setPromptText(bundle.getString("tfSearch"));
|
tfsearch.setPromptText(getBundle().getString("tfSearch"));
|
||||||
openfolderbtn.setText(bundle.getString("openFolder"));
|
openfolderbtn.setText(getBundle().getString("openFolder"));
|
||||||
updateBtn.setText(bundle.getString("checkUpdates"));
|
updateBtn.setText(getBundle().getString("checkUpdates"));
|
||||||
directoryBtn.setText(bundle.getString("chooseFolder"));
|
directoryBtn.setText(getBundle().getString("chooseFolder"));
|
||||||
streamingDirectoryBtn.setText(bundle.getString("chooseFolder"));
|
streamingDirectoryBtn.setText(getBundle().getString("chooseFolder"));
|
||||||
settingsHead1Label.setText(bundle.getString("settingsHead1Label"));
|
settingsHead1Label.setText(getBundle().getString("settingsHead1Label"));
|
||||||
mainColorLabel.setText(bundle.getString("mainColorLabel"));
|
mainColorLabel.setText(getBundle().getString("mainColorLabel"));
|
||||||
fontsizeLabel.setText(bundle.getString("fontsizeLabel"));
|
fontsizeLabel.setText(getBundle().getString("fontsizeLabel"));
|
||||||
localLabel.setText(bundle.getString("localLabel"));
|
localLabel.setText(getBundle().getString("localLabel"));
|
||||||
autoUpdateLabel.setText(bundle.getString("autoUpdateLabel"));
|
autoUpdateLabel.setText(getBundle().getString("autoUpdateLabel"));
|
||||||
versionLabel.setText(bundle.getString("version") + " " + version + " (Build: " + buildNumber + ")");
|
versionLabel.setText(getBundle().getString("version") + " " + version + " (Build: " + buildNumber + ")");
|
||||||
columnTitel.setText(bundle.getString("columnName"));
|
columnTitel.setText(getBundle().getString("columnName"));
|
||||||
columnRating.setText(bundle.getString("columnRating"));
|
columnRating.setText(getBundle().getString("columnRating"));
|
||||||
columnStreamUrl.setText(bundle.getString("columnStreamUrl"));
|
columnStreamUrl.setText(getBundle().getString("columnStreamUrl"));
|
||||||
columnResolution.setText(bundle.getString("columnResolution"));
|
columnResolution.setText(getBundle().getString("columnResolution"));
|
||||||
columnSeason.setText(bundle.getString("columnSeason"));
|
columnSeason.setText(getBundle().getString("columnSeason"));
|
||||||
columnYear.setText(bundle.getString("columnYear"));
|
columnYear.setText(getBundle().getString("columnYear"));
|
||||||
errorUpdateD = bundle.getString("errorUpdateD");
|
errorUpdateD = getBundle().getString("errorUpdateD");
|
||||||
errorUpdateV = bundle.getString("errorUpdateV");
|
errorUpdateV = getBundle().getString("errorUpdateV");
|
||||||
errorPlay = bundle.getString("errorPlay");
|
errorPlay = getBundle().getString("errorPlay");
|
||||||
errorOpenStream = bundle.getString("errorOpenStream");
|
errorOpenStream = getBundle().getString("errorOpenStream");
|
||||||
errorMode = bundle.getString("errorMode");
|
errorMode = getBundle().getString("errorMode");
|
||||||
errorLoad = bundle.getString("errorLoad");
|
errorLoad = getBundle().getString("errorLoad");
|
||||||
errorSave = bundle.getString("errorSave");
|
errorSave = getBundle().getString("errorSave");
|
||||||
noFilmFound = bundle.getString("noFilmFound");
|
noFilmFound = getBundle().getString("noFilmFound");
|
||||||
infoText = bundle.getString("version") + " " + version + " (Build: " + buildNumber + ") " + versionName + bundle.getString("infoText");
|
infoText = getBundle().getString("version") + " " + version + " (Build: " + buildNumber + ") " + versionName + getBundle().getString("infoText");
|
||||||
vlcNotInstalled = bundle.getString("vlcNotInstalled");
|
vlcNotInstalled = getBundle().getString("vlcNotInstalled");
|
||||||
|
|
||||||
title = bundle.getString("title");
|
|
||||||
year = bundle.getString("year");
|
|
||||||
rating = bundle.getString("rating");
|
|
||||||
publishedOn = bundle.getString("publishedOn");
|
|
||||||
duration = bundle.getString("duration");
|
|
||||||
genre = bundle.getString("genre");
|
|
||||||
director = bundle.getString("director");
|
|
||||||
writer = bundle.getString("writer");
|
|
||||||
actors = bundle.getString("actors");
|
|
||||||
plot = bundle.getString("plot");
|
|
||||||
language = bundle.getString("language");
|
|
||||||
country = bundle.getString("country");
|
|
||||||
awards = bundle.getString("awards");
|
|
||||||
metascore = bundle.getString("metascore");
|
|
||||||
imdbRating = bundle.getString("imdbRating");
|
|
||||||
type = bundle.getString("type");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void showErrorMsg(String msg, IOException exception) {
|
public void showErrorMsg(String msg, IOException exception) {
|
||||||
Alert alert = new Alert(AlertType.ERROR);
|
Alert alert = new Alert(AlertType.ERROR);
|
||||||
alert.setTitle("Error");
|
alert.setTitle("Error");
|
||||||
alert.setHeaderText("");
|
alert.setHeaderText("");
|
||||||
alert.setContentText(msg);
|
alert.setContentText(msg);
|
||||||
alert.initOwner(main.primaryStage);
|
alert.initOwner(main.getPrimaryStage());
|
||||||
|
|
||||||
// Create expandable Exception.
|
// Create expandable Exception.
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
|
@ -1147,6 +1121,23 @@ public class MainWindowController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if AutoUpdate, then check for updates
|
||||||
|
private void checkAutoUpdate() {
|
||||||
|
|
||||||
|
if (isAutoUpdate()) {
|
||||||
|
try {
|
||||||
|
LOGGER.info("AutoUpdate: looking for updates on startup ...");
|
||||||
|
updateController = new UpdateController(this, buildNumber, useBeta);
|
||||||
|
Thread updateThread = new Thread(updateController);
|
||||||
|
updateThread.setName("Updater");
|
||||||
|
updateThread.start();
|
||||||
|
updateThread.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// cuts 0x of the Color-pickers return value
|
// cuts 0x of the Color-pickers return value
|
||||||
private void editColor(String input) {
|
private void editColor(String input) {
|
||||||
StringBuilder sb = new StringBuilder(input);
|
StringBuilder sb = new StringBuilder(input);
|
||||||
|
@ -1212,14 +1203,6 @@ public class MainWindowController {
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCurrentWorkingDirectory() {
|
|
||||||
return currentWorkingDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCurrentWorkingDirectory(String currentWorkingDirectory) {
|
|
||||||
this.currentWorkingDirectory = currentWorkingDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ObservableList<tableData> getLocalFilms() {
|
public ObservableList<tableData> getLocalFilms() {
|
||||||
return localFilms;
|
return localFilms;
|
||||||
}
|
}
|
||||||
|
@ -1251,4 +1234,36 @@ public class MainWindowController {
|
||||||
public void setRatingSortType(String ratingSortType) {
|
public void setRatingSortType(String ratingSortType) {
|
||||||
this.ratingSortType = ratingSortType;
|
this.ratingSortType = ratingSortType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResourceBundle getBundle() {
|
||||||
|
return bundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBundle(ResourceBundle bundle) {
|
||||||
|
this.bundle = bundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextFlow getTextFlow() {
|
||||||
|
return textFlow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextFlow(TextFlow textFlow) {
|
||||||
|
this.textFlow = textFlow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImageView getImage1() {
|
||||||
|
return image1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImage1(ImageView image1) {
|
||||||
|
this.image1 = image1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JFXButton getUpdateBtn() {
|
||||||
|
return updateBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateBtn(JFXButton updateBtn) {
|
||||||
|
this.updateBtn = updateBtn;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,655 @@
|
||||||
|
/**
|
||||||
|
* Project-HomeFlix
|
||||||
|
*
|
||||||
|
* Copyright 2016-2018 <@Seil0>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kellerkinder.HomeFlix.controller;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import com.eclipsesource.json.Json;
|
||||||
|
import com.eclipsesource.json.JsonArray;
|
||||||
|
import com.eclipsesource.json.JsonObject;
|
||||||
|
import com.eclipsesource.json.JsonValue;
|
||||||
|
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.scene.text.Font;
|
||||||
|
import javafx.scene.text.FontWeight;
|
||||||
|
import javafx.scene.text.Text;
|
||||||
|
import kellerkinder.HomeFlix.application.Main;
|
||||||
|
import kellerkinder.HomeFlix.application.MainWindowController;
|
||||||
|
import kellerkinder.HomeFlix.datatypes.tableData;
|
||||||
|
|
||||||
|
public class DBController {
|
||||||
|
|
||||||
|
public DBController(Main main, MainWindowController mainWindowController) {
|
||||||
|
this.main = main;
|
||||||
|
this.mainWindowController = mainWindowController;
|
||||||
|
}
|
||||||
|
|
||||||
|
private MainWindowController mainWindowController;
|
||||||
|
private Main main;
|
||||||
|
private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; //path to database file
|
||||||
|
private Image favorite_black = new Image("icons/ic_favorite_black_18dp_1x.png");
|
||||||
|
private Image favorite_border_black = new Image("icons/ic_favorite_border_black_18dp_1x.png");
|
||||||
|
private List<String> filmsdbAll = new ArrayList<String>();
|
||||||
|
private List<String> filmsdbLocal = new ArrayList<String>();
|
||||||
|
private List<String> filmsdbStream = new ArrayList<String>();
|
||||||
|
private List<String> filmsdbStreamURL = new ArrayList<String>();
|
||||||
|
private List<String> filmsAll = new ArrayList<String>();
|
||||||
|
private List<String> filmsDir = new ArrayList<String>();
|
||||||
|
private List<String> filmsStream = new ArrayList<String>();
|
||||||
|
private List<String> filmsStreamURL = new ArrayList<String>();
|
||||||
|
private List<String> filmsStreamData = new ArrayList<String>();
|
||||||
|
private Connection connection = null;
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(DBController.class.getName());
|
||||||
|
|
||||||
|
public void init() {
|
||||||
|
LOGGER.info("<========== starting loading sql ==========>");
|
||||||
|
loadDatabase();
|
||||||
|
createDatabase();
|
||||||
|
loadData();
|
||||||
|
LOGGER.info("<========== finished loading sql ==========>");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadDatabase() {
|
||||||
|
if (System.getProperty("os.name").equals("Linux")) {
|
||||||
|
DB_PATH = System.getProperty("user.home") + "/HomeFlix/Homeflix.db";
|
||||||
|
}else{
|
||||||
|
DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db";
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// create a database connection
|
||||||
|
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
|
||||||
|
connection.setAutoCommit(false); //AutoCommit to false -> manual commit is active
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// if the error message is "out of memory", it probably means no database file is found
|
||||||
|
LOGGER.error("error while loading the ROM database", e);
|
||||||
|
}
|
||||||
|
LOGGER.info("ROM database loaded successfull");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createDatabase() {
|
||||||
|
PreparedStatement ps;
|
||||||
|
PreparedStatement psS;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
stmt.executeUpdate("create table if not exists film_local (rating, titel, streamUrl, favIcon, cached)");
|
||||||
|
stmt.executeUpdate("create table if not exists film_streaming (year, season, episode, rating, resolution, titel, streamUrl, favIcon, cached)");
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
|
||||||
|
while (rs.next()) {
|
||||||
|
filmsdbLocal.add(rs.getString(2));
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
|
||||||
|
rs = stmt.executeQuery("SELECT * FROM film_streaming;");
|
||||||
|
while (rs.next()) {
|
||||||
|
filmsdbStream.add(rs.getString(6));
|
||||||
|
filmsdbStreamURL.add(rs.getString(7));
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// getting all files from the selected directory TODO rework
|
||||||
|
String[] entries = new File(mainWindowController.getPath()).list();
|
||||||
|
if (mainWindowController.getPath().equals("") || mainWindowController.getPath() == null) {
|
||||||
|
LOGGER.warn("no path selected!");
|
||||||
|
} else if (new File(mainWindowController.getPath()).exists()) {
|
||||||
|
LOGGER.info(entries.length);
|
||||||
|
for (int i = 0; i != entries.length; i++) {
|
||||||
|
filmsDir.add(cutOffEnd(entries[i]));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.error(mainWindowController.getPath() + "dosen't exist!");
|
||||||
|
}
|
||||||
|
|
||||||
|
// getting all entries from the streaming lists
|
||||||
|
for (int v = 0; v < mainWindowController.getStreamingData().size(); v++) {
|
||||||
|
String fileName = mainWindowController.getStreamingPath() + "/"
|
||||||
|
+ mainWindowController.getStreamingData().get(v).getStreamUrl();
|
||||||
|
try {
|
||||||
|
JsonObject object = Json.parse(new FileReader(fileName)).asObject();
|
||||||
|
JsonArray items = object.get("entries").asArray();
|
||||||
|
for (JsonValue item : items) {
|
||||||
|
filmsStream.add(item.asObject().getString("titel", ""));
|
||||||
|
filmsStreamURL.add(item.asObject().getString("streamUrl", ""));
|
||||||
|
filmsStreamData.add(fileName);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// add all entries to filmsAll and filmsdbAl, for later comparing
|
||||||
|
filmsAll.addAll(filmsDir);
|
||||||
|
filmsAll.addAll(filmsStream);
|
||||||
|
filmsdbAll.addAll(filmsdbLocal);
|
||||||
|
filmsdbAll.addAll(filmsdbStream);
|
||||||
|
LOGGER.info("films in directory: " + filmsAll.size());
|
||||||
|
LOGGER.info("filme in db: " + filmsdbAll.size());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if filmsdbAll.size() == 0 database is empty, we need to fill it else check if
|
||||||
|
* there is something to remove or to add TODO separate local and streaming for
|
||||||
|
* better error handling
|
||||||
|
*/
|
||||||
|
if (filmsdbAll.size() == 0) {
|
||||||
|
LOGGER.info("Database is empty, creating tables ...");
|
||||||
|
|
||||||
|
try {
|
||||||
|
ps = connection.prepareStatement("insert into film_local values (?, ?, ?, ?, ?)");
|
||||||
|
psS = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
|
||||||
|
if (mainWindowController.getPath().equals("") || mainWindowController.getPath() == null) {
|
||||||
|
LOGGER.warn("no path selected!");
|
||||||
|
} else if (new File(mainWindowController.getPath()).exists()) {
|
||||||
|
for (int j = 0; j != entries.length; j++) // goes through all the files in the directory
|
||||||
|
{
|
||||||
|
ps.setInt(1, 0); // rating as integer 1. column
|
||||||
|
ps.setString(2, cutOffEnd(entries[j])); // name as String without ending 2. column
|
||||||
|
ps.setString(3, entries[j]); // path as String 3. column
|
||||||
|
ps.setString(4, "favorite_border_black");
|
||||||
|
ps.setBoolean(5, false);
|
||||||
|
ps.addBatch(); // add command to prepared statement
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mainWindowController.getStreamingPath().equals("") || mainWindowController.getStreamingPath().equals(null)) {
|
||||||
|
LOGGER.warn("no path selected!");
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < mainWindowController.getStreamingData().size(); i++) {
|
||||||
|
String fileNamea = mainWindowController.getStreamingPath() + "/"
|
||||||
|
+ mainWindowController.getStreamingData().get(i).getStreamUrl();
|
||||||
|
try {
|
||||||
|
JsonObject object = Json.parse(new FileReader(fileNamea)).asObject();
|
||||||
|
JsonArray items = object.get("entries").asArray();
|
||||||
|
for (JsonValue item : items) {
|
||||||
|
psS.setInt(1, item.asObject().getInt("year", 0));
|
||||||
|
psS.setInt(2, item.asObject().getInt("season", 0));
|
||||||
|
psS.setInt(3, item.asObject().getInt("episode", 0));
|
||||||
|
psS.setInt(4, 0);
|
||||||
|
psS.setString(5, item.asObject().getString("resolution", ""));
|
||||||
|
psS.setString(6, item.asObject().getString("titel", ""));
|
||||||
|
psS.setString(7, item.asObject().getString("streamUrl", ""));
|
||||||
|
psS.setString(8, "favorite_border_black");
|
||||||
|
psS.setBoolean(9, false);
|
||||||
|
psS.addBatch(); // add command to prepared statement
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ps.executeBatch(); // execute statement to write entries into table
|
||||||
|
psS.executeBatch();
|
||||||
|
connection.commit();
|
||||||
|
ps.close();
|
||||||
|
psS.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// check if film added or removed
|
||||||
|
try {
|
||||||
|
checkAddEntry();
|
||||||
|
checkRemoveEntry();
|
||||||
|
} catch (IOException | SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if cache table dosen't exist create it
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
// streamUrl is primary key
|
||||||
|
stmt.executeUpdate("create table if not exists cache ("
|
||||||
|
+ "streamUrl, Title, Year, Rated, Released, Runtime, Genre, Director, Writer,"
|
||||||
|
+ " Actors, Plot, Language, Country, Awards, Metascore, imdbRating, imdbVotes,"
|
||||||
|
+" imdbID, Type, Poster, Response)"
|
||||||
|
);
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// loading data from database to mainWindowController
|
||||||
|
public void loadData(){
|
||||||
|
LOGGER.info("loading data to mwc ...");
|
||||||
|
try {
|
||||||
|
//load local Data
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local ORDER BY titel");
|
||||||
|
while (rs.next()) {
|
||||||
|
if(rs.getString(4).equals("favorite_black")){
|
||||||
|
mainWindowController.getLocalFilms().add( new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black),rs.getBoolean(5)));
|
||||||
|
}else{
|
||||||
|
mainWindowController.getLocalFilms().add( new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black),rs.getBoolean(5)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
|
||||||
|
//load streaming Data FIXME check if there are streaming data before loading -> maybe there is an issue now
|
||||||
|
rs = stmt.executeQuery("SELECT * FROM film_streaming ORDER BY titel;");
|
||||||
|
while (rs.next()) {
|
||||||
|
if(rs.getString(8).equals("favorite_black")){
|
||||||
|
mainWindowController.getStreamingFilms().add(new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_black),rs.getBoolean(9)));
|
||||||
|
}else{
|
||||||
|
mainWindowController.getStreamingFilms().add(new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_border_black),rs.getBoolean(9)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.info("loading data to the GUI ...");
|
||||||
|
mainWindowController.addDataUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Refreshes the data in mainWindowController.newDaten and mainWindowController.streamData
|
||||||
|
//FIXME it seems that there is an issue at the moment with streaming refreshing wrong entry if there is more than one with the same name
|
||||||
|
public void refresh(String name, int i) throws SQLException {
|
||||||
|
LOGGER.info("refresh ...");
|
||||||
|
Statement stmt;
|
||||||
|
|
||||||
|
try {
|
||||||
|
stmt = connection.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = \""+name+"\";" );
|
||||||
|
if(rs.getString(4).equals("favorite_black")){
|
||||||
|
mainWindowController.getLocalFilms().set(i, new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black),rs.getBoolean(5)));
|
||||||
|
}else{
|
||||||
|
mainWindowController.getLocalFilms().set(i, new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black),rs.getBoolean(5)));
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
try {
|
||||||
|
stmt = connection.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM film_streaming WHERE titel = \""+name+"\";" );
|
||||||
|
if(rs.getString(8).equals("favorite_black")){
|
||||||
|
mainWindowController.getStreamingFilms().set(i,new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_black),rs.getBoolean(9)));
|
||||||
|
}else{
|
||||||
|
mainWindowController.getStreamingFilms().set(i,new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_border_black),rs.getBoolean(9)));
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e1) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if there are any entries that have been removed from the film-directory
|
||||||
|
*
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
private void checkRemoveEntry() throws SQLException {
|
||||||
|
LOGGER.info("checking for entrys to remove to DB ...");
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
|
||||||
|
for (int a = 0; a < filmsdbLocal.size(); a++) {
|
||||||
|
if (!filmsDir.contains(filmsdbLocal.get(a))) {
|
||||||
|
try {
|
||||||
|
stmt.executeUpdate("delete from film_local where titel = \"" + filmsdbLocal.get(a) + "\"");
|
||||||
|
connection.commit();
|
||||||
|
stmt.close();
|
||||||
|
LOGGER.info("removed \"" + filmsdbLocal.get(a) + "\" from database");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int b = 0; b < filmsdbStreamURL.size(); b++) {
|
||||||
|
if (!filmsStreamURL.contains(filmsdbStreamURL.get(b))) {
|
||||||
|
try {
|
||||||
|
stmt.executeUpdate("delete from film_streaming where titel = \"" + filmsdbStream.get(b) + "\"");
|
||||||
|
connection.commit();
|
||||||
|
stmt.close();
|
||||||
|
LOGGER.info("removed \"" + filmsdbStream.get(b) + "\" from database");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if there are new films in the film-directory
|
||||||
|
*
|
||||||
|
* @throws SQLException
|
||||||
|
* @throws FileNotFoundException
|
||||||
|
* @throws IOException
|
||||||
|
* if lastName != filmsStreamData.get(b) then set i = 0, file
|
||||||
|
* changed
|
||||||
|
*/
|
||||||
|
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException {
|
||||||
|
String lastName = "";
|
||||||
|
LOGGER.info("checking for entrys to add to DB ...");
|
||||||
|
String[] entries = new File(mainWindowController.getPath()).list();
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
PreparedStatement ps = connection
|
||||||
|
.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (int a = 0; a < filmsDir.size(); a++) {
|
||||||
|
if (!filmsdbLocal.contains(filmsDir.get(a))) {
|
||||||
|
stmt.executeUpdate("insert into film_local values (0, \"" + cutOffEnd(entries[a]) + "\", \""
|
||||||
|
+ entries[a] + "\",\"favorite_border_black\",0)");
|
||||||
|
connection.commit();
|
||||||
|
stmt.close();
|
||||||
|
LOGGER.info("added \"" + filmsDir.get(a) + "\" to database");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int b = 0; b < filmsStreamURL.size(); b++) {
|
||||||
|
if (filmsdbStreamURL.contains(filmsStreamURL.get(b))) {
|
||||||
|
} else {
|
||||||
|
if (lastName != "" && lastName != filmsStreamData.get(b)) {
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
lastName = filmsStreamData.get(b);
|
||||||
|
JsonObject object = Json.parse(new FileReader(filmsStreamData.get(b))).asObject();
|
||||||
|
JsonArray items = object.get("entries").asArray();
|
||||||
|
System.out.println(items.size() + ", " + i + "; " + b);
|
||||||
|
String streamURL = items.get(i).asObject().getString("streamUrl", "");
|
||||||
|
String titel = items.get(i).asObject().getString("titel", "");
|
||||||
|
|
||||||
|
if (streamURL.equals(filmsStreamURL.get(b))) {
|
||||||
|
System.out.println("added \"" + titel + "\"");
|
||||||
|
|
||||||
|
ps.setInt(1, items.get(i).asObject().getInt("year", 0));
|
||||||
|
ps.setInt(2, items.get(i).asObject().getInt("season", 0));
|
||||||
|
ps.setInt(3, items.get(i).asObject().getInt("episode", 0));
|
||||||
|
ps.setInt(4, 0);
|
||||||
|
ps.setString(5, items.get(i).asObject().getString("resolution", ""));
|
||||||
|
ps.setString(6, items.get(i).asObject().getString("titel", ""));
|
||||||
|
ps.setString(7, items.get(i).asObject().getString("streamUrl", ""));
|
||||||
|
ps.setString(8, "favorite_border_black");
|
||||||
|
ps.setBoolean(9, false);
|
||||||
|
ps.addBatch(); // adds the entry
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ps.executeBatch();
|
||||||
|
connection.commit();
|
||||||
|
ps.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO only for debugging
|
||||||
|
void ausgeben() {
|
||||||
|
LOGGER.info("Outputting all entries ... \n");
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.println(rs.getString(1));
|
||||||
|
System.out.println(rs.getString(2));
|
||||||
|
System.out.println(rs.getString(3));
|
||||||
|
System.out.println(rs.getString(4));
|
||||||
|
System.out.println(rs.getString(5) + "\n");
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
|
||||||
|
LOGGER.info("Streaming Entries: \n");
|
||||||
|
|
||||||
|
rs = stmt.executeQuery("SELECT * FROM film_streaming;");
|
||||||
|
while (rs.next()) {
|
||||||
|
System.out.println(rs.getString(1));
|
||||||
|
System.out.println(rs.getString(2));
|
||||||
|
System.out.println(rs.getString(3));
|
||||||
|
System.out.println(rs.getString(4));
|
||||||
|
System.out.println(rs.getString(5));
|
||||||
|
System.out.println(rs.getString(6));
|
||||||
|
System.out.println(rs.getString(7));
|
||||||
|
System.out.println(rs.getString(8));
|
||||||
|
System.out.println(rs.getString(9) + "\n");
|
||||||
|
}
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get favorite status TODO this should get the correct mode!
|
||||||
|
public void getFavStatus(String name) {
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT titel, rating, favIcon FROM film_local WHERE titel = \"" + name + "\";"); // SQL Befehl
|
||||||
|
LOGGER.info("local:" + rs.getString("rating") + ", " + rs.getString("titel") + ", " + rs.getString("favIcon"));
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
try {
|
||||||
|
Statement stmtS = connection.createStatement();
|
||||||
|
ResultSet rsS = stmtS.executeQuery("SELECT titel, rating, favIcon FROM film_streaming WHERE titel = \"" + name + "\";");
|
||||||
|
LOGGER.info("streaming:" + rsS.getString("rating") + ", " + rsS.getString("titel") + ", " + rsS.getString("favIcon"));
|
||||||
|
stmtS.close();
|
||||||
|
rsS.close();
|
||||||
|
} catch (SQLException e1) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// set rating=0 and favorite_border_black TODO this should get the correct mode!
|
||||||
|
public void dislike(String name, String streamUrl) {
|
||||||
|
LOGGER.info("defavorisieren ...");
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
stmt.executeUpdate("UPDATE film_local SET rating=0,favIcon='favorite_border_black' WHERE titel=\"" + name + "\";");
|
||||||
|
connection.commit();
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
stmt.executeUpdate("UPDATE film_streaming SET rating=0,favIcon='favorite_border_black' WHERE streamUrl=\"" + streamUrl + "\";");
|
||||||
|
connection.commit();
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set rating=1 and favorite_black TODO this should get the correct mode!
|
||||||
|
public void like(String name, String streamUrl) {
|
||||||
|
System.out.println("favorisieren ...");
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
stmt.executeUpdate("UPDATE film_local SET rating=1,favIcon='favorite_black' WHERE titel=\"" + name + "\";");
|
||||||
|
connection.commit();
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
stmt.executeUpdate("UPDATE film_streaming SET rating=1,favIcon='favorite_black' WHERE streamUrl=\"" + streamUrl + "\";");
|
||||||
|
connection.commit();
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCached(String streamUrl) throws SQLException {
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
stmt.executeUpdate("UPDATE film_local SET cached=1 WHERE streamUrl=\"" + streamUrl + "\";");
|
||||||
|
connection.commit();
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
stmt.executeUpdate("UPDATE film_streaming SET cached=1 WHERE streamUrl=\"" + streamUrl + "\";");
|
||||||
|
connection.commit();
|
||||||
|
stmt.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void addCache( String streamUrl, String Title, String Year, String Rated, String Released, String Runtime, String Genre, String Director,
|
||||||
|
String Writer, String Actors, String Plot, String Language, String Country, String Awards, String Metascore, String imdbRating,
|
||||||
|
String Type, String imdbVotes, String imdbID, String Poster, String Response) throws SQLException{
|
||||||
|
PreparedStatement ps = connection.prepareStatement("insert into cache values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||||
|
|
||||||
|
LOGGER.info("adding to cache: " + Title);
|
||||||
|
ps.setString(1,streamUrl);
|
||||||
|
ps.setString(2,Title);
|
||||||
|
ps.setString(3,Year);
|
||||||
|
ps.setString(4,Rated);
|
||||||
|
ps.setString(5,Released);
|
||||||
|
ps.setString(6,Runtime);
|
||||||
|
ps.setString(7,Genre);
|
||||||
|
ps.setString(8,Director);
|
||||||
|
ps.setString(9,Writer);
|
||||||
|
ps.setString(10,Actors);
|
||||||
|
ps.setString(11,Plot);
|
||||||
|
ps.setString(12,Language);
|
||||||
|
ps.setString(13,Country);
|
||||||
|
ps.setString(14,Awards);
|
||||||
|
ps.setString(15,Metascore);
|
||||||
|
ps.setString(16,imdbRating);
|
||||||
|
ps.setString(17,imdbVotes);
|
||||||
|
ps.setString(18,imdbID);
|
||||||
|
ps.setString(19,Type);
|
||||||
|
ps.setString(20,Poster);
|
||||||
|
ps.setString(21,Response);
|
||||||
|
ps.addBatch();
|
||||||
|
ps.executeBatch();
|
||||||
|
connection.commit();
|
||||||
|
ps.close();
|
||||||
|
LOGGER.info("done!");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readCache(String streamUrl) {
|
||||||
|
try {
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM cache WHERE streamUrl=\"" + streamUrl + "\";");
|
||||||
|
ArrayList<Text> nameText = new ArrayList<Text>();
|
||||||
|
ArrayList<Text> responseText = new ArrayList<Text>();
|
||||||
|
String fontFamily = main.getFONT_FAMILY();
|
||||||
|
Image im;
|
||||||
|
int fontSize = (int) Math.round(mainWindowController.size);
|
||||||
|
int j = 2;
|
||||||
|
|
||||||
|
nameText.add(0, new Text(mainWindowController.getBundle().getString("title") + ": "));
|
||||||
|
nameText.add(1, new Text(mainWindowController.getBundle().getString("year") + ": "));
|
||||||
|
nameText.add(2, new Text(mainWindowController.getBundle().getString("rating") + ": "));
|
||||||
|
nameText.add(3, new Text(mainWindowController.getBundle().getString("publishedOn") + ": "));
|
||||||
|
nameText.add(4, new Text(mainWindowController.getBundle().getString("duration") + ": "));
|
||||||
|
nameText.add(5, new Text(mainWindowController.getBundle().getString("genre") + ": "));
|
||||||
|
nameText.add(6, new Text(mainWindowController.getBundle().getString("director") + ": "));
|
||||||
|
nameText.add(7, new Text(mainWindowController.getBundle().getString("writer") + ": "));
|
||||||
|
nameText.add(8, new Text(mainWindowController.getBundle().getString("actors") + ": "));
|
||||||
|
nameText.add(9, new Text(mainWindowController.getBundle().getString("plot") + ": "));
|
||||||
|
nameText.add(10, new Text(mainWindowController.getBundle().getString("language") + ": "));
|
||||||
|
nameText.add(11, new Text(mainWindowController.getBundle().getString("country") + ": "));
|
||||||
|
nameText.add(12, new Text(mainWindowController.getBundle().getString("awards") + ": "));
|
||||||
|
nameText.add(13, new Text(mainWindowController.getBundle().getString("metascore") + ": "));
|
||||||
|
nameText.add(14, new Text(mainWindowController.getBundle().getString("imdbRating") + ": "));
|
||||||
|
nameText.add(15, new Text(mainWindowController.getBundle().getString("type") + ": "));
|
||||||
|
|
||||||
|
for (int i = 0; i < 15; i++) {
|
||||||
|
responseText.add(new Text(rs.getString(j) + "\n"));
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
responseText.add(new Text(rs.getString(19) + "\n"));
|
||||||
|
im = new Image(new File(rs.getString(20)).toURI().toString());
|
||||||
|
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
|
|
||||||
|
for (int i = 0; i < nameText.size(); i++) {
|
||||||
|
nameText.get(i).setFont(Font.font(fontFamily, FontWeight.BOLD, fontSize));
|
||||||
|
responseText.get(i).setFont(Font.font(fontFamily, fontSize));
|
||||||
|
}
|
||||||
|
|
||||||
|
mainWindowController.getTextFlow().getChildren().remove(0,
|
||||||
|
mainWindowController.getTextFlow().getChildren().size());
|
||||||
|
|
||||||
|
for (int i = 0; i < nameText.size(); i++) {
|
||||||
|
mainWindowController.getTextFlow().getChildren().addAll(nameText.get(i), responseText.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mainWindowController.getImage1().setImage(im);
|
||||||
|
} catch (Exception e) {
|
||||||
|
mainWindowController.getImage1().setImage(new Image("resources/icons/close_black_2048x2048.png"));
|
||||||
|
LOGGER.error(e);
|
||||||
|
}
|
||||||
|
mainWindowController.getImage1().setImage(im);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// removes the ending
|
||||||
|
private String cutOffEnd(String str) {
|
||||||
|
if (str == null) return null;
|
||||||
|
int pos = str.lastIndexOf(".");
|
||||||
|
if (pos == -1) return str;
|
||||||
|
return str.substring(0, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,163 @@
|
||||||
|
/**
|
||||||
|
* Project-HomeFlix
|
||||||
|
*
|
||||||
|
* Copyright 2018 <@Seil0>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kellerkinder.HomeFlix.controller;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import javax.swing.ProgressMonitor;
|
||||||
|
import javax.swing.ProgressMonitorInputStream;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
import com.eclipsesource.json.Json;
|
||||||
|
import com.eclipsesource.json.JsonArray;
|
||||||
|
import com.eclipsesource.json.JsonObject;
|
||||||
|
import com.eclipsesource.json.JsonValue;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import kellerkinder.HomeFlix.application.MainWindowController;
|
||||||
|
|
||||||
|
public class UpdateController implements Runnable {
|
||||||
|
|
||||||
|
private MainWindowController mainWindowController;
|
||||||
|
private String buildNumber;
|
||||||
|
private String apiOutput;
|
||||||
|
private String updateBuildNumber; // tag_name from Github
|
||||||
|
// private String updateName;
|
||||||
|
// private String updateChanges;
|
||||||
|
private String browserDownloadUrl; // update download link
|
||||||
|
private String githubApiRelease = "https://api.github.com/repos/Seil0/Project-HomeFlix/releases/latest";
|
||||||
|
private String githubApiBeta = "https://api.github.com/repos/Seil0/Project-HomeFlix/releases";
|
||||||
|
|
||||||
|
private URL githubApiUrl;
|
||||||
|
private boolean useBeta;
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(UpdateController.class.getName());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updater for Project HomeFlix based on cemu_UIs, checks for Updates and download it
|
||||||
|
*/
|
||||||
|
public UpdateController(MainWindowController mwc, String buildNumber, boolean useBeta) {
|
||||||
|
mainWindowController = mwc;
|
||||||
|
this.buildNumber = buildNumber;
|
||||||
|
this.useBeta = useBeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
LOGGER.info("beta:" + useBeta + "; checking for updates ...");
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnChecking"));
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (useBeta) {
|
||||||
|
githubApiUrl = new URL(githubApiBeta);
|
||||||
|
} else {
|
||||||
|
githubApiUrl = new URL(githubApiRelease);
|
||||||
|
}
|
||||||
|
|
||||||
|
// URL githubApiUrl = new URL(githubApiRelease);
|
||||||
|
BufferedReader ina = new BufferedReader(new InputStreamReader(githubApiUrl.openStream()));
|
||||||
|
apiOutput = ina.readLine();
|
||||||
|
ina.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
LOGGER.error("could not check update version", e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (useBeta) {
|
||||||
|
JsonArray objectArray = Json.parse("{\"items\": " + apiOutput + "}").asObject().get("items").asArray();
|
||||||
|
JsonValue object = objectArray.get(0);
|
||||||
|
JsonArray objectAssets = object.asObject().get("assets").asArray();
|
||||||
|
|
||||||
|
updateBuildNumber = object.asObject().getString("tag_name", "");
|
||||||
|
// updateName = object.asObject().getString("name", "");
|
||||||
|
// updateChanges = object.asObject().getString("body", "");
|
||||||
|
|
||||||
|
for (JsonValue asset : objectAssets) {
|
||||||
|
browserDownloadUrl = asset.asObject().getString("browser_download_url", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
JsonObject object = Json.parse(apiOutput).asObject();
|
||||||
|
JsonArray objectAssets = Json.parse(apiOutput).asObject().get("assets").asArray();
|
||||||
|
|
||||||
|
updateBuildNumber = object.getString("tag_name", "");
|
||||||
|
// updateName = object.getString("name", "");
|
||||||
|
// updateChanges = object.getString("body", "");
|
||||||
|
for (JsonValue asset : objectAssets) {
|
||||||
|
browserDownloadUrl = asset.asObject().getString("browser_download_url", "");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.info("Build: " + buildNumber + ", Update: " + updateBuildNumber);
|
||||||
|
|
||||||
|
// Compares the program BuildNumber with the current BuildNumber if program
|
||||||
|
// BuildNumber < current BuildNumber then perform a update
|
||||||
|
int iversion = Integer.parseInt(buildNumber);
|
||||||
|
int iaktVersion = Integer.parseInt(updateBuildNumber.replace(".", ""));
|
||||||
|
|
||||||
|
if (iversion >= iaktVersion) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnNoUpdateAvailable"));
|
||||||
|
});
|
||||||
|
LOGGER.info("no update available");
|
||||||
|
} else {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
mainWindowController.getUpdateBtn().setText(mainWindowController.getBundle().getString("updateBtnUpdateAvailable"));
|
||||||
|
});
|
||||||
|
LOGGER.info("update available");
|
||||||
|
LOGGER.info("download link: " + browserDownloadUrl);
|
||||||
|
try {
|
||||||
|
// open new Http connection, ProgressMonitorInputStream for downloading the data
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) new URL(browserDownloadUrl).openConnection();
|
||||||
|
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Downloading...", connection.getInputStream());
|
||||||
|
ProgressMonitor pm = pmis.getProgressMonitor();
|
||||||
|
pm.setMillisToDecideToPopup(0);
|
||||||
|
pm.setMillisToPopup(0);
|
||||||
|
pm.setMinimum(0);// set beginning of the progress bar to 0
|
||||||
|
pm.setMaximum(connection.getContentLength());// set the end to the file length
|
||||||
|
FileUtils.copyInputStreamToFile(pmis, new File("ProjectHomeFlix_update.jar")); // download update
|
||||||
|
org.apache.commons.io.FileUtils.copyFile(new File("ProjectHomeFlix_update.jar"), new File("ProjectHomeFlix.jar"));
|
||||||
|
org.apache.commons.io.FileUtils.deleteQuietly(new File("ProjectHomeFlix_update.jar")); // delete update
|
||||||
|
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); // start again TODO consider ProcessBuilder to execute
|
||||||
|
System.exit(0); // finishes itself
|
||||||
|
} catch (IOException e) {
|
||||||
|
Platform.runLater(() -> {
|
||||||
|
LOGGER.info("could not download update files", e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,8 +1,26 @@
|
||||||
/**
|
/**
|
||||||
* apiQuery for Project HomeFlix
|
* Project-HomeFlix
|
||||||
* sends a query to the omdb api
|
*
|
||||||
|
* Copyright 2016-2018 <@Seil0>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
package org.kellerkinder.Project_HomeFlix;
|
|
||||||
|
package kellerkinder.HomeFlix.controller;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
@ -23,6 +41,8 @@ import javafx.scene.image.Image;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
import javafx.scene.text.FontWeight;
|
import javafx.scene.text.FontWeight;
|
||||||
import javafx.scene.text.Text;
|
import javafx.scene.text.Text;
|
||||||
|
import kellerkinder.HomeFlix.application.Main;
|
||||||
|
import kellerkinder.HomeFlix.application.MainWindowController;
|
||||||
|
|
||||||
public class apiQuery{
|
public class apiQuery{
|
||||||
|
|
||||||
|
@ -43,7 +63,10 @@ public class apiQuery{
|
||||||
ArrayList<Text> responseText = new ArrayList<Text>();
|
ArrayList<Text> responseText = new ArrayList<Text>();
|
||||||
ArrayList<Text> nameText = new ArrayList<Text>();
|
ArrayList<Text> nameText = new ArrayList<Text>();
|
||||||
|
|
||||||
void startQuery(String titel, String streamUrl){
|
/**
|
||||||
|
* apiQuery for Project HomeFlix, sends a query to the omdb api
|
||||||
|
*/
|
||||||
|
public void startQuery(String titel, String streamUrl){
|
||||||
URL queryURL = null;
|
URL queryURL = null;
|
||||||
Scanner sc = null;
|
Scanner sc = null;
|
||||||
String moviename = null;
|
String moviename = null;
|
||||||
|
@ -106,12 +129,12 @@ public class apiQuery{
|
||||||
responseString[17] = object.getString("imdbID", "");
|
responseString[17] = object.getString("imdbID", "");
|
||||||
responseString[18] = object.getString("Poster", "");
|
responseString[18] = object.getString("Poster", "");
|
||||||
responseString[19] = object.getString("Response", "");
|
responseString[19] = object.getString("Response", "");
|
||||||
|
|
||||||
//adding poster to cache
|
//adding poster to cache
|
||||||
BufferedImage originalImage = ImageIO.read(new URL(responseString[18]));//change path to where file is located
|
BufferedImage originalImage = ImageIO.read(new URL(responseString[18]));//change path to where file is located
|
||||||
int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
|
int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
|
||||||
BufferedImage resizeImagePNG = resizeImage(originalImage, type, 198, 297);
|
BufferedImage resizeImagePNG = resizeImage(originalImage, type, 198, 297);
|
||||||
if(System.getProperty("os.name").equals("Linux")) {
|
if (System.getProperty("os.name").equals("Linux")) {
|
||||||
posterPath = posterCache+"/"+titel+".png";
|
posterPath = posterCache+"/"+titel+".png";
|
||||||
ImageIO.write(resizeImagePNG, "png", new File(posterCache+"/"+titel+".png")); //change path where you want it saved
|
ImageIO.write(resizeImagePNG, "png", new File(posterCache+"/"+titel+".png")); //change path where you want it saved
|
||||||
} else {
|
} else {
|
||||||
|
@ -127,58 +150,59 @@ public class apiQuery{
|
||||||
responseString[19]);
|
responseString[19]);
|
||||||
dbController.setCached(streamUrl);
|
dbController.setCached(streamUrl);
|
||||||
|
|
||||||
for(int i=0; i<20; i++){
|
for (int i = 0; i < 20; i++) {
|
||||||
Text text = new Text(responseString[i]+"\n");
|
Text text = new Text(responseString[i] + "\n");
|
||||||
responseText.add(text);
|
responseText.add(text);
|
||||||
responseText.get(i).setFont(Font.font(fontFamily, fontSize));
|
responseText.get(i).setFont(Font.font(fontFamily, fontSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
//if response == false then show mainWindowController.noFilmFound else create new Texts and add them to flowText
|
|
||||||
if(retdata.contains("\"Response\":\"False\"")){ //TODO + FIXME
|
|
||||||
mainWindowController.textFlow.getChildren().add(new Text(mainWindowController.noFilmFound));
|
|
||||||
im = new Image("resources/icons/close_black_2048x2048.png");
|
|
||||||
mainWindowController.image1.setImage(im);
|
|
||||||
}else{
|
|
||||||
nameText.add(0, new Text(mainWindowController.title+": "));
|
|
||||||
nameText.add(1, new Text(mainWindowController.year+": "));
|
|
||||||
nameText.add(2, new Text(mainWindowController.rating+": "));
|
|
||||||
nameText.add(3, new Text(mainWindowController.publishedOn+": "));
|
|
||||||
nameText.add(4, new Text(mainWindowController.duration+": "));
|
|
||||||
nameText.add(5, new Text(mainWindowController.genre+": "));
|
|
||||||
nameText.add(6, new Text(mainWindowController.director+": "));
|
|
||||||
nameText.add(7, new Text(mainWindowController.writer+": "));
|
|
||||||
nameText.add(8, new Text(mainWindowController.actors+": "));
|
|
||||||
nameText.add(9, new Text(mainWindowController.plot+": "));
|
|
||||||
nameText.add(10, new Text(mainWindowController.language+": "));
|
|
||||||
nameText.add(11, new Text(mainWindowController.country+": "));
|
|
||||||
nameText.add(12, new Text(mainWindowController.awards+": "));
|
|
||||||
nameText.add(13, new Text(mainWindowController.metascore+": "));
|
|
||||||
nameText.add(14, new Text(mainWindowController.imdbRating+": "));
|
|
||||||
nameText.add(15, new Text(mainWindowController.type+": "));
|
|
||||||
|
|
||||||
for(int i=0; i<nameText.size(); i++){
|
// if response == false then show mainWindowController.noFilmFound else create new Texts and add them to flowText
|
||||||
nameText.get(i).setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
if (retdata.contains("\"Response\":\"False\"")) { // TODO + FIXME
|
||||||
|
mainWindowController.getTextFlow().getChildren().add(new Text(mainWindowController.noFilmFound));
|
||||||
|
im = new Image("resources/icons/close_black_2048x2048.png");
|
||||||
|
mainWindowController.getImage1().setImage(im);
|
||||||
|
} else {
|
||||||
|
nameText.add(0, new Text(mainWindowController.getBundle().getString("title") + ": "));
|
||||||
|
nameText.add(1, new Text(mainWindowController.getBundle().getString("year") + ": "));
|
||||||
|
nameText.add(2, new Text(mainWindowController.getBundle().getString("rating") + ": "));
|
||||||
|
nameText.add(3, new Text(mainWindowController.getBundle().getString("publishedOn") + ": "));
|
||||||
|
nameText.add(4, new Text(mainWindowController.getBundle().getString("duration") + ": "));
|
||||||
|
nameText.add(5, new Text(mainWindowController.getBundle().getString("genre") + ": "));
|
||||||
|
nameText.add(6, new Text(mainWindowController.getBundle().getString("director") + ": "));
|
||||||
|
nameText.add(7, new Text(mainWindowController.getBundle().getString("writer") + ": "));
|
||||||
|
nameText.add(8, new Text(mainWindowController.getBundle().getString("actors") + ": "));
|
||||||
|
nameText.add(9, new Text(mainWindowController.getBundle().getString("plot") + ": "));
|
||||||
|
nameText.add(10, new Text(mainWindowController.getBundle().getString("language") + ": "));
|
||||||
|
nameText.add(11, new Text(mainWindowController.getBundle().getString("country") + ": "));
|
||||||
|
nameText.add(12, new Text(mainWindowController.getBundle().getString("awards") + ": "));
|
||||||
|
nameText.add(13, new Text(mainWindowController.getBundle().getString("metascore") + ": "));
|
||||||
|
nameText.add(14, new Text(mainWindowController.getBundle().getString("imdbRating") + ": "));
|
||||||
|
nameText.add(15, new Text(mainWindowController.getBundle().getString("type") + ": "));
|
||||||
|
|
||||||
|
for (int i = 0; i < nameText.size(); i++) {
|
||||||
|
nameText.get(i).setFont(Font.font(fontFamily, FontWeight.BOLD, fontSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindowController.textFlow.getChildren().remove(0, mainWindowController.textFlow.getChildren().size());
|
mainWindowController.getTextFlow().getChildren().remove(0,
|
||||||
|
mainWindowController.getTextFlow().getChildren().size());
|
||||||
for(int i=0;i<nameText.size(); i++){
|
|
||||||
mainWindowController.textFlow.getChildren().addAll(nameText.get(i),responseText.get(i));
|
for (int i = 0; i < nameText.size(); i++) {
|
||||||
|
mainWindowController.getTextFlow().getChildren().addAll(nameText.get(i), responseText.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
//if there is no poster
|
// if there is no poster
|
||||||
if(responseString[18].equals("N/A")){
|
if (responseString[18].equals("N/A")) {
|
||||||
im = new Image("resources/icons/close_black_2048x2048.png");
|
im = new Image("resources/icons/close_black_2048x2048.png");
|
||||||
}else{
|
} else {
|
||||||
im = new Image(responseString[18]);
|
im = new Image(responseString[18]);
|
||||||
}
|
}
|
||||||
mainWindowController.image1.setImage(im);
|
mainWindowController.getImage1().setImage(im);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mainWindowController.textFlow.getChildren().remove(0, mainWindowController.textFlow.getChildren().size());
|
mainWindowController.getTextFlow().getChildren().remove(0, mainWindowController.getTextFlow().getChildren().size());
|
||||||
mainWindowController.textFlow.getChildren().add(new Text(e.toString()));
|
mainWindowController.getTextFlow().getChildren().add(new Text(e.toString()));
|
||||||
System.out.println(e);
|
System.out.println(e);
|
||||||
} finally {
|
} finally {
|
||||||
//closes datainputStream, InputStream,Scanner if not already done
|
//closes datainputStream, InputStream,Scanner if not already done
|
|
@ -1,4 +1,25 @@
|
||||||
package org.kellerkinder.Project_HomeFlix;
|
/**
|
||||||
|
* Project-HomeFlix
|
||||||
|
*
|
||||||
|
* Copyright 2016-2018 <@Seil0>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kellerkinder.HomeFlix.datatypes;
|
||||||
|
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.DoubleProperty;
|
import javafx.beans.property.DoubleProperty;
|
|
@ -1,634 +0,0 @@
|
||||||
/**
|
|
||||||
* @author Jannik
|
|
||||||
* DBController for Project HomeFlix
|
|
||||||
* connection is in manual commit!
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.kellerkinder.Project_HomeFlix;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.eclipsesource.json.Json;
|
|
||||||
import com.eclipsesource.json.JsonArray;
|
|
||||||
import com.eclipsesource.json.JsonObject;
|
|
||||||
import com.eclipsesource.json.JsonValue;
|
|
||||||
import javafx.scene.image.Image;
|
|
||||||
import javafx.scene.image.ImageView;
|
|
||||||
import javafx.scene.text.Font;
|
|
||||||
import javafx.scene.text.FontWeight;
|
|
||||||
import javafx.scene.text.Text;
|
|
||||||
|
|
||||||
public class DBController {
|
|
||||||
|
|
||||||
public DBController(MainWindowController m, Main main) {
|
|
||||||
mainWindowController = m;
|
|
||||||
this.main = main;
|
|
||||||
}
|
|
||||||
|
|
||||||
private MainWindowController mainWindowController;
|
|
||||||
private Main main;
|
|
||||||
private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; //path to database file
|
|
||||||
private Image favorite_black = new Image("icons/ic_favorite_black_18dp_1x.png");
|
|
||||||
private Image favorite_border_black = new Image("icons/ic_favorite_border_black_18dp_1x.png");
|
|
||||||
private List<String> filmsdbAll = new ArrayList<String>();
|
|
||||||
private List<String> filmsdbLocal = new ArrayList<String>();
|
|
||||||
private List<String> filmsdbStream = new ArrayList<String>();
|
|
||||||
private List<String> filmsdbStreamURL = new ArrayList<String>();
|
|
||||||
private List<String> filmsAll = new ArrayList<String>();
|
|
||||||
private List<String> filmsDir = new ArrayList<String>();
|
|
||||||
private List<String> filmsStream = new ArrayList<String>();
|
|
||||||
private List<String> filmsStreamURL = new ArrayList<String>();
|
|
||||||
private List<String> filmsStreamData = new ArrayList<String>();
|
|
||||||
Connection connection = null;
|
|
||||||
|
|
||||||
public void main() {
|
|
||||||
if (System.getProperty("os.name").equals("Linux")) {
|
|
||||||
DB_PATH = System.getProperty("user.home") + "/HomeFlix/Homeflix.db";
|
|
||||||
}else{
|
|
||||||
DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db";
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
// create a database connection
|
|
||||||
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
|
|
||||||
connection.setAutoCommit(false); //AutoCommit to false -> manual commit is active
|
|
||||||
} catch (SQLException e) {
|
|
||||||
// if the error message is "out of memory", it probably means no database file is found
|
|
||||||
System.err.println(e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
//close connection -> at the moment this kills the program
|
|
||||||
// finally {
|
|
||||||
// try {
|
|
||||||
// if (connection != null)
|
|
||||||
// connection.close();
|
|
||||||
// } catch (SQLException e) {
|
|
||||||
// // connection close failed.
|
|
||||||
// System.err.println(e);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
void createDatabase() {
|
|
||||||
System.out.println("<==========starting loading sql==========>");
|
|
||||||
|
|
||||||
PreparedStatement ps;
|
|
||||||
PreparedStatement psS;
|
|
||||||
|
|
||||||
try {
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
stmt.executeUpdate("create table if not exists film_local (rating, titel, streamUrl, favIcon, cached)");
|
|
||||||
stmt.executeUpdate("create table if not exists film_streaming (year, season, episode, rating, resolution, titel, streamUrl, favIcon, cached)");
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
|
|
||||||
while (rs.next()) {
|
|
||||||
filmsdbLocal.add(rs.getString(2));
|
|
||||||
}
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
|
|
||||||
rs = stmt.executeQuery("SELECT * FROM film_streaming;");
|
|
||||||
while (rs.next()) {
|
|
||||||
filmsdbStream.add(rs.getString(6));
|
|
||||||
filmsdbStreamURL.add(rs.getString(7));
|
|
||||||
}
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
}catch (SQLException ea){
|
|
||||||
System.err.println("Ups! an error occured!");
|
|
||||||
ea.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
//getting all files from the selected directory TODO rework
|
|
||||||
String[] entries = new File(mainWindowController.getPath()).list();
|
|
||||||
if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){
|
|
||||||
System.out.println("Kein Pfad angegeben"); //if path == null or ""
|
|
||||||
}else if(new File(mainWindowController.getPath()).exists()) {
|
|
||||||
System.out.println(entries.length);
|
|
||||||
for(int i=0;i!=entries.length;i++){
|
|
||||||
filmsDir.add(cutOffEnd(entries[i]));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
System.out.println(mainWindowController.getPath() + "dosen't exist!");
|
|
||||||
}
|
|
||||||
|
|
||||||
//getting all entries from the streaming lists
|
|
||||||
for(int v=0; v< mainWindowController.getStreamingData().size(); v++){
|
|
||||||
String fileName = mainWindowController.getStreamingPath()+"/"+mainWindowController.getStreamingData().get(v).getStreamUrl();
|
|
||||||
try {
|
|
||||||
JsonObject object = Json.parse(new FileReader(fileName)).asObject();
|
|
||||||
JsonArray items = object.get("entries").asArray();
|
|
||||||
for (JsonValue item : items) {
|
|
||||||
filmsStream.add(item.asObject().getString("titel",""));
|
|
||||||
filmsStreamURL.add(item.asObject().getString("streamUrl",""));
|
|
||||||
filmsStreamData.add(fileName);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//add all entries to filmsAll and filmsdbAl, for later comparing
|
|
||||||
filmsAll.addAll(filmsDir);
|
|
||||||
filmsAll.addAll(filmsStream);
|
|
||||||
filmsdbAll.addAll(filmsdbLocal);
|
|
||||||
filmsdbAll.addAll(filmsdbStream);
|
|
||||||
System.out.println("films in directory: "+filmsAll.size());
|
|
||||||
System.out.println("filme in db: "+filmsdbAll.size());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* if filmsdbAll.size() == 0 database is empty, we need to fill it
|
|
||||||
* else check if there is something to remove or to add
|
|
||||||
* TODO separate local and streaming for better error handling
|
|
||||||
*/
|
|
||||||
if(filmsdbAll.size() == 0){
|
|
||||||
System.out.println("creating entries ...");
|
|
||||||
|
|
||||||
try{
|
|
||||||
ps = connection.prepareStatement("insert into film_local values (?, ?, ?, ?, ?)");
|
|
||||||
psS = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
||||||
|
|
||||||
if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){
|
|
||||||
System.out.println("Kein Pfad angegeben"); //if path == null or ""
|
|
||||||
}else if(new File(mainWindowController.getPath()).exists()){
|
|
||||||
for(int j=0;j!=entries.length;j++) //goes through all the files in the directory
|
|
||||||
{
|
|
||||||
ps.setInt(1, 0); //rating as integer 1. column
|
|
||||||
ps.setString(2, cutOffEnd(entries[j])); //name as String without ending 2. column
|
|
||||||
ps.setString(3,entries[j]); //path as String 3. column
|
|
||||||
ps.setString(4, "favorite_border_black");
|
|
||||||
ps.setBoolean(5, false);
|
|
||||||
ps.addBatch(); // add command to prepared statement
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(mainWindowController.getStreamingPath().equals("")||mainWindowController.getStreamingPath().equals(null)){
|
|
||||||
System.out.println("Kein Pfad angegeben"); //if path == null or ""
|
|
||||||
}else{
|
|
||||||
for(int i=0; i< mainWindowController.getStreamingData().size(); i++){
|
|
||||||
String fileNamea = mainWindowController.getStreamingPath()+"/"+mainWindowController.getStreamingData().get(i).getStreamUrl();
|
|
||||||
try {
|
|
||||||
JsonObject object = Json.parse(new FileReader(fileNamea)).asObject();
|
|
||||||
JsonArray items = object.get("entries").asArray();
|
|
||||||
for (JsonValue item : items) {
|
|
||||||
psS.setInt(1, item.asObject().getInt("year", 0));
|
|
||||||
psS.setInt(2, item.asObject().getInt("season", 0));
|
|
||||||
psS.setInt(3, item.asObject().getInt("episode", 0));
|
|
||||||
psS.setInt(4, 0);
|
|
||||||
psS.setString(5, item.asObject().getString("resolution", ""));
|
|
||||||
psS.setString(6, item.asObject().getString("titel",""));
|
|
||||||
psS.setString(7, item.asObject().getString("streamUrl", ""));
|
|
||||||
psS.setString(8, "favorite_border_black");
|
|
||||||
psS.setBoolean(9, false);
|
|
||||||
psS.addBatch(); // add command to prepared statement
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ps.executeBatch(); //execute statement to write entries into table
|
|
||||||
psS.executeBatch();
|
|
||||||
connection.commit();
|
|
||||||
ps.close();
|
|
||||||
psS.close();
|
|
||||||
}catch (SQLException ea) {
|
|
||||||
System.err.println("Ups! an error occured!");
|
|
||||||
ea.printStackTrace();
|
|
||||||
}
|
|
||||||
}else {
|
|
||||||
try {
|
|
||||||
try {
|
|
||||||
checkAddEntry(); //check if added a new file
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
checkRemoveEntry(); //check if removed a file
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//start of cache-table
|
|
||||||
try {
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
stmt.executeUpdate( "create table if not exists cache (streamUrl, Title, Year, Rated, Released, Runtime, Genre, Director, Writer," //streamUrl is primary key
|
|
||||||
+" Actors, Plot, Language, Country, Awards, Metascore, imdbRating, imdbVotes, imdbID, Type, Poster, Response)");
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//loading data from database to mainWindowController
|
|
||||||
void loadData(){
|
|
||||||
System.out.println("loading data to mwc ...");
|
|
||||||
try {
|
|
||||||
//load local Data
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local ORDER BY titel");
|
|
||||||
while (rs.next()) {
|
|
||||||
if(rs.getString(4).equals("favorite_black")){
|
|
||||||
mainWindowController.getLocalFilms().add( new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black),rs.getBoolean(5)));
|
|
||||||
}else{
|
|
||||||
mainWindowController.getLocalFilms().add( new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black),rs.getBoolean(5)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
|
|
||||||
//load streaming Data FIXME check if there are streaming data before loading -> maybe there is an issue now
|
|
||||||
rs = stmt.executeQuery("SELECT * FROM film_streaming ORDER BY titel;");
|
|
||||||
while (rs.next()) {
|
|
||||||
if(rs.getString(8).equals("favorite_black")){
|
|
||||||
mainWindowController.getStreamingFilms().add(new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_black),rs.getBoolean(9)));
|
|
||||||
}else{
|
|
||||||
mainWindowController.getStreamingFilms().add(new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_border_black),rs.getBoolean(9)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
System.err.println("Ups! an error occured!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println("<==========finished loading sql==========>");
|
|
||||||
}
|
|
||||||
|
|
||||||
//Refreshes the data in mainWindowController.newDaten and mainWindowController.streamData
|
|
||||||
//FIXME it seems that there is an issue at the moment with streaming refreshing wrong entry if there is more than one with the same name
|
|
||||||
void refresh(String name,int i) throws SQLException{
|
|
||||||
System.out.println("refresh ...");
|
|
||||||
Statement stmt;
|
|
||||||
|
|
||||||
try {
|
|
||||||
stmt = connection.createStatement();
|
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = \""+name+"\";" );
|
|
||||||
if(rs.getString(4).equals("favorite_black")){
|
|
||||||
mainWindowController.getLocalFilms().set(i, new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black),rs.getBoolean(5)));
|
|
||||||
}else{
|
|
||||||
mainWindowController.getLocalFilms().set(i, new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black),rs.getBoolean(5)));
|
|
||||||
}
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
try {
|
|
||||||
stmt = connection.createStatement();
|
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_streaming WHERE titel = \""+name+"\";" );
|
|
||||||
if(rs.getString(8).equals("favorite_black")){
|
|
||||||
mainWindowController.getStreamingFilms().set(i,new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_black),rs.getBoolean(9)));
|
|
||||||
}else{
|
|
||||||
mainWindowController.getStreamingFilms().set(i,new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_border_black),rs.getBoolean(9)));
|
|
||||||
}
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
System.err.println("Ups! an error occured!");
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* check if there are any entries that have been removed from the film-directory
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
|
||||||
private void checkRemoveEntry() throws SQLException{
|
|
||||||
System.out.println("checking for entrys to remove to DB ...");
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
|
|
||||||
for(int a=0; a<filmsdbLocal.size(); a++){
|
|
||||||
if(!filmsDir.contains(filmsdbLocal.get(a))){
|
|
||||||
try {
|
|
||||||
stmt.executeUpdate("delete from film_local where titel = \""+filmsdbLocal.get(a) + "\"");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
System.out.println("removed \""+filmsdbLocal.get(a)+"\" from databsae");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int b=0; b<filmsdbStreamURL.size(); b++){
|
|
||||||
if(!filmsStreamURL.contains(filmsdbStreamURL.get(b))){
|
|
||||||
try {
|
|
||||||
stmt.executeUpdate("delete from film_streaming where titel = \"" + filmsdbStream.get(b) + "\"");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
System.out.println("removed \""+filmsdbStream.get(b)+"\" from databsae");
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check if there are new films in the film-directory
|
|
||||||
* @throws SQLException
|
|
||||||
* @throws FileNotFoundException
|
|
||||||
* @throws IOException
|
|
||||||
* if lastName != filmsStreamData.get(b) then set i = 0, file changed
|
|
||||||
*/
|
|
||||||
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException{
|
|
||||||
String lastName = "";
|
|
||||||
System.out.println("checking for entrys to add to DB ...");
|
|
||||||
String[] entries = new File(mainWindowController.getPath()).list();
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
PreparedStatement ps = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
|
|
||||||
int i=0;
|
|
||||||
|
|
||||||
for(int a=0; a<filmsDir.size(); a++){
|
|
||||||
if(!filmsdbLocal.contains(filmsDir.get(a))){
|
|
||||||
stmt.executeUpdate("insert into film_local values (0, \""+cutOffEnd(entries[a])+"\", \""+entries[a]+"\",\"favorite_border_black\",0)");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
System.out.println("added \""+filmsDir.get(a)+"\" to databsae");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int b=0; b<filmsStreamURL.size(); b++){
|
|
||||||
if(filmsdbStreamURL.contains(filmsStreamURL.get(b))) {
|
|
||||||
} else {
|
|
||||||
if(lastName != "" && lastName != filmsStreamData.get(b)) {
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
lastName = filmsStreamData.get(b);
|
|
||||||
JsonObject object = Json.parse(new FileReader(filmsStreamData.get(b))).asObject();
|
|
||||||
JsonArray items = object.get("entries").asArray();
|
|
||||||
System.out.println(items.size()+", "+i+"; "+b);
|
|
||||||
String streamURL = items.get(i).asObject().getString("streamUrl","");
|
|
||||||
String titel = items.get(i).asObject().getString("titel","");
|
|
||||||
|
|
||||||
if(streamURL.equals(filmsStreamURL.get(b))){
|
|
||||||
System.out.println("added \""+titel+"\"");
|
|
||||||
|
|
||||||
ps.setInt(1, items.get(i).asObject().getInt("year", 0));
|
|
||||||
ps.setInt(2, items.get(i).asObject().getInt("season", 0));
|
|
||||||
ps.setInt(3, items.get(i).asObject().getInt("episode", 0));
|
|
||||||
ps.setInt(4, 0);
|
|
||||||
ps.setString(5, items.get(i).asObject().getString("resolution", ""));
|
|
||||||
ps.setString(6, items.get(i).asObject().getString("titel",""));
|
|
||||||
ps.setString(7, items.get(i).asObject().getString("streamUrl", ""));
|
|
||||||
ps.setString(8, "favorite_border_black");
|
|
||||||
ps.setBoolean(9, false);
|
|
||||||
ps.addBatch(); // adds the entry
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ps.executeBatch();
|
|
||||||
connection.commit();
|
|
||||||
ps.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ausgeben(){
|
|
||||||
System.out.println("Outputting all entries ... \n");
|
|
||||||
try {
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
|
|
||||||
while (rs.next()) {
|
|
||||||
System.out.println(rs.getString(1));
|
|
||||||
System.out.println(rs.getString(2));
|
|
||||||
System.out.println(rs.getString(3));
|
|
||||||
System.out.println(rs.getString(4));
|
|
||||||
System.out.println(rs.getString(5)+"\n");
|
|
||||||
}
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
|
|
||||||
System.out.println("Streaming Entries: \n");
|
|
||||||
|
|
||||||
rs = stmt.executeQuery("SELECT * FROM film_streaming;");
|
|
||||||
while (rs.next()) {
|
|
||||||
System.out.println(rs.getString(1));
|
|
||||||
System.out.println(rs.getString(2));
|
|
||||||
System.out.println(rs.getString(3));
|
|
||||||
System.out.println(rs.getString(4));
|
|
||||||
System.out.println(rs.getString(5));
|
|
||||||
System.out.println(rs.getString(6));
|
|
||||||
System.out.println(rs.getString(7));
|
|
||||||
System.out.println(rs.getString(8));
|
|
||||||
System.out.println(rs.getString(9)+"\n");
|
|
||||||
}
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
System.err.println("Ups! an error occured!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//get favorite status
|
|
||||||
void getFavStatus(String name){
|
|
||||||
try{
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
ResultSet rs = stmt.executeQuery("SELECT titel, rating, favIcon FROM film_local WHERE titel = \""+name+"\";" ); //SQL Befehl
|
|
||||||
System.out.println("local:"+rs.getString("rating")+", "+rs.getString("titel")+", "+rs.getString("favIcon"));
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
}catch(SQLException e){
|
|
||||||
try {
|
|
||||||
Statement stmtS = connection.createStatement();
|
|
||||||
ResultSet rsS = stmtS.executeQuery("SELECT titel, rating, favIcon FROM film_streaming WHERE titel = \""+name+"\";" );
|
|
||||||
System.out.println("streaming:"+rsS.getString("rating")+", "+rsS.getString("titel")+", "+rsS.getString("favIcon"));
|
|
||||||
stmtS.close();
|
|
||||||
rsS.close();
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
System.out.println("Ups! an error occured!");
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
//set rating=0 and favorite_border_black
|
|
||||||
void dislike(String name,String streamUrl){
|
|
||||||
System.out.println("defavorisieren ...");
|
|
||||||
try{
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
stmt.executeUpdate("UPDATE film_local SET rating=0,favIcon='favorite_border_black' WHERE titel=\""+name+"\";");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
}catch(SQLException e){
|
|
||||||
System.out.println("Ups! an error occured!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
stmt.executeUpdate("UPDATE film_streaming SET rating=0,favIcon='favorite_border_black' WHERE streamUrl=\""+streamUrl+"\";");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
System.out.println("Ups! an error occured!");
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//set rating=1 and favorite_black
|
|
||||||
void like(String name,String streamUrl){
|
|
||||||
System.out.println("favorisieren ...");
|
|
||||||
try{
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
stmt.executeUpdate("UPDATE film_local SET rating=1,favIcon='favorite_black' WHERE titel=\""+name+"\";");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
}catch(SQLException e){
|
|
||||||
System.out.println("Ups! an error occured!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
stmt.executeUpdate("UPDATE film_streaming SET rating=1,favIcon='favorite_black' WHERE streamUrl=\""+streamUrl+"\";");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
System.out.println("Ups! an error occured!");
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCached(String streamUrl) throws SQLException{
|
|
||||||
try{
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
stmt.executeUpdate("UPDATE film_local SET cached=1 WHERE streamUrl=\""+streamUrl+"\";");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
}catch(SQLException e){
|
|
||||||
System.out.println("Ups! an error occured!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
stmt.executeUpdate("UPDATE film_streaming SET cached=1 WHERE streamUrl=\""+streamUrl+"\";");
|
|
||||||
connection.commit();
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e1) {
|
|
||||||
System.out.println("Ups! an error occured!");
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void addCache( String streamUrl, String Title, String Year, String Rated, String Released, String Runtime, String Genre, String Director,
|
|
||||||
String Writer, String Actors, String Plot, String Language, String Country, String Awards, String Metascore, String imdbRating,
|
|
||||||
String Type, String imdbVotes, String imdbID, String Poster, String Response) throws SQLException{
|
|
||||||
PreparedStatement ps = connection.prepareStatement("insert into cache values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
|
||||||
|
|
||||||
System.out.println("adding to cache: " + Title);
|
|
||||||
ps.setString(1,streamUrl);
|
|
||||||
ps.setString(2,Title);
|
|
||||||
ps.setString(3,Year);
|
|
||||||
ps.setString(4,Rated);
|
|
||||||
ps.setString(5,Released);
|
|
||||||
ps.setString(6,Runtime);
|
|
||||||
ps.setString(7,Genre);
|
|
||||||
ps.setString(8,Director);
|
|
||||||
ps.setString(9,Writer);
|
|
||||||
ps.setString(10,Actors);
|
|
||||||
ps.setString(11,Plot);
|
|
||||||
ps.setString(12,Language);
|
|
||||||
ps.setString(13,Country);
|
|
||||||
ps.setString(14,Awards);
|
|
||||||
ps.setString(15,Metascore);
|
|
||||||
ps.setString(16,imdbRating);
|
|
||||||
ps.setString(17,imdbVotes);
|
|
||||||
ps.setString(18,imdbID);
|
|
||||||
ps.setString(19,Type);
|
|
||||||
ps.setString(20,Poster);
|
|
||||||
ps.setString(21,Response);
|
|
||||||
ps.addBatch();
|
|
||||||
ps.executeBatch();
|
|
||||||
connection.commit();
|
|
||||||
ps.close();
|
|
||||||
System.out.println("done!");
|
|
||||||
}
|
|
||||||
|
|
||||||
void readCache(String streamUrl){
|
|
||||||
try{
|
|
||||||
Statement stmt = connection.createStatement();
|
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM cache WHERE streamUrl=\""+streamUrl+"\";");
|
|
||||||
ArrayList<Text> nameText = new ArrayList<Text>();
|
|
||||||
ArrayList<Text> responseText = new ArrayList<Text>();
|
|
||||||
String fontFamily = main.getFONT_FAMILY();
|
|
||||||
Image im;
|
|
||||||
int fontSize = (int) Math.round(mainWindowController.size);
|
|
||||||
int j=2;
|
|
||||||
|
|
||||||
nameText.add(0, new Text(mainWindowController.title+": "));
|
|
||||||
nameText.add(1, new Text(mainWindowController.year+": "));
|
|
||||||
nameText.add(2, new Text(mainWindowController.rating+": "));
|
|
||||||
nameText.add(3, new Text(mainWindowController.publishedOn+": "));
|
|
||||||
nameText.add(4, new Text(mainWindowController.duration+": "));
|
|
||||||
nameText.add(5, new Text(mainWindowController.genre+": "));
|
|
||||||
nameText.add(6, new Text(mainWindowController.director+": "));
|
|
||||||
nameText.add(7, new Text(mainWindowController.writer+": "));
|
|
||||||
nameText.add(8, new Text(mainWindowController.actors+": "));
|
|
||||||
nameText.add(9, new Text(mainWindowController.plot+": "));
|
|
||||||
nameText.add(10, new Text(mainWindowController.language+": "));
|
|
||||||
nameText.add(11, new Text(mainWindowController.country+": "));
|
|
||||||
nameText.add(12, new Text(mainWindowController.awards+": "));
|
|
||||||
nameText.add(13, new Text(mainWindowController.metascore+": "));
|
|
||||||
nameText.add(14, new Text(mainWindowController.imdbRating+": "));
|
|
||||||
nameText.add(15, new Text(mainWindowController.type+": "));
|
|
||||||
|
|
||||||
for(int i=0; i<15; i++){
|
|
||||||
responseText.add(new Text(rs.getString(j)+"\n"));
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
responseText.add(new Text(rs.getString(19)+"\n"));
|
|
||||||
im = new Image(new File(rs.getString(20)).toURI().toString());
|
|
||||||
|
|
||||||
stmt.close();
|
|
||||||
rs.close();
|
|
||||||
|
|
||||||
for(int i=0; i<nameText.size(); i++){
|
|
||||||
nameText.get(i).setFont(Font.font (fontFamily, FontWeight.BOLD, fontSize));
|
|
||||||
responseText.get(i).setFont(Font.font(fontFamily, fontSize));
|
|
||||||
}
|
|
||||||
|
|
||||||
mainWindowController.textFlow.getChildren().remove(0, mainWindowController.textFlow.getChildren().size());
|
|
||||||
|
|
||||||
for(int i=0;i<nameText.size(); i++){
|
|
||||||
mainWindowController.textFlow.getChildren().addAll(nameText.get(i),responseText.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
|
||||||
mainWindowController.image1.setImage(im);
|
|
||||||
}catch (Exception e){
|
|
||||||
mainWindowController.image1.setImage(new Image("resources/icons/close_black_2048x2048.png"));
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
mainWindowController.image1.setImage(im);
|
|
||||||
|
|
||||||
}catch (SQLException e) {
|
|
||||||
System.out.println("Ups! an error occured!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//removes the ending
|
|
||||||
private String cutOffEnd (String str) {
|
|
||||||
|
|
||||||
if (str == null) return null;
|
|
||||||
int pos = str.lastIndexOf(".");
|
|
||||||
if (pos == -1) return str;
|
|
||||||
return str.substring(0, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,105 +0,0 @@
|
||||||
/**
|
|
||||||
* updater for Project HomeFlix
|
|
||||||
* checks for Updates and downloads it in case there is one
|
|
||||||
*/
|
|
||||||
package org.kellerkinder.Project_HomeFlix;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import javax.swing.ProgressMonitor;
|
|
||||||
import javax.swing.ProgressMonitorInputStream;
|
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
|
||||||
|
|
||||||
import com.eclipsesource.json.Json;
|
|
||||||
import com.eclipsesource.json.JsonArray;
|
|
||||||
import com.eclipsesource.json.JsonObject;
|
|
||||||
import com.eclipsesource.json.JsonValue;
|
|
||||||
import javafx.application.Platform;
|
|
||||||
|
|
||||||
public class updater implements Runnable{
|
|
||||||
|
|
||||||
private MainWindowController mainWindowController;
|
|
||||||
private String buildNumber;
|
|
||||||
private String apiOutput;
|
|
||||||
private String updateBuildNumber; //tag_name from Github
|
|
||||||
private String browserDownloadUrl; //update download link
|
|
||||||
private String githubApi = "https://api.github.com/repos/Seil0/Project-HomeFlix/releases/latest";
|
|
||||||
|
|
||||||
|
|
||||||
public updater(MainWindowController m, String buildNumber){
|
|
||||||
mainWindowController=m;
|
|
||||||
this.buildNumber=buildNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run(){
|
|
||||||
System.out.println("check for updates ...");
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("checkingUpdates"));
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
URL githubApiUrl = new URL(githubApi);
|
|
||||||
BufferedReader ina = new BufferedReader(new InputStreamReader(githubApiUrl.openStream()));
|
|
||||||
apiOutput = ina.readLine();
|
|
||||||
ina.close();
|
|
||||||
} catch (IOException e1) {
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
mainWindowController.showErrorMsg(mainWindowController.errorUpdateV, e1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject object = Json.parse(apiOutput).asObject();
|
|
||||||
JsonArray objectAssets = Json.parse(apiOutput).asObject().get("assets").asArray();
|
|
||||||
|
|
||||||
updateBuildNumber = object.getString("tag_name", "");
|
|
||||||
// updateName = object.getString("name", "");
|
|
||||||
// updateChanges = object.getString("body", "");
|
|
||||||
for (JsonValue asset : objectAssets) {
|
|
||||||
browserDownloadUrl = asset.asObject().getString("browser_download_url", "");
|
|
||||||
|
|
||||||
}
|
|
||||||
System.out.println("Build: "+buildNumber+", Update: "+updateBuildNumber);
|
|
||||||
|
|
||||||
//Compares the program BuildNumber with the current BuildNumber if program BuildNumber < current BuildNumber then perform a update
|
|
||||||
int iversion = Integer.parseInt(buildNumber);
|
|
||||||
int iaktVersion = Integer.parseInt(updateBuildNumber.replace(".", ""));
|
|
||||||
|
|
||||||
if(iversion >= iaktVersion){
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("updateBtnNotavail"));
|
|
||||||
});
|
|
||||||
System.out.println("no update available");
|
|
||||||
}else{
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
mainWindowController.updateBtn.setText(mainWindowController.bundle.getString("updateBtnavail"));
|
|
||||||
});
|
|
||||||
System.out.println("update available");
|
|
||||||
System.out.println("download link: " + browserDownloadUrl);
|
|
||||||
try {
|
|
||||||
//open new Http connection, ProgressMonitorInputStream for downloading the data
|
|
||||||
HttpURLConnection conn = (HttpURLConnection) new URL(browserDownloadUrl).openConnection();
|
|
||||||
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Downloading...", conn.getInputStream());
|
|
||||||
ProgressMonitor pm = pmis.getProgressMonitor();
|
|
||||||
pm.setMillisToDecideToPopup(0);
|
|
||||||
pm.setMillisToPopup(0);
|
|
||||||
pm.setMinimum(0);// tell the progress bar that we start at the beginning of the stream
|
|
||||||
pm.setMaximum(conn.getContentLength());// tell the progress bar the total number of bytes we are going to read.
|
|
||||||
FileUtils.copyInputStreamToFile(pmis, new File("ProjectHomeFlix_update.jar")); //download update
|
|
||||||
org.apache.commons.io.FileUtils.copyFile(new File("ProjectHomeFlix_update.jar"), new File("ProjectHomeFlix.jar")); //TODO rename update to old name
|
|
||||||
org.apache.commons.io.FileUtils.deleteQuietly(new File("ProjectHomeFlix_update.jar")); //delete update
|
|
||||||
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
|
|
||||||
System.exit(0); //finishes itself
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
Platform.runLater(() -> {
|
|
||||||
mainWindowController.showErrorMsg(mainWindowController.errorUpdateD, e);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -20,7 +20,7 @@
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
<?import javafx.scene.text.TextFlow?>
|
<?import javafx.scene.text.TextFlow?>
|
||||||
|
|
||||||
<AnchorPane fx:id="anpane" prefHeight="600.0" prefWidth="950.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.kellerkinder.Project_HomeFlix.MainWindowController">
|
<AnchorPane fx:id="anpane" prefHeight="600.0" prefWidth="950.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="kellerkinder.HomeFlix.application.MainWindowController">
|
||||||
<children>
|
<children>
|
||||||
<ScrollPane fx:id="scrollPane" fitToWidth="true" layoutX="408.0" layoutY="44.0" prefHeight="544.0" prefWidth="320.0" AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="408.0" AnchorPane.rightAnchor="222.0" AnchorPane.topAnchor="44.0">
|
<ScrollPane fx:id="scrollPane" fitToWidth="true" layoutX="408.0" layoutY="44.0" prefHeight="544.0" prefWidth="320.0" AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="408.0" AnchorPane.rightAnchor="222.0" AnchorPane.topAnchor="44.0">
|
||||||
<content>
|
<content>
|
||||||
|
@ -100,7 +100,7 @@
|
||||||
<ChoiceBox fx:id="cbLocal" layoutX="118.0" layoutY="208.0" prefWidth="150.0" AnchorPane.leftAnchor="118.0" AnchorPane.topAnchor="208.0" />
|
<ChoiceBox fx:id="cbLocal" layoutX="118.0" layoutY="208.0" prefWidth="150.0" AnchorPane.leftAnchor="118.0" AnchorPane.topAnchor="208.0" />
|
||||||
<JFXButton fx:id="updateBtn" layoutX="16.0" layoutY="269.0" onAction="#updateBtnAction" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="253.0" />
|
<JFXButton fx:id="updateBtn" layoutX="16.0" layoutY="269.0" onAction="#updateBtnAction" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="253.0" />
|
||||||
<Label fx:id="autoUpdateLabel" layoutX="14.0" layoutY="310.0" prefHeight="17.0" text="check at startup for updates:" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="298.0" />
|
<Label fx:id="autoUpdateLabel" layoutX="14.0" layoutY="310.0" prefHeight="17.0" text="check at startup for updates:" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="298.0" />
|
||||||
<JFXToggleButton fx:id="autoupdateBtn" layoutX="14.0" layoutY="336.0" onAction="#autoupdateBtnAction" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="320.0" />
|
<JFXToggleButton fx:id="autoUpdateToggleBtn" layoutX="14.0" layoutY="336.0" onAction="#autoUpdateToggleBtnAction" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="320.0" />
|
||||||
<Label fx:id="versionLabel" layoutX="14.0" layoutY="418.0" text="Label" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="396.0" />
|
<Label fx:id="versionLabel" layoutX="14.0" layoutY="418.0" text="Label" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="396.0" />
|
||||||
<Label fx:id="settingsHead1Label" layoutX="14.0" layoutY="24.0" text="HomeFlix Settings" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="24.0">
|
<Label fx:id="settingsHead1Label" layoutX="14.0" layoutY="24.0" text="HomeFlix Settings" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="24.0">
|
||||||
<font>
|
<font>
|
||||||
|
|
|
@ -15,9 +15,9 @@ mainColorLabel = Hauptfarbe:
|
||||||
fontsizeLabel = Schriftgr\u00F6\u00DFe:
|
fontsizeLabel = Schriftgr\u00F6\u00DFe:
|
||||||
localLabel = Sprache:
|
localLabel = Sprache:
|
||||||
checkUpdates = Auf Update pr\u00FCfen
|
checkUpdates = Auf Update pr\u00FCfen
|
||||||
checkingUpdates = Es wird nach Updates gesucht...
|
updateBtnChecking = Es wird nach Updates gesucht...
|
||||||
updateBtnavail = Update verf\u00FCgbar
|
updateBtnUpdateAvailable = Update verf\u00FCgbar
|
||||||
updateBtnNotavail = Kein Update verf\u00FCgbar
|
updateBtnNoUpdateAvailable = Kein Update verf\u00FCgbar
|
||||||
autoUpdateLabel = beim Start nach Updates suchen:
|
autoUpdateLabel = beim Start nach Updates suchen:
|
||||||
version = Version:
|
version = Version:
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,9 @@ mainColorLabel = main color:
|
||||||
fontsizeLabel = font size:
|
fontsizeLabel = font size:
|
||||||
localLabel = local:
|
localLabel = local:
|
||||||
checkUpdates = check for updates
|
checkUpdates = check for updates
|
||||||
checkingUpdates = checking for updates...
|
updateBtnChecking = checking for updates...
|
||||||
updateBtnavail = update available
|
updateBtnUpdateAvailable = update available
|
||||||
updateBtnNotavail = no update available
|
updateBtnNoUpdateAvailable = no update available
|
||||||
autoUpdateLabel = check at startup for updates:
|
autoUpdateLabel = check at startup for updates:
|
||||||
version = Version:
|
version = Version:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue