HomeFlix supports more than one source directory

* HomeFlix supports more than one source directory, this is WIP!
* general code cleanup
This commit is contained in:
Jannik 2018-03-04 20:07:43 +01:00
parent f14159407f
commit 73a74917aa
7 changed files with 432 additions and 549 deletions

View File

@ -12,7 +12,7 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-9"> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
@ -22,10 +22,6 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

View File

@ -107,8 +107,7 @@ public class Main extends Application {
// startup checks // startup checks
if (!configFile.exists()) { if (!configFile.exists()) {
directory.mkdir(); directory.mkdir();
mainWindowController.setPath(firstStart()); mainWindowController.addSource(firstStart(), "local");
mainWindowController.setStreamingPath(directory.getAbsolutePath());
mainWindowController.setColor("ee3523"); mainWindowController.setColor("ee3523");
mainWindowController.setSize(FONT_SIZE); mainWindowController.setSize(FONT_SIZE);
mainWindowController.setAutoUpdate(false); mainWindowController.setAutoUpdate(false);
@ -143,14 +142,17 @@ public class Main extends Application {
// Method for first Start // Method for first Start
private String firstStart(){ private String firstStart(){
switch(System.getProperty("user.language")+"_"+System.getProperty("user.country")){ switch (System.getProperty("user.language") + "_" + System.getProperty("user.country")) {
case "en_US": bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); //us_english case "en_US":
break; bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_english
case "de_DE": bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN); //German break;
break; case "de_DE":
default: bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); //default local bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.GERMAN); // German
break; break;
} default:
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // default local
break;
}
Alert alert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser Alert alert = new Alert(AlertType.CONFIRMATION); //new alert with file-chooser
alert.setTitle("Project HomeFlix"); alert.setTitle("Project HomeFlix");

View File

@ -27,12 +27,15 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.io.Writer;
import java.math.BigInteger; import java.math.BigInteger;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
@ -46,6 +49,9 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.cemu_UI.uiElements.JFXInfoDialog; import com.cemu_UI.uiElements.JFXInfoDialog;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonArray;
import com.eclipsesource.json.JsonObject;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXColorPicker; import com.jfoenix.controls.JFXColorPicker;
import com.jfoenix.controls.JFXHamburger; import com.jfoenix.controls.JFXHamburger;
@ -54,8 +60,6 @@ import com.jfoenix.controls.JFXTextField;
import com.jfoenix.controls.JFXToggleButton; import com.jfoenix.controls.JFXToggleButton;
import com.jfoenix.transitions.hamburger.HamburgerBackArrowBasicTransition; import com.jfoenix.transitions.hamburger.HamburgerBackArrowBasicTransition;
import javafx.animation.FadeTransition;
import javafx.animation.ParallelTransition;
import javafx.animation.TranslateTransition; import javafx.animation.TranslateTransition;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
@ -90,6 +94,7 @@ import javafx.scene.paint.Color;
import javafx.scene.text.Font; 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.stage.FileChooser;
import javafx.util.Duration; import javafx.util.Duration;
import kellerkinder.HomeFlix.controller.DBController; import kellerkinder.HomeFlix.controller.DBController;
import kellerkinder.HomeFlix.controller.UpdateController; import kellerkinder.HomeFlix.controller.UpdateController;
@ -101,9 +106,6 @@ public class MainWindowController {
@FXML @FXML
private AnchorPane mainAnchorPane; private AnchorPane mainAnchorPane;
@FXML
private AnchorPane streamingSettingsAnchorPane;
@FXML @FXML
private ScrollPane settingsScrollPane; private ScrollPane settingsScrollPane;
@ -120,8 +122,8 @@ public class MainWindowController {
private TreeTableView<tableData> treeTableViewfilm; private TreeTableView<tableData> treeTableViewfilm;
@FXML @FXML
private TableView<tableData> tableViewStreamingdata; private TableView<tableData> sourcesTable;
@FXML @FXML
private TextFlow textFlow; private TextFlow textFlow;
@ -143,9 +145,6 @@ public class MainWindowController {
@FXML @FXML
private JFXButton settingsBtn; private JFXButton settingsBtn;
@FXML
private JFXButton streamingSettingsBtn;
@FXML @FXML
private JFXButton switchBtn; private JFXButton switchBtn;
@ -156,10 +155,10 @@ public class MainWindowController {
public JFXButton updateBtn; public JFXButton updateBtn;
@FXML @FXML
private JFXButton directoryBtn; private JFXButton addDirectoryBtn;
@FXML @FXML
private JFXButton streamingDirectoryBtn; private JFXButton addStreamSourceBtn;
@FXML @FXML
private JFXHamburger menuHam; private JFXHamburger menuHam;
@ -167,12 +166,6 @@ public class MainWindowController {
@FXML @FXML
private JFXToggleButton autoUpdateToggleBtn; private JFXToggleButton autoUpdateToggleBtn;
@FXML
public JFXTextField filmDirTextField;
@FXML
public JFXTextField streamingPathTextField;
@FXML @FXML
private JFXTextField searchTextField; private JFXTextField searchTextField;
@ -191,9 +184,6 @@ public class MainWindowController {
@FXML @FXML
private Label homeflixSettingsLbl; private Label homeflixSettingsLbl;
@FXML
private Label filmDirectoryLbl;
@FXML @FXML
private Label mainColorLbl; private Label mainColorLbl;
@ -208,6 +198,9 @@ public class MainWindowController {
@FXML @FXML
private Label branchLbl; private Label branchLbl;
@FXML
private Label sourcesLbl;
@FXML @FXML
private Label versionLbl; private Label versionLbl;
@ -218,7 +211,7 @@ public class MainWindowController {
private ImageView imv1; private ImageView imv1;
@FXML @FXML
TreeItem<tableData> root = new TreeItem<>(new tableData(1, 1, 1, 5.0, "1", "filme", "1", imv1, false)); public TreeItem<tableData> root = new TreeItem<>(new tableData(1, 1, 1, 5.0, "1", "filme", "1", imv1, false));
@FXML @FXML
TreeTableColumn<tableData, ImageView> columnRating = new TreeTableColumn<>("Rating"); TreeTableColumn<tableData, ImageView> columnRating = new TreeTableColumn<>("Rating");
@FXML @FXML
@ -235,15 +228,14 @@ public class MainWindowController {
TreeTableColumn<tableData, Integer> columnEpisode = new TreeTableColumn<>("Episode"); TreeTableColumn<tableData, Integer> columnEpisode = new TreeTableColumn<>("Episode");
@FXML @FXML
private TreeItem<tableData> streamingRoot =new TreeItem<>(new tableData(1 ,1 ,1 ,1.0 ,"1" ,"filme" ,"1", imv1, false)); public TreeItem<tableData> streamingRoot =new TreeItem<>(new tableData(1 ,1 ,1 ,1.0 ,"1" ,"filme" ,"1", imv1, false)); // TODO make private
@FXML @FXML
private TableColumn<tableData, String> dataNameColumn = new TableColumn<>("Datei Name"); private TableColumn<tableData, String> sourceColumn;
@FXML @FXML
private TableColumn<tableData, String> dataNameEndColumn = new TableColumn<>("Datei Name mit Endung"); private TableColumn<tableData, String> modeColumn;
private boolean menuTrue = false; private boolean menuTrue = false;
private boolean settingsTrue = false; private boolean settingsTrue = false;
private boolean streamingSettingsTrue = false;
private boolean autoUpdate = false; private boolean autoUpdate = false;
private boolean useBeta = false; private boolean useBeta = false;
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName()); private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
@ -262,7 +254,6 @@ public class MainWindowController {
private String errorSave; private String errorSave;
private String infoText; private String infoText;
private String vlcNotInstalled; private String vlcNotInstalled;
private String path;
private String streamingPath; private String streamingPath;
private String color; private String color;
private String name; private String name;
@ -275,8 +266,6 @@ public class MainWindowController {
private int last; private int last;
private int selected; private int selected;
private int next; private int next;
private File selectedFolder;
private File selectedStreamingFolder;
private ResourceBundle bundle; private ResourceBundle bundle;
private ObservableList<tableData> filterData = FXCollections.observableArrayList(); private ObservableList<tableData> filterData = FXCollections.observableArrayList();
@ -284,7 +273,7 @@ public class MainWindowController {
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta"); private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
private ObservableList<tableData> localFilms = FXCollections.observableArrayList(); private ObservableList<tableData> localFilms = FXCollections.observableArrayList();
private ObservableList<tableData> streamingFilms = FXCollections.observableArrayList(); private ObservableList<tableData> streamingFilms = FXCollections.observableArrayList();
private ObservableList<tableData> streamingData = FXCollections.observableArrayList(); private ObservableList<tableData> sourcesList = FXCollections.observableArrayList();
private ImageView skip_previous_white = new ImageView(new Image("icons/ic_skip_previous_white_18dp_1x.png")); private ImageView skip_previous_white = new ImageView(new Image("icons/ic_skip_previous_white_18dp_1x.png"));
private ImageView skip_previous_black = new ImageView(new Image("icons/ic_skip_previous_black_18dp_1x.png")); private ImageView skip_previous_black = new ImageView(new Image("icons/ic_skip_previous_black_18dp_1x.png"));
private ImageView skip_next_white = new ImageView(new Image("icons/ic_skip_next_white_18dp_1x.png")); private ImageView skip_next_white = new ImageView(new Image("icons/ic_skip_next_white_18dp_1x.png"));
@ -313,11 +302,10 @@ public class MainWindowController {
void init() { void init() {
loadSettings(); loadSettings();
loadStreamingSettings();
checkAutoUpdate(); checkAutoUpdate();
initTabel(); initTabel();
initActions(); initActions();
initUI(); initUI();
} }
//Initialize the tables (treeTableViewfilm and tableViewStreamingdata) //Initialize the tables (treeTableViewfilm and tableViewStreamingdata)
@ -327,8 +315,6 @@ public class MainWindowController {
columnRating.setMaxWidth(80); columnRating.setMaxWidth(80);
columnTitel.setMaxWidth(260); columnTitel.setMaxWidth(260);
columnStreamUrl.setMaxWidth(0); columnStreamUrl.setMaxWidth(0);
dataNameColumn.setPrefWidth(150);
dataNameEndColumn.setPrefWidth(220);
columnRating.setStyle("-fx-alignment: CENTER;"); columnRating.setStyle("-fx-alignment: CENTER;");
treeTableViewfilm.setRoot(root); treeTableViewfilm.setRoot(root);
@ -353,119 +339,80 @@ public class MainWindowController {
treeTableViewfilm.getColumns().add(columnSeason); treeTableViewfilm.getColumns().add(columnSeason);
treeTableViewfilm.getColumns().add(columnEpisode); treeTableViewfilm.getColumns().add(columnEpisode);
treeTableViewfilm.getColumns().get(2).setVisible(false); //hide columnStreamUrl (column with file URL, important for opening a file/stream) treeTableViewfilm.getColumns().get(2).setVisible(false); //hide columnStreamUrl (column with file URL, important for opening a file/stream)
//Change-listener for treeTableViewfilm
treeTableViewfilm.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() {
@Override
public void changed(ObservableValue<?> observable, Object oldVal, Object newVal){
// last = selected; //for auto-play
selected = treeTableViewfilm.getSelectionModel().getSelectedIndex(); //get selected item
last = selected - 1;
next = selected + 1;
name = columnTitel.getCellData(selected); //get name of selected item
datPath = columnStreamUrl.getCellData(selected); //get file path of selected item
if(mode.equals("local")){
if(localFilms.get(selected).getCached()==true){
LOGGER.info("loading from cache: "+name);
dbController.readCache(datPath);
}else{
ApiQuery.startQuery(name,datPath); // start api query
}
}else{
LOGGER.info(streamingFilms.size());
if(streamingFilms.get(selected).getCached()==true){
LOGGER.info("loading from cache: "+name);
dbController.readCache(datPath);
}else{
ApiQuery.startQuery(name,datPath); // start api query
}
}
}
});
//context menu for treeTableViewfilm //context menu for treeTableViewfilm
treeTableViewfilm.setContextMenu(menu); treeTableViewfilm.setContextMenu(menu);
//Streaming-Settings Table // sourcesTreeTable
dataNameColumn.setCellValueFactory(cellData -> cellData.getValue().titleProperty()); sourceColumn.setCellValueFactory(cellData -> cellData.getValue().titleProperty());
dataNameEndColumn.setCellValueFactory(cellData -> cellData.getValue().streamUrlProperty()); modeColumn.setCellValueFactory(cellData -> cellData.getValue().streamUrlProperty());
sourcesTable.setItems(sourcesList);
tableViewStreamingdata.getColumns().add(dataNameColumn);
tableViewStreamingdata.getColumns().add(dataNameEndColumn);
tableViewStreamingdata.setItems(streamingData);
} }
//Initializing the actions //Initializing the actions
private void initActions(){ private void initActions() {
HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam); HamburgerBackArrowBasicTransition burgerTask = new HamburgerBackArrowBasicTransition(menuHam);
menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e)->{ menuHam.addEventHandler(MouseEvent.MOUSE_PRESSED, (e) -> {
if(menuTrue == false){ if (menuTrue == false) {
sideMenuSlideIn(); sideMenuSlideIn();
burgerTask.setRate(1.0); burgerTask.setRate(1.0);
burgerTask.play(); burgerTask.play();
menuTrue = true; menuTrue = true;
}else{ } else {
sideMenuSlideOut(); sideMenuSlideOut();
burgerTask.setRate(-1.0); burgerTask.setRate(-1.0);
burgerTask.play(); burgerTask.play();
menuTrue = false; menuTrue = false;
} }
if(settingsTrue == true){ if (settingsTrue == true) {
settingsScrollPane.setVisible(false); settingsScrollPane.setVisible(false);
setPath(filmDirTextField.getText());
saveSettings(); saveSettings();
settingsTrue = false; settingsTrue = false;
} }
if(streamingSettingsTrue == true){
streamingSettingsAnchorPane.setVisible(false);
streamingSettingsTrue = false;
}
}); });
searchTextField.textProperty().addListener(new ChangeListener<String>() { searchTextField.textProperty().addListener(new ChangeListener<String>() {
@Override @Override
public void changed(ObservableValue<? extends String> observable,String oldValue, String newValue) { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
ObservableList<tableData> helpData; ObservableList<tableData> helpData;
filterData.removeAll(filterData); filterData.removeAll(filterData);
root.getChildren().remove(0,root.getChildren().size()); root.getChildren().remove(0, root.getChildren().size());
if(mode.equals("local")){ if (mode.equals("local")) {
helpData = localFilms; helpData = localFilms;
}else{ } else {
helpData = streamingFilms; helpData = streamingFilms;
} }
for(int i = 0; i < helpData.size(); i++){ for (int i = 0; i < helpData.size(); i++) {
if(helpData.get(i).getTitle().toLowerCase().contains(searchTextField.getText().toLowerCase())){ if (helpData.get(i).getTitle().toLowerCase().contains(searchTextField.getText().toLowerCase())) {
filterData.add(helpData.get(i)); //add data from newDaten to filteredData where title contains search input filterData.add(helpData.get(i)); // add data from newDaten to filteredData where title contains search input
} }
} }
for(int i = 0; i < filterData.size(); i++){ for (int i = 0; i < filterData.size(); i++) {
root.getChildren().add(new TreeItem<tableData>(filterData.get(i))); //add filtered data to root node after search root.getChildren().add(new TreeItem<tableData>(filterData.get(i))); // add filtered data to root node after search
} }
if(searchTextField.getText().hashCode()== hashA){ if (searchTextField.getText().hashCode() == hashA) {
setColor("000000"); setColor("000000");
applyColor(); applyColor();
} }
} }
}); });
languageChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { languageChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override @Override
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) { public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
String local = languageChoisBox.getItems().get((int) new_value).toString(); String local = languageChoisBox.getItems().get((int) new_value).toString();
local = local.substring(local.length()-6,local.length()-1); //reading only en_US from English (en_US) local = local.substring(local.length() - 6, local.length() - 1); // reading only en_US from English (en_US)
setLocal(local); setLocal(local);
setLocalUI(); setLocalUI();
saveSettings(); saveSettings();
} }
}); });
branchChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() { branchChoisBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override @Override
public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) { public void changed(ObservableValue<? extends Number> ov, Number value, Number new_value) {
if (branchChoisBox.getItems().get((int) new_value).toString() == "beta") { if (branchChoisBox.getItems().get((int) new_value).toString() == "beta") {
@ -477,28 +424,26 @@ public class MainWindowController {
} }
}); });
fontsizeSlider.valueProperty().addListener(new ChangeListener<Number>() { fontsizeSlider.valueProperty().addListener(new ChangeListener<Number>() {
@Override @Override
public void changed(ObservableValue<? extends Number> ov,Number old_val, Number new_val) { public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
setSize(fontsizeSlider.getValue()); setSize(fontsizeSlider.getValue());
if (name != null) {
if(name != null){
dbController.readCache(datPath); dbController.readCache(datPath);
} }
// ta1.setFont(Font.font("System", size));
// ta1.setFont(Font.font("System", size));
saveSettings(); saveSettings();
} }
}); });
like.setOnAction(new EventHandler<ActionEvent>() { like.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
if(mode.equals("streaming")){ if (mode.equals("streaming")) {
dbController.like(name,streamingFilms.get(selected).getStreamUrl()); dbController.like(name, streamingFilms.get(selected).getStreamUrl());
}else{ } else {
dbController.like(name,localFilms.get(selected).getStreamUrl()); dbController.like(name, localFilms.get(selected).getStreamUrl());
} }
dbController.getFavStatus(name); dbController.getFavStatus(name);
try { try {
dbController.refresh(name, selected); dbController.refresh(name, selected);
@ -507,78 +452,108 @@ public class MainWindowController {
} }
refreshTable(); refreshTable();
} }
}); });
dislike.setOnAction(new EventHandler<ActionEvent>() { dislike.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
if(mode.equals("streaming")){ if (mode.equals("streaming")) {
dbController.dislike(name,streamingFilms.get(selected).getStreamUrl()); dbController.dislike(name, streamingFilms.get(selected).getStreamUrl());
}else{ } else {
dbController.dislike(name,localFilms.get(selected).getStreamUrl()); dbController.dislike(name, localFilms.get(selected).getStreamUrl());
} }
dbController.getFavStatus(name); dbController.getFavStatus(name);
try { try {
dbController.refresh(name, selected); dbController.refresh(name, selected);
} catch (SQLException e) { } catch (SQLException e) {
LOGGER.error("There was a problem with the like/dislike function!",e); LOGGER.error("There was a problem with the like/dislike function!", e);
} }
refreshTable(); refreshTable();
} }
}); });
/** /**
* FIXME fix bug when sort by ASCENDING, wrong order * FIXME fix bug when sort by ASCENDING, wrong order
*/ */
columnRating.sortTypeProperty().addListener(new ChangeListener<SortType>() { columnRating.sortTypeProperty().addListener(new ChangeListener<SortType>() {
@Override @Override
public void changed(ObservableValue<? extends SortType> paramObservableValue, SortType paramT1, SortType paramT2) { public void changed(ObservableValue<? extends SortType> paramObservableValue, SortType paramT1,
LOGGER.info("NAME Clicked -- sortType = " + paramT1 + ", SortType=" + paramT2); SortType paramT2) {
ArrayList<Integer> fav_true = new ArrayList<Integer>(); LOGGER.info("NAME Clicked -- sortType = " + paramT1 + ", SortType=" + paramT2);
ArrayList<Integer> fav_false = new ArrayList<Integer>(); ArrayList<Integer> fav_true = new ArrayList<Integer>();
ObservableList<tableData> helpData; ArrayList<Integer> fav_false = new ArrayList<Integer>();
filterData.removeAll(filterData); ObservableList<tableData> helpData;
// treeTableViewfilm.getSelectionModel().clearSelection(selected); filterData.removeAll(filterData);
root.getChildren().remove(0,root.getChildren().size()); // treeTableViewfilm.getSelectionModel().clearSelection(selected);
root.getChildren().remove(0, root.getChildren().size());
if(mode.equals("local")){
helpData = localFilms; if (mode.equals("local")) {
}else{ helpData = localFilms;
helpData = streamingFilms; } else {
} helpData = streamingFilms;
}
for(int i = 0;i<helpData.size();i++){ for (int i = 0; i < helpData.size(); i++) {
if(helpData.get(i).getRating()==1.0){ if (helpData.get(i).getRating() == 1.0) {
fav_true.add(i); fav_true.add(i);
}else{ } else {
fav_false.add(i); fav_false.add(i);
} }
} }
if(paramT2.toString().equals("DESCENDING")){ if (paramT2.toString().equals("DESCENDING")) {
LOGGER.info("Absteigend"); //Debug, delete? LOGGER.info("Absteigend"); // Debug, delete?
for(int i = 0;i<fav_true.size();i++){ for (int i = 0; i < fav_true.size(); i++) {
filterData.add(helpData.get(fav_true.get(i))); filterData.add(helpData.get(fav_true.get(i)));
} }
for(int i = 0;i<fav_false.size();i++){ for (int i = 0; i < fav_false.size(); i++) {
filterData.add(helpData.get(fav_false.get(i))); filterData.add(helpData.get(fav_false.get(i)));
} }
}else{ } else {
for(int i = 0;i<fav_false.size();i++){ for (int i = 0; i < fav_false.size(); i++) {
filterData.add(helpData.get(fav_false.get(i))); filterData.add(helpData.get(fav_false.get(i)));
} }
for(int i = 0;i<fav_true.size();i++){ for (int i = 0; i < fav_true.size(); i++) {
filterData.add(helpData.get(fav_true.get(i))); filterData.add(helpData.get(fav_true.get(i)));
} }
} }
LOGGER.info(filterData.size()); //Debug, delete? LOGGER.info(filterData.size()); // Debug, delete?
for(int i = 0; i < filterData.size(); i++){ for (int i = 0; i < filterData.size(); i++) {
// LOGGER.info(filterData.get(i).getTitle()+"; "+filterData.get(i).getRating()); // Debugging // LOGGER.info(filterData.get(i).getTitle()+"; "+filterData.get(i).getRating()); // Debugging
root.getChildren().add(new TreeItem<tableData>(filterData.get(i))); //add filtered data to root node after search root.getChildren().add(new TreeItem<tableData>(filterData.get(i))); // add filtered data to root node after search
} }
} }
}); });
// Change-listener for treeTableViewfilm
treeTableViewfilm.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Object>() {
@Override
public void changed(ObservableValue<?> observable, Object oldVal, Object newVal) {
// last = selected; //for auto-play
selected = treeTableViewfilm.getSelectionModel().getSelectedIndex(); // get selected item
last = selected - 1;
next = selected + 1;
name = columnTitel.getCellData(selected); // get name of selected item
datPath = columnStreamUrl.getCellData(selected); // get file path of selected item
if (mode.equals("local")) {
if (localFilms.get(selected).getCached() == true) {
LOGGER.info("loading from cache: " + name);
dbController.readCache(datPath);
} else {
ApiQuery.startQuery(name, datPath); // start api query
}
} else {
LOGGER.info(streamingFilms.size());
if (streamingFilms.get(selected).getCached() == true) {
LOGGER.info("loading from cache: " + name);
dbController.readCache(datPath);
} else {
ApiQuery.startQuery(name, datPath); // start api query
}
}
}
});
} }
// initialize UI elements // initialize UI elements
@ -587,7 +562,6 @@ public class MainWindowController {
debugBtn.setDisable(true); // debugging button for tests debugBtn.setDisable(true); // debugging button for tests
debugBtn.setVisible(false); debugBtn.setVisible(false);
filmDirTextField.setText(getPath());
versionLbl.setText("Version: " + version + " (Build: " + buildNumber + ")"); versionLbl.setText("Version: " + version + " (Build: " + buildNumber + ")");
fontsizeSlider.setValue(getSize()); fontsizeSlider.setValue(getSize());
colorPicker.setValue(Color.valueOf(getColor())); colorPicker.setValue(Color.valueOf(getColor()));
@ -643,14 +617,14 @@ public class MainWindowController {
vlcInfoDialog.show(); vlcInfoDialog.show();
}else{ }else{
try { try {
Runtime.getRuntime().exec(new String[] { "vlc", getPath()+"/"+ datPath}); Runtime.getRuntime().exec(new String[] { "vlc", datPath}); // TODO switch to ProcessBuilder
} catch (IOException e) { } catch (IOException e) {
showErrorMsg(errorPlay,e); showErrorMsg(errorPlay,e);
} }
} }
}else if(System.getProperty("os.name").contains("Windows") || System.getProperty("os.name").contains("Mac OS X")){ }else if(System.getProperty("os.name").contains("Windows") || System.getProperty("os.name").contains("Mac OS X")){
try { try {
Desktop.getDesktop().open(new File(getPath()+"\\"+ datPath)); Desktop.getDesktop().open(new File(datPath));
} catch (IOException e) { } catch (IOException e) {
showErrorMsg(errorPlay,e); showErrorMsg(errorPlay,e);
} }
@ -665,11 +639,12 @@ public class MainWindowController {
@FXML @FXML
private void openfolderbtnclicked(){ private void openfolderbtnclicked(){
try { //TODO rework
Desktop.getDesktop().open(new File(getPath())); //open path when button is clicked // try {
} catch (IOException e) { // Desktop.getDesktop().open(new File(getPath())); //open path when button is clicked
e.printStackTrace(); // } catch (IOException e) {
} // e.printStackTrace();
// }
} }
@FXML @FXML
@ -693,38 +668,15 @@ public class MainWindowController {
@FXML @FXML
private void settingsBtnclicked(){ private void settingsBtnclicked(){
if(settingsTrue == false){ if(settingsTrue == false){
if(streamingSettingsTrue == true){
streamingSettingsAnchorPane.setVisible(false);
streamingSettingsTrue = false;
}
settingsScrollPane.setVisible(true); settingsScrollPane.setVisible(true);
settingsTrue = true; settingsTrue = true;
}else{ }else{
settingsScrollPane.setVisible(false); settingsScrollPane.setVisible(false);
setPath(filmDirTextField.getText());
saveSettings(); saveSettings();
settingsTrue = false; settingsTrue = false;
} }
} }
/**
* TODO additional info about the "streaming.json"
*/
@FXML
private void streamingSettingsBtnclicked(){
if(streamingSettingsTrue == false){
if(settingsTrue == true){
settingsScrollPane.setVisible(false);
settingsTrue = false;
}
streamingSettingsAnchorPane.setVisible(true);
streamingSettingsTrue = true;
}else{
streamingSettingsAnchorPane.setVisible(false);
streamingSettingsTrue = false;
}
}
@FXML @FXML
private void switchBtnclicked(){ private void switchBtnclicked(){
if(mode.equals("local")){ //switch to streaming mode if(mode.equals("local")){ //switch to streaming mode
@ -738,41 +690,38 @@ public class MainWindowController {
root.getChildren().remove(0,root.getChildren().size()); root.getChildren().remove(0,root.getChildren().size());
addDataUI(); addDataUI();
settingsScrollPane.setVisible(false); settingsScrollPane.setVisible(false);
streamingSettingsAnchorPane.setVisible(false);
sideMenuSlideOut(); //disables side-menu sideMenuSlideOut(); //disables side-menu
menuTrue = false; menuTrue = false;
settingsTrue = false; settingsTrue = false;
streamingSettingsTrue = false;
} }
@FXML @FXML
private void debugBtnclicked(){ private void debugBtnclicked(){
//for testing //for testing
} }
@FXML @FXML
private void filmDirTextFieldAction(){ private void addDirectoryBtnAction(){
setPath(filmDirTextField.getText()); File selectedFolder = directoryChooser.showDialog(null);
saveSettings(); if (selectedFolder != null && selectedFolder.exists()) {
addSource(selectedFolder.getPath(), "local");
dbController.refreshDataBase();
} else {
LOGGER.error("The selected folder dosen't exist!");
}
} }
@FXML @FXML
private void directoryBtnAction(){ private void addStreamSourceBtnAction(){
selectedFolder = directoryChooser.showDialog(null); FileChooser fileChooser = new FileChooser();
if(selectedFolder == null){ fileChooser.setTitle("Open Resource File");
LOGGER.warn("No Directory selected"); File selectedFile = fileChooser.showOpenDialog(main.getPrimaryStage());
}else{ if (selectedFile != null && selectedFile.exists()) {
setPath(selectedFolder.getAbsolutePath()); addSource(selectedFile.getPath(), "local");
saveSettings(); dbController.refreshDataBase();
filmDirTextField.setText(getPath()); } else {
try { LOGGER.error("The selected file dosen't exist!");
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again }
System.exit(0); //finishes itself
} catch (IOException e) {
LOGGER.error("error while restarting HomeFlix", e);
}
}
} }
@FXML @FXML
@ -799,29 +748,6 @@ public class MainWindowController {
saveSettings(); saveSettings();
} }
@FXML
private void streamingPathTextFieldAction(){
//
}
@FXML
private void streamingDirectoryBtnAction(){
selectedStreamingFolder = directoryChooser.showDialog(null);
if(selectedStreamingFolder == null){
LOGGER.warn("No Directory selected");
}else{
setStreamingPath(selectedStreamingFolder.getAbsolutePath());
saveSettings();
streamingPathTextField.setText(getStreamingPath());
try {
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); //start again
System.exit(0); //finishes itself
} catch (IOException e) {
LOGGER.error("error while restarting HomeFlix", e);
}
}
}
private void refreshTable(){ private void refreshTable(){
if(mode.equals("local")){ if(mode.equals("local")){
root.getChildren().set(selected, new TreeItem<tableData>(localFilms.get(selected))); root.getChildren().set(selected, new TreeItem<tableData>(localFilms.get(selected)));
@ -858,32 +784,28 @@ public class MainWindowController {
} }
} }
void loadStreamingSettings() { public void addSourceToTable(String path, String mode) {
if (getStreamingPath().equals("") || getStreamingPath().equals(null)) { sourcesList.add(new tableData(1, 1, 1, 5.0, "1", path, mode, imv1, false));
LOGGER.warn("Kein Pfad angegeben"); streamingRoot.getChildren().add(new TreeItem<tableData>(sourcesList.get(sourcesList.size() - 1))); // adds data to root-node
} else {
String[] entries = new File(getStreamingPath()).list();
for (int i = 0; i < entries.length; i++) {
if (entries[i].endsWith(".json")) {
String titel = ohneEndung(entries[i]);
String data = entries[i];
streamingData.add(new tableData(1, 1, 1, 5.0, "1", titel, data, imv1, false));
}
}
for (int i = 0; i < streamingData.size(); i++) {
streamingRoot.getChildren().add(new TreeItem<tableData>(streamingData.get(i))); // adds data to root-node
}
}
} }
// removes the ending public void addSource(String path, String mode) {
private String ohneEndung(String str) { JsonObject source = null;
if (str == null) JsonArray newsources = null;
return null;
int pos = str.lastIndexOf("."); try {
if (pos == -1) // read old array
return str; newsources = Json.parse(new FileReader(main.getDirectory() + "/sources.json")).asArray();
return str.substring(0, pos);
// add new source
Writer writer = new FileWriter(main.getDirectory() + "/sources.json");
source = Json.object().add("path", path).add("mode", mode);
newsources.add(source);
newsources.writeTo(writer);
writer.close();
} catch (IOException e) {
LOGGER.error(e);
}
} }
//set color of UI-Elements //set color of UI-Elements
@ -897,17 +819,15 @@ public class MainWindowController {
sideMenuVBox.setStyle(style); sideMenuVBox.setStyle(style);
topHBox.setStyle(style); topHBox.setStyle(style);
searchTextField.setFocusColor(Color.valueOf(getColor())); searchTextField.setFocusColor(Color.valueOf(getColor()));
filmDirTextField.setFocusColor(Color.valueOf(getColor()));
if (icolor.compareTo(ccolor) == -1) { if (icolor.compareTo(ccolor) == -1) {
dialogBtnStyle = btnStyleWhite; dialogBtnStyle = btnStyleWhite;
settingsBtn.setStyle("-fx-text-fill: WHITE;"); settingsBtn.setStyle("-fx-text-fill: WHITE;");
streamingSettingsBtn.setStyle("-fx-text-fill: WHITE;");
switchBtn.setStyle("-fx-text-fill: WHITE;"); switchBtn.setStyle("-fx-text-fill: WHITE;");
aboutBtn.setStyle("-fx-text-fill: WHITE;"); aboutBtn.setStyle("-fx-text-fill: WHITE;");
debugBtn.setStyle("-fx-text-fill: WHITE;"); debugBtn.setStyle("-fx-text-fill: WHITE;");
directoryBtn.setStyle(btnStyleWhite); addDirectoryBtn.setStyle(btnStyleWhite);
streamingDirectoryBtn.setStyle(btnStyleWhite); addStreamSourceBtn.setStyle(btnStyleWhite);
updateBtn.setStyle(btnStyleWhite); updateBtn.setStyle(btnStyleWhite);
playbtn.setStyle(btnStyleWhite); playbtn.setStyle(btnStyleWhite);
openfolderbtn.setStyle(btnStyleWhite); openfolderbtn.setStyle(btnStyleWhite);
@ -920,12 +840,11 @@ public class MainWindowController {
} else { } else {
dialogBtnStyle = btnStyleBlack; dialogBtnStyle = btnStyleBlack;
settingsBtn.setStyle("-fx-text-fill: BLACK;"); settingsBtn.setStyle("-fx-text-fill: BLACK;");
streamingSettingsBtn.setStyle("-fx-text-fill: BLACK;");
switchBtn.setStyle("-fx-text-fill: BLACK;"); switchBtn.setStyle("-fx-text-fill: BLACK;");
aboutBtn.setStyle("-fx-text-fill: BLACK;"); aboutBtn.setStyle("-fx-text-fill: BLACK;");
debugBtn.setStyle("-fx-text-fill: BLACK;"); debugBtn.setStyle("-fx-text-fill: BLACK;");
directoryBtn.setStyle(btnStyleBlack); addDirectoryBtn.setStyle(btnStyleBlack);
streamingDirectoryBtn.setStyle(btnStyleBlack); addStreamSourceBtn.setStyle(btnStyleBlack);
updateBtn.setStyle(btnStyleBlack); updateBtn.setStyle(btnStyleBlack);
playbtn.setStyle(btnStyleBlack); playbtn.setStyle(btnStyleBlack);
openfolderbtn.setStyle(btnStyleBlack); openfolderbtn.setStyle(btnStyleBlack);
@ -944,36 +863,21 @@ public class MainWindowController {
} }
} }
// slide in in 400ms
private void sideMenuSlideIn() { private void sideMenuSlideIn() {
sideMenuVBox.setVisible(true); sideMenuVBox.setVisible(true);
// fade in from 40% to 100% opacity in 400ms
FadeTransition fadeTransition = new FadeTransition(Duration.millis(400), sideMenuVBox);
fadeTransition.setFromValue(0.4);
fadeTransition.setToValue(1.0);
// slide in in 400ms
TranslateTransition translateTransition = new TranslateTransition(Duration.millis(400), sideMenuVBox); TranslateTransition translateTransition = new TranslateTransition(Duration.millis(400), sideMenuVBox);
translateTransition.setFromX(-150); translateTransition.setFromX(-150);
translateTransition.setToX(0); translateTransition.setToX(0);
// in case both animations are used (add (fadeTransition, translateTransition) in the second line under this command) translateTransition.play();
ParallelTransition parallelTransition = new ParallelTransition();
parallelTransition.getChildren().addAll(translateTransition);// (fadeTransition, translateTransition);
parallelTransition.play();
} }
// slide out in 400ms
private void sideMenuSlideOut() { private void sideMenuSlideOut() {
// sideMenuVBox.setVisible(false);
// fade out from 100% to 40% opacity in 400ms
FadeTransition fadeTransition = new FadeTransition(Duration.millis(400), sideMenuVBox);
fadeTransition.setFromValue(1.0);
fadeTransition.setToValue(0.4);
// slide out in 400ms
TranslateTransition translateTransition = new TranslateTransition(Duration.millis(400), sideMenuVBox); TranslateTransition translateTransition = new TranslateTransition(Duration.millis(400), sideMenuVBox);
translateTransition.setFromX(0); translateTransition.setFromX(0);
translateTransition.setToX(-150); translateTransition.setToX(-150);
// in case both animations are used (add (fadeTransition, translateTransition) in the second line under this command) translateTransition.play();
ParallelTransition parallelTransition = new ParallelTransition();
parallelTransition.getChildren().addAll(translateTransition);// (fadeTransition, translateTransition);
parallelTransition.play();
} }
void setLocalUI() { void setLocalUI() {
@ -993,14 +897,11 @@ public class MainWindowController {
} }
aboutBtn.setText(getBundle().getString("info")); aboutBtn.setText(getBundle().getString("info"));
settingsBtn.setText(getBundle().getString("settings")); settingsBtn.setText(getBundle().getString("settings"));
streamingSettingsBtn.setText(getBundle().getString("streamingSettings"));
filmDirTextField.setPromptText(getBundle().getString("filmDirTextField"));
streamingPathTextField.setPromptText(getBundle().getString("filmDirTextField"));
searchTextField.setPromptText(getBundle().getString("tfSearch")); searchTextField.setPromptText(getBundle().getString("tfSearch"));
openfolderbtn.setText(getBundle().getString("openFolder")); openfolderbtn.setText(getBundle().getString("openFolder"));
updateBtn.setText(getBundle().getString("checkUpdates")); updateBtn.setText(getBundle().getString("checkUpdates"));
directoryBtn.setText(getBundle().getString("chooseFolder")); addDirectoryBtn.setText(getBundle().getString("addDirectory"));
streamingDirectoryBtn.setText(getBundle().getString("chooseFolder")); addStreamSourceBtn.setText(getBundle().getString("addStreamSource"));
homeflixSettingsLbl.setText(getBundle().getString("homeflixSettingsLbl")); homeflixSettingsLbl.setText(getBundle().getString("homeflixSettingsLbl"));
mainColorLbl.setText(getBundle().getString("mainColorLbl")); mainColorLbl.setText(getBundle().getString("mainColorLbl"));
fontsizeLbl.setText(getBundle().getString("fontsizeLbl")); fontsizeLbl.setText(getBundle().getString("fontsizeLbl"));
@ -1059,7 +960,6 @@ public class MainWindowController {
public void saveSettings() { public void saveSettings() {
LOGGER.info("saving settings ..."); LOGGER.info("saving settings ...");
try { try {
props.setProperty("path", getPath()); // writes path into property
props.setProperty("color", getColor()); props.setProperty("color", getColor());
props.setProperty("autoUpdate", String.valueOf(isAutoUpdate())); props.setProperty("autoUpdate", String.valueOf(isAutoUpdate()));
props.setProperty("useBeta", String.valueOf(isUseBeta())); props.setProperty("useBeta", String.valueOf(isUseBeta()));
@ -1085,12 +985,12 @@ public class MainWindowController {
InputStream inputStream = new FileInputStream(main.getConfigFile()); InputStream inputStream = new FileInputStream(main.getConfigFile());
props.loadFromXML(inputStream); // new input-stream from .xml props.loadFromXML(inputStream); // new input-stream from .xml
try { // try {
setPath(props.getProperty("path")); // read path from property // setPath(props.getProperty("path")); // read path from property
} catch (Exception e) { // } catch (Exception e) {
LOGGER.error("cloud not load path", e); // LOGGER.error("cloud not load path", e);
setPath(""); // setPath("");
} // }
try { try {
setStreamingPath(props.getProperty("streamingPath")); setStreamingPath(props.getProperty("streamingPath"));
@ -1198,14 +1098,6 @@ public class MainWindowController {
return color; return color;
} }
public void setPath(String input) {
this.path = input;
}
public String getPath() {
return path;
}
public void setStreamingPath(String input) { public void setStreamingPath(String input) {
this.streamingPath = input; this.streamingPath = input;
} }
@ -1270,12 +1162,12 @@ public class MainWindowController {
this.streamingFilms = streamingFilms; this.streamingFilms = streamingFilms;
} }
public ObservableList<tableData> getStreamingData() { public ObservableList<tableData> getSourcesList() {
return streamingData; return sourcesList;
} }
public void setStreamingData(ObservableList<tableData> streamingData) { public void setSourcesList(ObservableList<tableData> sourcesList) {
this.streamingData = streamingData; this.sourcesList = sourcesList;
} }
public String getRatingSortType() { public String getRatingSortType() {

View File

@ -64,27 +64,26 @@ public class DBController {
private Image favorite_black = new Image("icons/ic_favorite_black_18dp_1x.png"); 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 Image favorite_border_black = new Image("icons/ic_favorite_border_black_18dp_1x.png");
private List<String> filmsdbAll = new ArrayList<String>(); private List<String> filmsdbAll = new ArrayList<String>();
private List<String> filmsdbDir = new ArrayList<String>(); private List<String> filmsdbDir = new ArrayList<String>(); // needed
private List<String> filmsdbStream = new ArrayList<String>(); private List<String> filmsdbStream = new ArrayList<String>();
private List<String> filmsdbStreamURL = new ArrayList<String>(); private List<String> filmsdbStreamURL = new ArrayList<String>(); // needed
private List<String> filmsAll = new ArrayList<String>(); private List<String> filmsAll = new ArrayList<String>();
private List<String> filmsDir = new ArrayList<String>(); // private List<String> filmsDirURL = new ArrayList<String>();
private List<String> filmsDirURL = new ArrayList<String>();
private List<String> filmsStream = new ArrayList<String>(); private List<String> filmsStream = new ArrayList<String>();
private List<String> filmsStreamURL = new ArrayList<String>(); private List<String> filmsStreamURL = new ArrayList<String>(); // needed
private List<String> filmsStreamData = new ArrayList<String>(); private List<String> filmsStreamData = new ArrayList<String>();
private Connection connection = null; private Connection connection = null;
private static final Logger LOGGER = LogManager.getLogger(DBController.class.getName()); private static final Logger LOGGER = LogManager.getLogger(DBController.class.getName());
public void init() { public void init() {
LOGGER.info("<========== starting loading sql ==========>"); LOGGER.info("<========== starting loading sql ==========>");
loadDatabase(); initDatabaseConnection();
createDatabase(); createDatabase();
loadData(); refreshDataBase();
LOGGER.info("<========== finished loading sql ==========>"); LOGGER.info("<========== finished loading sql ==========>");
} }
public void loadDatabase() { public void initDatabaseConnection() {
DB_PATH = main.getDirectory() + "/Homeflix.db"; DB_PATH = main.getDirectory() + "/Homeflix.db";
try { try {
// create a database connection // create a database connection
@ -97,11 +96,11 @@ public class DBController {
LOGGER.info("ROM database loaded successfull"); LOGGER.info("ROM database loaded successfull");
} }
public void createDatabase() { /**
/** * if tables don't exist create them
* if tables don't exist create them * cache table: streamUrl is primary key
* cache table: streamUrl is primary key */
*/ private void createDatabase() {
try { try {
Statement stmt = connection.createStatement(); 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_local (rating, titel, streamUrl, favIcon, cached)");
@ -114,7 +113,10 @@ public class DBController {
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
LOGGER.error(e); LOGGER.error(e);
} }
}
private void loadDatabase() {
// get all entries from the tables // get all entries from the tables
try { try {
@ -137,123 +139,64 @@ public class DBController {
LOGGER.error("Ups! an error occured!", e); LOGGER.error("Ups! an error occured!", e);
} }
// getting all files from the selected directory
if (new File(mainWindowController.getPath()).exists()) {
for (String entry : new File(mainWindowController.getPath()).list()) {
filmsDir.add(cutOffEnd(entry));
filmsDirURL.add(entry);
// System.out.println(cutOffEnd(entry));
// System.out.println(entry);
}
} else {
LOGGER.error(mainWindowController.getPath() + "dosen't exist!");
}
// getting all entries from the streaming lists
for (int i = 0; i < mainWindowController.getStreamingData().size(); i++) {
String fileName = mainWindowController.getStreamingPath() + "/"
+ mainWindowController.getStreamingData().get(i).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);
// System.out.println(item.asObject().getString("titel", ""));
// System.out.println(item.asObject().getString("streamUrl", ""));
// System.out.println(fileName);
}
} catch (IOException e) {
e.printStackTrace();
}
}
// add all entries to filmsAll and filmsdbAl, for later comparing // add all entries to filmsAll and filmsdbAl, for later comparing
filmsAll.addAll(filmsDir);
filmsAll.addAll(filmsStream); filmsAll.addAll(filmsStream);
filmsdbAll.addAll(filmsdbDir); filmsdbAll.addAll(filmsdbDir);
filmsdbAll.addAll(filmsdbStream); filmsdbAll.addAll(filmsdbStream);
LOGGER.info("films in directory: " + filmsAll.size()); LOGGER.info("films in directory: " + filmsAll.size());
LOGGER.info("filme in db: " + filmsdbAll.size()); LOGGER.info("filme in db: " + filmsdbAll.size());
/**
* if filmsdbAll.size() == 0 the database is empty, we need to fill it with loadFilms()
* else check if there is something to remove or to add
*/
if (filmsdbAll.size() == 0) {
loadFilms();
} else {
try {
checkAddEntry();
checkRemoveEntry();
} catch (IOException | SQLException e) {
e.printStackTrace();
}
}
} }
private void loadFilms() { // load the sources from sources.json
PreparedStatement ps; private void loadSources() {
PreparedStatement psS; // remove sources from table
LOGGER.info("Database is empty, filling tables ..."); mainWindowController.getSourcesList().removeAll(mainWindowController.getSourcesList());
mainWindowController.streamingRoot.getChildren().removeAll(mainWindowController.streamingRoot.getChildren());
try { try {
ps = connection.prepareStatement("insert into film_local values (?, ?, ?, ?, ?)"); JsonArray sources = Json.parse(new FileReader(main.getDirectory() + "/sources.json")).asArray();
psS = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); for (JsonValue source : sources) {
String path = source.asObject().getString("path", "");
if (new File(mainWindowController.getPath()).exists()) { String mode = source.asObject().getString("mode", "");
// go through all the files in the directory mainWindowController.addSourceToTable(path, mode); // add source to source-table
for (int j = 0; j != filmsDir.size(); j++) if (mode.equals("local")) {
{ // getting all files from the selected directory
ps.setInt(1, 0); // rating as integer 1. column if (new File(path).exists()) {
ps.setString(2, filmsDir.get(j)); // name as String without ending 2. column for (String entry : new File(path).list()) {
ps.setString(3, filmsDirURL.get(j)); // path as String 3. column filmsAll.add(cutOffEnd(entry));
ps.setString(4, "favorite_border_black"); }
ps.setBoolean(5, false); LOGGER.info("added files from: " + path);
ps.addBatch(); // add command to prepared statement } else {
} LOGGER.error(path + "dosen't exist!");
} }
} else {
if (mainWindowController.getStreamingPath().equals("") || mainWindowController.getStreamingPath().equals(null)) { // getting all entries from the streaming lists
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 { try {
JsonObject object = Json.parse(new FileReader(fileNamea)).asObject(); JsonObject object = Json.parse(new FileReader(path)).asObject();
JsonArray items = object.get("entries").asArray(); JsonArray items = object.get("entries").asArray();
for (JsonValue item : items) { for (JsonValue item : items) {
psS.setInt(1, item.asObject().getInt("year", 0)); filmsStream.add(item.asObject().getString("titel", ""));
psS.setInt(2, item.asObject().getInt("season", 0)); filmsStreamURL.add(item.asObject().getString("streamUrl", ""));
psS.setInt(3, item.asObject().getInt("episode", 0)); filmsStreamData.add(path);
psS.setInt(4, 0); // TODO check if all this is needed, maybe only use one table!
psS.setString(5, item.asObject().getString("resolution", "")); // System.out.println(item.asObject().getString("titel", ""));
psS.setString(6, item.asObject().getString("titel", "")); // System.out.println(item.asObject().getString("streamUrl", ""));
psS.setString(7, item.asObject().getString("streamUrl", "")); // System.out.println(fileName);
psS.setString(8, "favorite_border_black");
psS.setBoolean(9, false);
psS.addBatch(); // add command to prepared statement
} }
LOGGER.info("added films from: " + path);
} catch (IOException e) { } catch (IOException e) {
LOGGER.error(e); LOGGER.error(e);
e.printStackTrace();
} }
} }
} }
ps.executeBatch(); // execute statement to write entries into table } catch (Exception e) {
psS.executeBatch(); e.printStackTrace();
connection.commit();
ps.close();
psS.close();
} catch (SQLException e) {
LOGGER.error(e);
} }
} }
// loading data from database to mainWindowController // loading data from database to mainWindowController
public void loadData() { public void loadDataToMWC() {
LOGGER.info("loading data to mwc ..."); LOGGER.info("loading data to mwc ...");
try { try {
//load local Data //load local Data
@ -333,39 +276,84 @@ public class DBController {
} }
} }
} }
/**
* refresh database to contain all (new added) entries
* refresh the MainWindowController content,
* to contain all (new added) entries from the database
*/
public void refreshDataBase() {
LOGGER.info("refreshing the Database ...");
// clean all ArraLists
filmsdbAll.removeAll(filmsdbAll);
filmsdbDir.removeAll(filmsdbDir);
filmsdbStream.removeAll(filmsdbStream);
filmsdbStreamURL.removeAll(filmsdbStreamURL);
filmsAll.removeAll(filmsAll);
filmsStream.removeAll(filmsStream);
filmsStreamURL.removeAll(filmsStreamURL);
filmsStreamData.removeAll(filmsStreamData);
loadSources(); // reload all sources
loadDatabase(); // reload all films saved in the DB
try {
checkAddEntry();
checkRemoveEntry();
} catch (Exception e) {
LOGGER.error("Error while refreshing the database", e);
}
// remove all films from the mwc lists
mainWindowController.getLocalFilms().removeAll(mainWindowController.getLocalFilms());
mainWindowController.getStreamingFilms().removeAll(mainWindowController.getStreamingFilms());
mainWindowController.root.getChildren().removeAll(mainWindowController.root.getChildren());
loadDataToMWC(); // load the new data to the mwc
}
/** /**
* check if there are any entries that have been removed from the film-directory * check if there are any entries that have been removed from the film-directory
* @throws SQLException
*/ */
private void checkRemoveEntry() throws SQLException { private void checkRemoveEntry() {
LOGGER.info("checking for entrys to remove to DB ..."); LOGGER.info("checking for entrys to remove to DB ...");
Statement stmt = connection.createStatement();
try {
for (int i = 0; i < filmsdbDir.size(); i++) { Statement stmt = connection.createStatement();
if (!filmsDir.contains(filmsdbDir.get(i))) {
try { for (String entry : filmsdbDir) {
stmt.executeUpdate("delete from film_local where titel = \"" + filmsdbDir.get(i) + "\""); if (!filmsAll.contains(cutOffEnd(entry))) {
stmt.executeUpdate("delete from film_local where titel = \"" + entry + "\"");
connection.commit(); connection.commit();
stmt.close(); stmt.close();
LOGGER.info("removed \"" + filmsdbDir.get(i) + "\" from database"); LOGGER.info("removed \"" + entry + "\" from database");
} catch (Exception e) {
e.printStackTrace();
} }
} }
}
// TODO needs testing, then remove 1
for (int j = 0; j < filmsdbStreamURL.size(); j++) { for (String entry : filmsdbStreamURL) {
if (!filmsStreamURL.contains(filmsdbStreamURL.get(j))) { if (!filmsStreamURL.contains(entry)) {
try { stmt.executeUpdate("delete from film_streaming where titel = \"" + entry + "\"");
stmt.executeUpdate("delete from film_streaming where titel = \"" + filmsdbStream.get(j) + "\"");
connection.commit(); connection.commit();
stmt.close(); stmt.close();
LOGGER.info("removed \"" + filmsdbStream.get(j) + "\" from database"); LOGGER.info("removed \"" + entry + "\" from database");
} catch (Exception e) {
e.printStackTrace();
} }
} }
// this is 1
// for (int j = 0; j < filmsdbStreamURL.size(); j++) {
// if (!filmsStreamURL.contains(filmsdbStreamURL.get(j))) {
// stmt.executeUpdate("delete from film_streaming where titel = \"" + filmsdbStream.get(j) + "\"");
// connection.commit();
// stmt.close();
// LOGGER.info("removed \"" + filmsdbStream.get(j) + "\" from database");
// }
// }
} catch (Exception e) {
LOGGER.error(e);
} }
} }
@ -378,50 +366,60 @@ public class DBController {
*/ */
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException { private void checkAddEntry() throws SQLException, FileNotFoundException, IOException {
String lastName = ""; String lastName = "";
LOGGER.info("checking for entrys to add to DB ...");
String[] entries = new File(mainWindowController.getPath()).list();
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
PreparedStatement ps = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); PreparedStatement ps = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?, ?)");
int i = 0; LOGGER.info("checking for entrys to add to DB ...");
int a = 0;
for (int a = 0; a < filmsDir.size(); a++) {
if (!filmsdbDir.contains(filmsDir.get(a))) { // source is a single source of the sources list
stmt.executeUpdate("insert into film_local values (0, \"" + cutOffEnd(entries[a]) + "\", \"" for (tableData source : mainWindowController.getSourcesList()) {
+ entries[a] + "\",\"favorite_border_black\",0)"); // if it's a local source check the folder for new film
connection.commit(); if (source.getStreamUrl().equals("local")) {
stmt.close(); for (String entry : new File(source.getTitle()).list()) {
LOGGER.info("added \"" + filmsDir.get(a) + "\" to database"); if (!filmsdbAll.contains(cutOffEnd(entry))) {
stmt.executeUpdate("insert into film_local values (0, \"" + cutOffEnd(entry) + "\", \""
+ source.getTitle() + "/" + entry + "\",\"favorite_border_black\",0)");
connection.commit();
stmt.close();
LOGGER.info("added \"" + entry + "\" to database");
filmsAll.add(cutOffEnd(entry));
}
}
} else {
// if it's a streaming source check the file for new films
// TODO implement add check for streaming sources
} }
} }
// TODO comment and rework
for (int b = 0; b < filmsStreamURL.size(); b++) { for (int b = 0; b < filmsStreamURL.size(); b++) {
if (filmsdbStreamURL.contains(filmsStreamURL.get(b))) { if (filmsdbStreamURL.contains(filmsStreamURL.get(b))) {
} else { } else {
if (lastName != "" && lastName != filmsStreamData.get(b)) { if (lastName != "" && lastName != filmsStreamData.get(b)) {
i = 0; a = 0;
} }
lastName = filmsStreamData.get(b); lastName = filmsStreamData.get(b);
JsonObject object = Json.parse(new FileReader(filmsStreamData.get(b))).asObject(); JsonObject object = Json.parse(new FileReader(filmsStreamData.get(b))).asObject();
JsonArray items = object.get("entries").asArray(); JsonArray items = object.get("entries").asArray();
LOGGER.info(items.size() + ", " + i + "; " + b); LOGGER.info(items.size() + ", " + a + "; " + b);
String streamURL = items.get(i).asObject().getString("streamUrl", ""); String streamURL = items.get(a).asObject().getString("streamUrl", "");
String titel = items.get(i).asObject().getString("titel", ""); String titel = items.get(a).asObject().getString("titel", "");
if (streamURL.equals(filmsStreamURL.get(b))) { if (streamURL.equals(filmsStreamURL.get(b))) {
LOGGER.info("added \"" + titel + "\""); LOGGER.info("added \"" + titel + "\"");
ps.setInt(1, items.get(i).asObject().getInt("year", 0)); ps.setInt(1, items.get(a).asObject().getInt("year", 0));
ps.setInt(2, items.get(i).asObject().getInt("season", 0)); ps.setInt(2, items.get(a).asObject().getInt("season", 0));
ps.setInt(3, items.get(i).asObject().getInt("episode", 0)); ps.setInt(3, items.get(a).asObject().getInt("episode", 0));
ps.setInt(4, 0); ps.setInt(4, 0);
ps.setString(5, items.get(i).asObject().getString("resolution", "")); ps.setString(5, items.get(a).asObject().getString("resolution", ""));
ps.setString(6, items.get(i).asObject().getString("titel", "")); ps.setString(6, items.get(a).asObject().getString("titel", ""));
ps.setString(7, items.get(i).asObject().getString("streamUrl", "")); ps.setString(7, items.get(a).asObject().getString("streamUrl", ""));
ps.setString(8, "favorite_border_black"); ps.setString(8, "favorite_border_black");
ps.setBoolean(9, false); ps.setBoolean(9, false);
ps.addBatch(); // adds the entry ps.addBatch(); // adds the entry
} }
i++; a++;
} }
} }
ps.executeBatch(); ps.executeBatch();

View File

@ -11,6 +11,7 @@
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?> <?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Separator?> <?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?> <?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TreeTableView?> <?import javafx.scene.control.TreeTableView?>
<?import javafx.scene.image.Image?> <?import javafx.scene.image.Image?>
@ -68,11 +69,6 @@
<Font name="System Bold" size="15.0" /> <Font name="System Bold" size="15.0" />
</font> </font>
</JFXButton> </JFXButton>
<JFXButton fx:id="streamingSettingsBtn" onAction="#streamingSettingsBtnclicked" prefHeight="32.0" prefWidth="150.0" textAlignment="CENTER">
<font>
<Font name="System Bold" size="15.0" />
</font>
</JFXButton>
<JFXButton fx:id="switchBtn" onAction="#switchBtnclicked" prefHeight="32.0" prefWidth="150.0" textAlignment="CENTER"> <JFXButton fx:id="switchBtn" onAction="#switchBtnclicked" prefHeight="32.0" prefWidth="150.0" textAlignment="CENTER">
<font> <font>
<Font name="System Bold" size="15.0" /> <Font name="System Bold" size="15.0" />
@ -85,7 +81,7 @@
</JFXButton> </JFXButton>
</children> </children>
</VBox> </VBox>
<ScrollPane fx:id="settingsScrollPane" style="-fx-background: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="32.0"> <ScrollPane fx:id="settingsScrollPane" prefHeight="568.0" prefWidth="800.0" style="-fx-background: white;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="32.0">
<content> <content>
<AnchorPane fx:id="settingsAnchorPane" style="-fx-background-color: white;"> <AnchorPane fx:id="settingsAnchorPane" style="-fx-background-color: white;">
<children> <children>
@ -94,7 +90,7 @@
<Insets bottom="14.0" top="14.0" /> <Insets bottom="14.0" top="14.0" />
</padding> </padding>
<children> <children>
<VBox prefHeight="193.0" prefWidth="797.0" spacing="25.0"> <VBox spacing="25.0">
<padding> <padding>
<Insets left="24.0" /> <Insets left="24.0" />
</padding> </padding>
@ -116,20 +112,6 @@
<Insets left="-14.0" /> <Insets left="-14.0" />
</padding> </padding>
</VBox> </VBox>
<VBox spacing="7.0">
<padding>
<Insets right="5.0" />
</padding>
<children>
<Label fx:id="filmDirectoryLbl" text="Film Directory" />
<HBox spacing="10.0">
<children>
<JFXTextField fx:id="filmDirTextField" maxWidth="305.0" minWidth="305.0" onAction="#filmDirTextFieldAction" prefHeight="32.0" prefWidth="305.0" promptText="Film Directory" />
<JFXButton fx:id="directoryBtn" onAction="#directoryBtnAction" prefHeight="32.0" text="choose directory" />
</children>
</HBox>
</children>
</VBox>
<HBox minHeight="25.0" spacing="10.0"> <HBox minHeight="25.0" spacing="10.0">
<children> <children>
<Label fx:id="mainColorLbl" prefHeight="25.0" text="Main-Color" /> <Label fx:id="mainColorLbl" prefHeight="25.0" text="Main-Color" />
@ -166,6 +148,23 @@
</children> </children>
</VBox> </VBox>
<Label fx:id="versionLbl" text="Version" /> <Label fx:id="versionLbl" text="Version" />
<VBox spacing="10.0">
<children>
<Label fx:id="sourcesLbl" text="Sources" />
<HBox spacing="10.0">
<children>
<JFXButton fx:id="addStreamSourceBtn" onAction="#addStreamSourceBtnAction" prefHeight="32.0" text="add stream source" />
<JFXButton fx:id="addDirectoryBtn" onAction="#addDirectoryBtnAction" prefHeight="32.0" text="add directory" />
</children>
</HBox>
<TableView fx:id="sourcesTable" maxWidth="430.0" minHeight="100.0" prefHeight="100.0" prefWidth="430.0">
<columns>
<TableColumn fx:id="sourceColumn" prefWidth="290.0" resizable="false" text="Sources" />
<TableColumn fx:id="modeColumn" minWidth="130.0" prefWidth="138.0" resizable="false" text="Mode" />
</columns>
</TableView>
</children>
</VBox>
</children> </children>
</VBox> </VBox>
<VBox spacing="25.0"> <VBox spacing="25.0">
@ -179,11 +178,5 @@
</AnchorPane> </AnchorPane>
</content> </content>
</ScrollPane> </ScrollPane>
<AnchorPane fx:id="streamingSettingsAnchorPane" layoutX="138.0" layoutY="33.0" prefHeight="566.0" prefWidth="760.0" style="-fx-background-color: #FFFFFF;" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="150.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="38.0">
<children>
<JFXTextField fx:id="streamingPathTextField" layoutX="14.0" layoutY="14.0" onAction="#streamingPathTextFieldAction" prefWidth="250.0" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="5.0" />
<JFXButton fx:id="streamingDirectoryBtn" layoutX="263.0" layoutY="2.0" onAction="#streamingDirectoryBtnAction" prefHeight="25.0" prefWidth="115.0" AnchorPane.leftAnchor="260.0" AnchorPane.topAnchor="5.0" />
<TableView fx:id="tableViewStreamingdata" layoutX="14.0" layoutY="44.0" prefHeight="517.0" prefWidth="370.0" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="5.0" AnchorPane.topAnchor="40.0" />
</children></AnchorPane>
</children> </children>
</AnchorPane> </AnchorPane>

View File

@ -10,7 +10,8 @@ openFolder = Ordner \u00F6ffnen
#settings translations #settings translations
homeflixSettingsLbl = HomeFlix Einstellungen homeflixSettingsLbl = HomeFlix Einstellungen
filmDirTextField = Pfad... filmDirTextField = Pfad...
chooseFolder = Ordner ausw\u00E4hlen addDirectory = Ordner hinzuf\u00FCgen
addStreamSource = Stream Quelle hinzuf\u00FCgen
mainColorLbl = Hauptfarbe: mainColorLbl = Hauptfarbe:
fontsizeLbl = Schriftgr\u00F6\u00DFe: fontsizeLbl = Schriftgr\u00F6\u00DFe:
languageLbl = Sprache: languageLbl = Sprache:

View File

@ -10,7 +10,8 @@ openFolder = open Folder
#settings translations #settings translations
homeflixSettingsLbl = HomeFlix Settings homeflixSettingsLbl = HomeFlix Settings
filmDirTextField = Path... filmDirTextField = Path...
chooseFolder = choose Directory addDirectory = add directory
addStreamSource = add stream source
mainColorLbl = main color: mainColorLbl = main color:
fontsizeLbl = font size: fontsizeLbl = font size:
languageLbl = local: languageLbl = local: