more code cleanup and bug fixes

* removed year and resolution from all tables as they're not used anywhere
* fixed a bug that caused issues, when refreshing streaming entres with the same title
* like, dislike are now based on the streamUrl insted of the title
* fixed a bug, that ocured when liking/disliking the last entry in the table
This commit is contained in:
Jannik 2018-03-05 22:37:32 +01:00
parent af343dea44
commit f27c3810ff
6 changed files with 320 additions and 322 deletions

View File

@ -39,7 +39,6 @@ import java.io.Writer;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Properties;
@ -99,7 +98,8 @@ import javafx.util.Duration;
import kellerkinder.HomeFlix.controller.DBController;
import kellerkinder.HomeFlix.controller.UpdateController;
import kellerkinder.HomeFlix.controller.apiQuery;
import kellerkinder.HomeFlix.datatypes.tableData;
import kellerkinder.HomeFlix.datatypes.SourceDataType;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
public class MainWindowController {
@ -119,10 +119,10 @@ public class MainWindowController {
private VBox sideMenuVBox;
@FXML
private TreeTableView<tableData> treeTableViewfilm;
private TreeTableView<FilmTabelDataType> treeTableViewfilm;
@FXML
private TableView<tableData> sourcesTable;
private TableView<SourceDataType> sourcesTable;
@FXML
private TextFlow textFlow;
@ -211,28 +211,24 @@ public class MainWindowController {
private ImageView imv1;
@FXML
public TreeItem<tableData> root = new TreeItem<>(new tableData(1, 1, 1, 5.0, "1", "filme", "1", imv1, false));
private TreeItem<FilmTabelDataType> filmRoot = new TreeItem<>(new FilmTabelDataType(1, 1, 5.0, "filme", "1", imv1, false));
@FXML
TreeTableColumn<tableData, ImageView> columnRating = new TreeTableColumn<>("Rating");
TreeTableColumn<FilmTabelDataType, ImageView> columnRating = new TreeTableColumn<>("Rating");
@FXML
TreeTableColumn<tableData, String> columnTitel = new TreeTableColumn<>("Titel");
TreeTableColumn<FilmTabelDataType, String> columnTitel = new TreeTableColumn<>("Titel");
@FXML
TreeTableColumn<tableData, String> columnStreamUrl = new TreeTableColumn<>("File Name");
TreeTableColumn<FilmTabelDataType, String> columnStreamUrl = new TreeTableColumn<>("File Name");
@FXML
TreeTableColumn<tableData, String> columnResolution = new TreeTableColumn<>("Resolution");
TreeTableColumn<FilmTabelDataType, Integer> columnSeason = new TreeTableColumn<>("Season");
@FXML
TreeTableColumn<tableData, Integer> columnYear = new TreeTableColumn<>("Year");
@FXML
TreeTableColumn<tableData, Integer> columnSeason = new TreeTableColumn<>("Season");
@FXML
TreeTableColumn<tableData, Integer> columnEpisode = new TreeTableColumn<>("Episode");
TreeTableColumn<FilmTabelDataType, Integer> columnEpisode = new TreeTableColumn<>("Episode");
@FXML
public TreeItem<tableData> streamingRoot =new TreeItem<>(new tableData(1 ,1 ,1 ,1.0 ,"1" ,"filme" ,"1", imv1, false)); // TODO make private
private TreeItem<SourceDataType> streamingRoot =new TreeItem<>(new SourceDataType("", ""));
@FXML
private TableColumn<tableData, String> sourceColumn;
private TableColumn<SourceDataType, String> sourceColumn;
@FXML
private TableColumn<tableData, String> modeColumn;
private TableColumn<SourceDataType, String> modeColumn;
private boolean menuTrue = false;
private boolean settingsTrue = false;
@ -256,8 +252,8 @@ public class MainWindowController {
private String vlcNotInstalled;
private String streamingPath;
private String color;
private String name;
private String datPath;
private String title;
private String streamUrl;
private String mode;
private String ratingSortType;
private String local;
@ -268,12 +264,12 @@ public class MainWindowController {
private int next;
private ResourceBundle bundle;
private ObservableList<tableData> filterData = FXCollections.observableArrayList();
private ObservableList<FilmTabelDataType> filterData = FXCollections.observableArrayList();
private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
private ObservableList<tableData> localFilms = FXCollections.observableArrayList();
private ObservableList<tableData> streamingFilms = FXCollections.observableArrayList();
private ObservableList<tableData> sourcesList = FXCollections.observableArrayList();
private ObservableList<FilmTabelDataType> localFilms = FXCollections.observableArrayList();
private ObservableList<FilmTabelDataType> streamingFilms = FXCollections.observableArrayList();
private ObservableList<SourceDataType> sourcesList = FXCollections.observableArrayList();
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_next_white = new ImageView(new Image("icons/ic_skip_next_white_18dp_1x.png"));
@ -284,14 +280,15 @@ public class MainWindowController {
private MenuItem like = new MenuItem("like");
private MenuItem dislike = new MenuItem("dislike"); //TODO one option (like or dislike)
private ContextMenu menu = new ContextMenu(like, dislike);
Properties props = new Properties();
private Properties props = new Properties();
private Main main;
private UpdateController updateController;
private apiQuery ApiQuery;
DBController dbController;
/**"Main" Method called in Main.java main() when starting
/**
* "Main" Method called in Main.java main() when starting
* Initialize other objects: Updater, dbController and ApiQuery
*/
void setMain(Main main) {
@ -308,44 +305,38 @@ public class MainWindowController {
initUI();
}
//Initialize the tables (treeTableViewfilm and tableViewStreamingdata)
// Initialize the tables (treeTableViewfilm and sourcesTable)
private void initTabel() {
//film Table
columnRating.setMaxWidth(80);
columnTitel.setMaxWidth(260);
columnStreamUrl.setMaxWidth(0);
columnRating.setStyle("-fx-alignment: CENTER;");
treeTableViewfilm.setRoot(root);
treeTableViewfilm.setColumnResizePolicy( TreeTableView.CONSTRAINED_RESIZE_POLICY );
treeTableViewfilm.setShowRoot(false);
//write content into cell
columnTitel.setCellValueFactory(cellData -> cellData.getValue().getValue().titleProperty());
columnRating.setCellValueFactory(cellData -> cellData.getValue().getValue().imageProperty());
columnStreamUrl.setCellValueFactory(cellData -> cellData.getValue().getValue().streamUrlProperty());
columnResolution.setCellValueFactory(cellData -> cellData.getValue().getValue().resolutionProperty());
columnYear.setCellValueFactory(cellData -> cellData.getValue().getValue().yearProperty().asObject());
columnSeason.setCellValueFactory(cellData -> cellData.getValue().getValue().seasonProperty().asObject());
columnEpisode.setCellValueFactory(cellData -> cellData.getValue().getValue().episodeProperty().asObject());
// film Table
columnStreamUrl.setMaxWidth(0);
columnRating.setStyle("-fx-alignment: CENTER;");
//add columns to treeTableViewfilm
treeTableViewfilm.setRoot(filmRoot);
treeTableViewfilm.setColumnResizePolicy(TreeTableView.CONSTRAINED_RESIZE_POLICY);
treeTableViewfilm.setShowRoot(false);
// write content into cell
columnTitel.setCellValueFactory(cellData -> cellData.getValue().getValue().titleProperty());
columnRating.setCellValueFactory(cellData -> cellData.getValue().getValue().imageProperty());
columnStreamUrl.setCellValueFactory(cellData -> cellData.getValue().getValue().streamUrlProperty());
columnSeason.setCellValueFactory(cellData -> cellData.getValue().getValue().seasonProperty().asObject());
columnEpisode.setCellValueFactory(cellData -> cellData.getValue().getValue().episodeProperty().asObject());
// add columns to treeTableViewfilm
treeTableViewfilm.getColumns().add(columnTitel);
treeTableViewfilm.getColumns().add(columnRating);
treeTableViewfilm.getColumns().add(columnStreamUrl);
treeTableViewfilm.getColumns().add(columnResolution);
treeTableViewfilm.getColumns().add(columnYear);
treeTableViewfilm.getColumns().add(columnSeason);
treeTableViewfilm.getColumns().add(columnEpisode);
treeTableViewfilm.getColumns().get(2).setVisible(false); //hide columnStreamUrl (column with file URL, important for opening a file/stream)
//context menu for treeTableViewfilm
// context menu for treeTableViewfilm
treeTableViewfilm.setContextMenu(menu);
// sourcesTreeTable
sourceColumn.setCellValueFactory(cellData -> cellData.getValue().titleProperty());
modeColumn.setCellValueFactory(cellData -> cellData.getValue().streamUrlProperty());
sourceColumn.setCellValueFactory(cellData -> cellData.getValue().pathProperty());
modeColumn.setCellValueFactory(cellData -> cellData.getValue().modeProperty());
sourcesTable.setItems(sourcesList);
}
@ -375,9 +366,9 @@ public class MainWindowController {
searchTextField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
ObservableList<tableData> helpData;
ObservableList<FilmTabelDataType> helpData;
filterData.removeAll(filterData);
root.getChildren().remove(0, root.getChildren().size());
filmRoot.getChildren().removeAll(filmRoot.getChildren());
if (mode.equals("local")) {
helpData = localFilms;
@ -392,7 +383,7 @@ public class MainWindowController {
}
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
filmRoot.getChildren().add(new TreeItem<FilmTabelDataType>(filterData.get(i))); // add filtered data to root node after search
}
if (searchTextField.getText().hashCode() == hashA) {
setColor("000000");
@ -428,8 +419,8 @@ public class MainWindowController {
@Override
public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
setSize(fontsizeSlider.getValue());
if (name != null) {
dbController.readCache(datPath);
if (title != null) {
dbController.readCache(streamUrl);
}
// ta1.setFont(Font.font("System", size));
saveSettings();
@ -439,17 +430,8 @@ public class MainWindowController {
like.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if (mode.equals("streaming")) {
dbController.like(name, streamingFilms.get(selected).getStreamUrl());
} else {
dbController.like(name, localFilms.get(selected).getStreamUrl());
}
dbController.getFavStatus(name);
try {
dbController.refresh(name, selected);
} catch (SQLException e) {
LOGGER.error("(like-problem), it seems as a cat has stolen the \"like-methode\"!", e);
}
dbController.like(streamUrl);
dbController.refresh(streamUrl, selected);
refreshTable();
}
});
@ -457,17 +439,8 @@ public class MainWindowController {
dislike.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if (mode.equals("streaming")) {
dbController.dislike(name, streamingFilms.get(selected).getStreamUrl());
} else {
dbController.dislike(name, localFilms.get(selected).getStreamUrl());
}
dbController.getFavStatus(name);
try {
dbController.refresh(name, selected);
} catch (SQLException e) {
LOGGER.error("There was a problem with the like/dislike function!", e);
}
dbController.dislike(streamUrl);
dbController.refresh(streamUrl, selected);
refreshTable();
}
});
@ -477,15 +450,14 @@ public class MainWindowController {
*/
columnRating.sortTypeProperty().addListener(new ChangeListener<SortType>() {
@Override
public void changed(ObservableValue<? extends SortType> paramObservableValue, SortType paramT1,
SortType paramT2) {
public void changed(ObservableValue<? extends SortType> paramObservableValue, SortType paramT1, SortType paramT2) {
LOGGER.info("NAME Clicked -- sortType = " + paramT1 + ", SortType=" + paramT2);
ArrayList<Integer> fav_true = new ArrayList<Integer>();
ArrayList<Integer> fav_false = new ArrayList<Integer>();
ObservableList<tableData> helpData;
ObservableList<FilmTabelDataType> helpData;
filterData.removeAll(filterData);
// treeTableViewfilm.getSelectionModel().clearSelection(selected);
root.getChildren().remove(0, root.getChildren().size());
filmRoot.getChildren().removeAll(filmRoot.getChildren());
if (mode.equals("local")) {
helpData = localFilms;
@ -520,7 +492,8 @@ public class MainWindowController {
LOGGER.info(filterData.size()); // Debug, delete?
for (int i = 0; i < filterData.size(); i++) {
// 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
// add filtered data to root node after search
filmRoot.getChildren().add(new TreeItem<FilmTabelDataType>(filterData.get(i)));
}
}
});
@ -533,23 +506,22 @@ public class MainWindowController {
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
title = columnTitel.getCellData(selected); // get name of selected item
streamUrl = 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);
LOGGER.info("loading from cache: " + title);
dbController.readCache(streamUrl);
} else {
ApiQuery.startQuery(name, datPath); // start api query
ApiQuery.startQuery(title, streamUrl); // start api query
}
} else {
LOGGER.info(streamingFilms.size());
if (streamingFilms.get(selected).getCached() == true) {
LOGGER.info("loading from cache: " + name);
dbController.readCache(datPath);
LOGGER.info("loading from cache: " + title);
dbController.readCache(streamUrl);
} else {
ApiQuery.startQuery(name, datPath); // start api query
ApiQuery.startQuery(title, streamUrl); // start api query
}
}
}
@ -587,7 +559,7 @@ public class MainWindowController {
if (Desktop.isDesktopSupported()) {
new Thread(() -> {
try {
Desktop.getDesktop().browse(new URI(datPath)); //open the streaming URL in browser
Desktop.getDesktop().browse(new URI(streamUrl)); //open the streaming URL in browser
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
showErrorMsg(errorOpenStream, (IOException) e);
@ -617,14 +589,14 @@ public class MainWindowController {
vlcInfoDialog.show();
}else{
try {
Runtime.getRuntime().exec(new String[] { "vlc", datPath}); // TODO switch to ProcessBuilder
Runtime.getRuntime().exec(new String[] { "vlc", streamUrl}); // TODO switch to ProcessBuilder
} catch (IOException e) {
showErrorMsg(errorPlay,e);
}
}
}else if(System.getProperty("os.name").contains("Windows") || System.getProperty("os.name").contains("Mac OS X")){
try {
Desktop.getDesktop().open(new File(datPath));
Desktop.getDesktop().open(new File(streamUrl));
} catch (IOException e) {
showErrorMsg(errorPlay,e);
}
@ -639,7 +611,7 @@ public class MainWindowController {
@FXML
private void openfolderbtnclicked() {
String dest = new File(datPath).getParentFile().getAbsolutePath();
String dest = new File(streamUrl).getParentFile().getAbsolutePath();
if (!System.getProperty("os.name").contains("Linux")) {
try {
Desktop.getDesktop().open(new File(dest));
@ -689,7 +661,7 @@ public class MainWindowController {
switchBtn.setText("streaming");
}
saveSettings();
root.getChildren().remove(0,root.getChildren().size());
filmRoot.getChildren().removeAll(filmRoot.getChildren());
addDataUI();
settingsScrollPane.setVisible(false);
sideMenuSlideOut(); //disables side-menu
@ -750,45 +722,42 @@ public class MainWindowController {
saveSettings();
}
private void refreshTable(){
if(mode.equals("local")){
root.getChildren().set(selected, new TreeItem<tableData>(localFilms.get(selected)));
}else if(mode.equals("streaming")){
root.getChildren().set(selected, new TreeItem<tableData>(streamingFilms.get(selected)));
// refresh the selected child of the root node
private void refreshTable() {
if (mode.equals("local")) {
filmRoot.getChildren().get(selected).setValue(localFilms.get(selected));
} else {
filmRoot.getChildren().get(selected).setValue(streamingFilms.get(selected));
}
}
// TODO rework
public void addDataUI(){
if(mode.equals("local")){
for(int i = 0; i < localFilms.size(); i++){
root.getChildren().add(new TreeItem<tableData>(localFilms.get(i))); //add data to root-node
filmRoot.getChildren().add(new TreeItem<FilmTabelDataType>(localFilms.get(i))); //add data to root-node
}
columnRating.setMaxWidth(85);
columnTitel.setMaxWidth(290);
treeTableViewfilm.getColumns().get(3).setVisible(false);
treeTableViewfilm.getColumns().get(4).setVisible(false);
treeTableViewfilm.getColumns().get(5).setVisible(false);
treeTableViewfilm.getColumns().get(6).setVisible(false);
}else if(mode.equals("streaming")){
for(int i = 0; i < streamingFilms.size(); i++){
root.getChildren().add(new TreeItem<tableData>(streamingFilms.get(i))); //add data to root-node
filmRoot.getChildren().add(new TreeItem<FilmTabelDataType>(streamingFilms.get(i))); //add data to root-node
}
columnTitel.setMaxWidth(150);
columnResolution.setMaxWidth(65);
columnRating.setMaxWidth(50);
columnYear.setMaxWidth(43);
columnSeason.setMaxWidth(42);
columnEpisode.setMaxWidth(44);
columnTitel.setMaxWidth(215);
columnRating.setMaxWidth(60);
columnSeason.setMaxWidth(55);
columnEpisode.setMaxWidth(64);
treeTableViewfilm.getColumns().get(3).setVisible(true);
treeTableViewfilm.getColumns().get(4).setVisible(true);
treeTableViewfilm.getColumns().get(5).setVisible(true);
treeTableViewfilm.getColumns().get(6).setVisible(true);
}
}
public void addSourceToTable(String path, String mode) {
sourcesList.add(new tableData(1, 1, 1, 5.0, "1", path, mode, imv1, false));
streamingRoot.getChildren().add(new TreeItem<tableData>(sourcesList.get(sourcesList.size() - 1))); // adds data to root-node
sourcesList.add(new SourceDataType(path, mode));
streamingRoot.getChildren().add(new TreeItem<SourceDataType>(sourcesList.get(sourcesList.size() - 1))); // adds data to root-node
}
public void addSource(String path, String mode) {
@ -913,9 +882,7 @@ public class MainWindowController {
columnTitel.setText(getBundle().getString("columnName"));
columnRating.setText(getBundle().getString("columnRating"));
columnStreamUrl.setText(getBundle().getString("columnStreamUrl"));
columnResolution.setText(getBundle().getString("columnResolution"));
columnSeason.setText(getBundle().getString("columnSeason"));
columnYear.setText(getBundle().getString("columnYear"));
errorPlay = getBundle().getString("errorPlay");
errorOpenStream = getBundle().getString("errorOpenStream");
errorMode = getBundle().getString("errorMode");
@ -926,7 +893,7 @@ public class MainWindowController {
}
// TODO rework to material design
public void showErrorMsg(String msg, IOException exception) {
public void showErrorMsg(String msg, Exception exception) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("Error");
alert.setHeaderText("");
@ -1141,27 +1108,27 @@ public class MainWindowController {
return mode;
}
public ObservableList<tableData> getLocalFilms() {
public ObservableList<FilmTabelDataType> getLocalFilms() {
return localFilms;
}
public void setLocalFilms(ObservableList<tableData> localFilms) {
public void setLocalFilms(ObservableList<FilmTabelDataType> localFilms) {
this.localFilms = localFilms;
}
public ObservableList<tableData> getStreamingFilms() {
public ObservableList<FilmTabelDataType> getStreamingFilms() {
return streamingFilms;
}
public void setStreamingFilms(ObservableList<tableData> streamingFilms) {
public void setStreamingFilms(ObservableList<FilmTabelDataType> streamingFilms) {
this.streamingFilms = streamingFilms;
}
public ObservableList<tableData> getSourcesList() {
public ObservableList<SourceDataType> getSourcesList() {
return sourcesList;
}
public void setSourcesList(ObservableList<tableData> sourcesList) {
public void setSourcesList(ObservableList<SourceDataType> sourcesList) {
this.sourcesList = sourcesList;
}
@ -1185,23 +1152,19 @@ public class MainWindowController {
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;
public TreeItem<FilmTabelDataType> getFilmRoot() {
return filmRoot;
}
public TreeItem<SourceDataType> getStreamingRoot() {
return streamingRoot;
}
}

View File

@ -49,7 +49,8 @@ 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;
import kellerkinder.HomeFlix.datatypes.SourceDataType;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
public class DBController {
@ -79,7 +80,7 @@ public class DBController {
LOGGER.info("<========== finished loading sql ==========>");
}
public void initDatabaseConnection() {
private void initDatabaseConnection() {
DB_PATH = main.getDirectory() + "/Homeflix.db";
try {
// create a database connection
@ -99,9 +100,8 @@ public class DBController {
private void createDatabase() {
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.executeUpdate("create table if not exists film_local (rating, titel, streamUrl, cached)");
stmt.executeUpdate("create table if not exists film_streaming (season, episode, rating, titel, streamUrl, cached)");
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,"
@ -119,15 +119,15 @@ public class DBController {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
while (rs.next()) {
filmsdbDir.add(rs.getString(2));
filmsdbDir.add(rs.getString("titel"));
}
stmt.close();
rs.close();
rs = stmt.executeQuery("SELECT * FROM film_streaming;");
while (rs.next()) {
filmsdbAll.add(rs.getString(6));
filmsdbStreamURL.add(rs.getString(7));
filmsdbAll.add(rs.getString("titel"));
filmsdbStreamURL.add(rs.getString("streamUrl"));
}
stmt.close();
rs.close();
@ -145,7 +145,7 @@ public class DBController {
private void loadSources() {
// remove sources from table
mainWindowController.getSourcesList().removeAll(mainWindowController.getSourcesList());
mainWindowController.streamingRoot.getChildren().removeAll(mainWindowController.streamingRoot.getChildren());
mainWindowController.getStreamingRoot().getChildren().removeAll(mainWindowController.getStreamingRoot().getChildren());
try {
JsonArray sources = Json.parse(new FileReader(main.getDirectory() + "/sources.json")).asArray();
@ -187,19 +187,19 @@ public class DBController {
}
// loading data from database to mainWindowController
public void loadDataToMWC() {
private void loadDataToMWC() {
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)));
if (rs.getInt("rating") == 1) {
mainWindowController.getLocalFilms().add(new FilmTabelDataType(1, 1, rs.getDouble("rating"), rs.getString("titel"),
rs.getString("streamUrl"), new ImageView(favorite_black), rs.getBoolean("cached")));
} 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)));
mainWindowController.getLocalFilms().add(new FilmTabelDataType(1, 1, rs.getDouble("rating"), rs.getString("titel"),
rs.getString("streamUrl"), new ImageView(favorite_border_black), rs.getBoolean("cached")));
}
}
stmt.close();
@ -208,14 +208,14 @@ public class DBController {
//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)));
if (rs.getInt("rating") == 1) {
mainWindowController.getStreamingFilms().add(new FilmTabelDataType(rs.getInt("season"),
rs.getInt("episode"), rs.getDouble("rating"), rs.getString("titel"), rs.getString("streamUrl"),
new ImageView(favorite_black), rs.getBoolean("cached")));
} 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)));
mainWindowController.getStreamingFilms().add(new FilmTabelDataType(rs.getInt("season"),
rs.getInt("episode"),rs.getDouble("rating"), rs.getString("titel"),rs.getString("streamUrl"),
new ImageView(favorite_border_black), rs.getBoolean("cached")));
}
}
stmt.close();
@ -228,43 +228,43 @@ public class DBController {
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 {
/**
* refresh data in mainWindowController localFilms and streamingFilms
* @param title of the film
* @param i index of the film in LocalFilms list
* @throws SQLException
*/
public void refresh(String streamUrl, int index) {
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)));
Statement stmt = connection.createStatement();
if (mainWindowController.getMode().equals("local")) {
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE streamUrl = \"" + streamUrl + "\";");
if (rs.getInt("rating") == 1) {
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(1, 1, rs.getDouble("rating"),
rs.getString("titel"), rs.getString("streamUrl"), new ImageView(favorite_black), rs.getBoolean("cached")));
} else {
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(1, 1, rs.getDouble("rating"),
rs.getString("titel"), rs.getString("streamUrl"), new ImageView(favorite_border_black), rs.getBoolean("cached")));
}
rs.close();
} 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)));
ResultSet rs = stmt.executeQuery("SELECT * FROM film_streaming WHERE streamUrl = \"" + streamUrl + "\";");
if (rs.getInt("rating") == 1) {
mainWindowController.getStreamingFilms().set(index, new FilmTabelDataType(rs.getInt("season"),
rs.getInt("episode"), rs.getDouble("rating"), rs.getString("titel"), rs.getString("streamUrl"),
new ImageView(favorite_black), rs.getBoolean("cached")));
} else {
mainWindowController.getStreamingFilms().set(index, new FilmTabelDataType(rs.getInt("season"),
rs.getInt("episode"), rs.getDouble("rating"), rs.getString("titel"), rs.getString("streamUrl"),
new ImageView(favorite_border_black), rs.getBoolean("cached")));
}
rs.close();
}
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);
}
} catch (Exception e) {
LOGGER.error("Ups! error while refreshing mwc!", e);
}
}
@ -297,7 +297,7 @@ public class DBController {
// remove all films from the mwc lists
mainWindowController.getLocalFilms().removeAll(mainWindowController.getLocalFilms());
mainWindowController.getStreamingFilms().removeAll(mainWindowController.getStreamingFilms());
mainWindowController.root.getChildren().removeAll(mainWindowController.root.getChildren());
mainWindowController.getFilmRoot().getChildren().removeAll(mainWindowController.getFilmRoot().getChildren());
loadDataToMWC(); // load the new data to the mwc
}
@ -315,7 +315,6 @@ public class DBController {
if (!filmsAll.contains(cutOffEnd(entry))) {
stmt.executeUpdate("delete from film_local where titel = \"" + entry + "\"");
connection.commit();
stmt.close();
LOGGER.info("removed \"" + entry + "\" from database");
}
}
@ -324,11 +323,11 @@ public class DBController {
if (!filmsStreamURL.contains(entry)) {
stmt.executeUpdate("delete from film_streaming where streamUrl = \"" + entry + "\"");
connection.commit();
stmt.close();
LOGGER.info("removed \"" + entry + "\" from database");
}
}
stmt.close();
} catch (Exception e) {
LOGGER.error(e);
}
@ -346,13 +345,13 @@ public class DBController {
LOGGER.info("checking for entrys to add to DB ...");
// source is a single source of the sources list
for (tableData source : mainWindowController.getSourcesList()) {
for (SourceDataType source : mainWindowController.getSourcesList()) {
// if it's a local source check the folder for new film
if (source.getStreamUrl().equals("local")) {
for (String entry : new File(source.getTitle()).list()) {
if (source.getMode().equals("local")) {
for (String entry : new File(source.getPath()).list()) {
if (!filmsdbAll.contains(cutOffEnd(entry))) {
stmt.executeUpdate("insert into film_local values (0, \"" + cutOffEnd(entry) + "\", \""
+ source.getTitle() + "/" + entry + "\",\"favorite_border_black\",0)");
+ source.getPath() + "/" + entry + "\",\"favorite_border_black\",0)");
connection.commit();
stmt.close();
LOGGER.info("added \"" + entry + "\" to database");
@ -363,7 +362,7 @@ public class DBController {
// if it's a streaming source check the file for new films
for (String entry : filmsStreamURL) {
if (!filmsdbStreamURL.contains(entry)) {
JsonArray items = Json.parse(new FileReader(source.getTitle())).asObject().get("entries").asArray();
JsonArray items = Json.parse(new FileReader(source.getPath())).asObject().get("entries").asArray();
// for each item, check if it's the needed
for (JsonValue item : items) {
String streamUrl = item.asObject().getString("streamUrl", "");
@ -378,8 +377,7 @@ public class DBController {
ps.setString(5, item.asObject().getString("resolution", ""));
ps.setString(6, titel);
ps.setString(7, streamUrl);
ps.setString(8, "favorite_border_black");
ps.setBoolean(9, false);
ps.setBoolean(8, false);
ps.addBatch(); // adds the entry
LOGGER.info("added \"" + titel + "\" to database");
filmsAll.add(cutOffEnd(titel));
@ -401,11 +399,10 @@ public class DBController {
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");
System.out.println(rs.getString("rating"));
System.out.println(rs.getString("titel"));
System.out.println(rs.getString("streamUrl"));
System.out.println(rs.getString("cached") + "\n");
}
stmt.close();
rs.close();
@ -414,15 +411,12 @@ public class DBController {
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");
System.out.println(rs.getString("season"));
System.out.println(rs.getString("episode"));
System.out.println(rs.getString("rating"));
System.out.println(rs.getString("titel"));
System.out.println(rs.getString("streamUrl"));
System.out.println(rs.getString("cached") + "\n");
}
stmt.close();
rs.close();
@ -431,80 +425,21 @@ public class DBController {
LOGGER.error("An error occured, while printing all entries", e);
}
}
// get favorite status
public void getFavStatus(String name) {
try {
if (mainWindowController.getMode().equals("local")) {
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();
} else {
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 e) {
LOGGER.error("Ups! an error occured!", e);
}
}
// set rating=0 and favorite_border_black
public void dislike(String name, String streamUrl) {
LOGGER.info("defavorisieren ...");
try {
if (mainWindowController.getMode().equals("local")) {
Statement stmt = connection.createStatement();
stmt.executeUpdate("UPDATE film_local SET rating=0,favIcon='favorite_border_black' WHERE titel=\"" + name + "\";");
connection.commit();
stmt.close();
} else {
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
public void like(String name, String streamUrl) {
LOGGER.info("favorisieren ...");
try {
if (mainWindowController.getMode().equals("local")) {
Statement stmt = connection.createStatement();
stmt.executeUpdate("UPDATE film_local SET rating=1,favIcon='favorite_black' WHERE titel=\"" + name + "\";");
connection.commit();
stmt.close();
} else {
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 {
/**
* update the database entry for the given film, rating = 0
* @param name of the film
* @param streamUrl URL of the film
*/
public void dislike(String streamUrl) {
LOGGER.info("dislike " + streamUrl);
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 + "\";");
if (mainWindowController.getMode().equals("local")) {
stmt.executeUpdate("UPDATE film_local SET rating=0 WHERE streamUrl=\"" + streamUrl + "\";");
} else {
stmt.executeUpdate("UPDATE film_streaming SET rating=0 WHERE streamUrl=\"" + streamUrl + "\";");
}
connection.commit();
stmt.close();
} catch (SQLException e) {
@ -512,6 +447,71 @@ public class DBController {
}
}
/**
* update the database entry for the given film, rating = 1
* @param name of the film
* @param streamUrl URL of the film
*/
public void like(String streamUrl) {
LOGGER.info("like " + streamUrl);
try {
Statement stmt = connection.createStatement();
if (mainWindowController.getMode().equals("local")) {
stmt.executeUpdate("UPDATE film_local SET rating=1 WHERE streamUrl=\"" + streamUrl + "\";");
} else {
stmt.executeUpdate("UPDATE film_streaming SET rating=1 WHERE streamUrl=\"" + streamUrl + "\";");
}
connection.commit();
stmt.close();
} catch (SQLException e) {
LOGGER.error("Ups! an error occured!", e);
}
}
/**
* update the database entry for the given film, cached = 1
* @param streamUrl URL of the film
*/
void setCached(String streamUrl) {
try {
Statement stmt = connection.createStatement();
if (mainWindowController.getMode().equals("local")) {
stmt.executeUpdate("UPDATE film_local SET cached=1 WHERE streamUrl=\"" + streamUrl + "\";");
} else {
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);
}
}
/**
* add the received data to the cache table
* @param streamUrl URL of the film
* @param Title
* @param Year
* @param Rated
* @param Released
* @param Runtime
* @param Genre
* @param Director
* @param Writer
* @param Actors
* @param Plot
* @param Language
* @param Country
* @param Awards
* @param Metascore
* @param imdbRating
* @param Type
* @param imdbVotes
* @param imdbID
* @param Poster
* @param Response
* @throws SQLException
*/
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{
@ -546,6 +546,10 @@ public class DBController {
LOGGER.info("done!");
}
/**
* sets the cached data to mwc's TextFlow
* @param streamUrl URL of the film
*/
public void readCache(String streamUrl) {
try {
Statement stmt = connection.createStatement();
@ -573,7 +577,7 @@ public class DBController {
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++;

View File

@ -32,44 +32,34 @@ import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.image.ImageView;
public class tableData {
private final IntegerProperty year = new SimpleIntegerProperty();
public class FilmTabelDataType {
private final IntegerProperty season = new SimpleIntegerProperty();
private final IntegerProperty episode = new SimpleIntegerProperty();
private final DoubleProperty rating = new SimpleDoubleProperty();
private final StringProperty resolution = new SimpleStringProperty();
private final StringProperty title = new SimpleStringProperty();
private final StringProperty streamUrl = new SimpleStringProperty();
private final SimpleObjectProperty<ImageView> image = new SimpleObjectProperty<>();
private final BooleanProperty cached = new SimpleBooleanProperty();
/**
/** TODO rating boolean
* tableData is the data-type of tree-table-view
* @param year the release year of the film
* @param season season if it's a series
* @param episode episode if it's a series
* @param rating indicator for favourites, used for sorting the items
* @param resolution resolution of the film
* @param rating indicator for favorites, used for sorting the items
* @param titel title of the film
* @param streamUrl the concrete path to the file or the URL
* @param image the favourite icon
* @param cached indicator for caching status
*/
public tableData (final int year, final int season, final int episode, final double rating, final String resolution, final String title, final String streamUrl, final ImageView image, final boolean cached) {
this.year.set(year);
public FilmTabelDataType(final int season, final int episode, final double rating, final String title,
final String streamUrl, final ImageView image, final boolean cached) {
this.season.set(season);
this.episode.set(episode);
this.rating.set(rating);
this.resolution.set(resolution);
this.title.set(title);
this.streamUrl.set(streamUrl);
this.image.set(image);
this.cached.set(cached);
}
public IntegerProperty yearProperty(){
return year;
}
public IntegerProperty seasonProperty(){
return season;
@ -83,10 +73,6 @@ public class tableData {
return rating;
}
public StringProperty resolutionProperty(){
return resolution;
}
public StringProperty titleProperty(){
return title;
}
@ -103,10 +89,6 @@ public class tableData {
return cached;
}
public final int getYear() {
return yearProperty().get();
}
public final int getSeason() {
return seasonProperty().get();
@ -119,10 +101,6 @@ public class tableData {
public final double getRating() {
return ratingProperty().get();
}
public final String getResolution() {
return resolutionProperty().get();
}
public final String getTitle() {
return titleProperty().get();
@ -141,9 +119,6 @@ public class tableData {
}
public final void setYear(int year) {
yearProperty().set(year);
}
public final void setSeason(int season) {
seasonProperty().set(season);
@ -157,10 +132,6 @@ public class tableData {
ratingProperty().set(rating);
}
public final void setResolution(String resolution) {
resolutionProperty().set(resolution);
}
public final void setTitle(String title) {
titleProperty().set(title);
}

View File

@ -0,0 +1,64 @@
/**
* 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.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class SourceDataType {
private final StringProperty path = new SimpleStringProperty();
private final StringProperty mode = new SimpleStringProperty();
/**
* data type for the source table
* @param path of the source
* @param mode of the source, stream or local
*/
public SourceDataType (final String path, final String mode) {
this.path.set(path);
this.mode.set(mode);
}
public StringProperty pathProperty(){
return path;
}
public StringProperty modeProperty(){
return mode;
}
public final String getPath() {
return pathProperty().get();
}
public final String getMode() {
return modeProperty().get();
}
public final void setPath(String path) {
pathProperty().set(path);
}
public final void setMode(String mode) {
modeProperty().set(mode);
}
}

View File

@ -26,9 +26,7 @@ branchLbl = Updatezweig
columnName = Name
columnRating = Bewertung
columnStreamUrl = Datei Name
columnResolution = Aufl\u00F6sung
columnSeason = Staffel
columnYear = Jahr
#error translations
errorUpdateV = Beim ausf\u00FChren des Updates ist ein Fehler aufgetreten! \nError: could not check update version (nvc)\nWeitere Hilfe erhalten sie unter www.kellerkinder.xyz \noder wenden sie sich an support@kellerkinder.xyz

View File

@ -26,9 +26,7 @@ branchLbl = Branch
columnName = Name
columnRating = Rating
columnStreamUrl = File Name
columnResolution = Resolution
columnSeason = Season
columnYear = Year
#error translations
errorUpdateV = An error has occurred during update! \nError: could not check update version (nvc) \nTo get help, visit www.kellerkinder.xyz \nor contcat support@kellerkinder.xyz