diff --git a/bin/application/DBController.class b/bin/application/DBController.class index 4a9c489..a1a5c42 100644 Binary files a/bin/application/DBController.class and b/bin/application/DBController.class differ diff --git a/bin/application/MainWindowController$1.class b/bin/application/MainWindowController$1.class index 68b1b57..181a88f 100644 Binary files a/bin/application/MainWindowController$1.class and b/bin/application/MainWindowController$1.class differ diff --git a/bin/application/MainWindowController$2.class b/bin/application/MainWindowController$2.class index 24ed899..70f04c3 100644 Binary files a/bin/application/MainWindowController$2.class and b/bin/application/MainWindowController$2.class differ diff --git a/bin/application/MainWindowController$3.class b/bin/application/MainWindowController$3.class index 05dc50b..fc86b80 100644 Binary files a/bin/application/MainWindowController$3.class and b/bin/application/MainWindowController$3.class differ diff --git a/bin/application/MainWindowController$4.class b/bin/application/MainWindowController$4.class index dbce121..d91fced 100644 Binary files a/bin/application/MainWindowController$4.class and b/bin/application/MainWindowController$4.class differ diff --git a/bin/application/MainWindowController$5.class b/bin/application/MainWindowController$5.class index 1e47f18..efb4d6a 100644 Binary files a/bin/application/MainWindowController$5.class and b/bin/application/MainWindowController$5.class differ diff --git a/bin/application/MainWindowController$6.class b/bin/application/MainWindowController$6.class index ea12f4a..ea8dddf 100644 Binary files a/bin/application/MainWindowController$6.class and b/bin/application/MainWindowController$6.class differ diff --git a/bin/application/MainWindowController$7.class b/bin/application/MainWindowController$7.class index 176f270..9f0a1b0 100644 Binary files a/bin/application/MainWindowController$7.class and b/bin/application/MainWindowController$7.class differ diff --git a/bin/application/MainWindowController.class b/bin/application/MainWindowController.class index 76ac617..5541174 100644 Binary files a/bin/application/MainWindowController.class and b/bin/application/MainWindowController.class differ diff --git a/bin/application/apiQuery.class b/bin/application/apiQuery.class index 9de2779..ab95a6e 100644 Binary files a/bin/application/apiQuery.class and b/bin/application/apiQuery.class differ diff --git a/bin/application/streamUiData.class b/bin/application/streamUiData.class deleted file mode 100644 index 034c7a2..0000000 Binary files a/bin/application/streamUiData.class and /dev/null differ diff --git a/bin/application/tableData.class b/bin/application/tableData.class new file mode 100644 index 0000000..00d2897 Binary files /dev/null and b/bin/application/tableData.class differ diff --git a/src/application/DBController.java b/src/application/DBController.java index 3dc251a..9e2f3fd 100644 --- a/src/application/DBController.java +++ b/src/application/DBController.java @@ -1,7 +1,6 @@ /** * DBController for Project HomeFlix * connection is in manual commit! - * TODO arraylists not string -> streamUIData */ package application; @@ -57,15 +56,13 @@ public class DBController { try { // create a database connection connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH); - // Statement statement = connection.createStatement(); - // statement.setQueryTimeout(30); // set timeout to 30 sec. TODO don't know what to do with this - connection.setAutoCommit(false); //AutoCommit to false -> manual commit is active -// fuelleDatenbank(); } catch (SQLException e) { // if the error message is "out of memory", it probably means no database file is found System.err.println(e.getMessage()); } + + //close connection -> at the moment this kills the program // finally { // try { // if (connection != null) @@ -85,8 +82,8 @@ public class DBController { try { Statement stmt = connection.createStatement(); - stmt.executeUpdate("create table if not exists film_local (rating, titel, streamUrl, favIcon)"); - stmt.executeUpdate("create table if not exists film_streaming (year, season, episode, rating, resolution, titel, streamUrl, favIcon)"); + stmt.executeUpdate("create table if not exists film_local (rating, titel, streamUrl, favIcon, cached)"); + stmt.executeUpdate("create table if not exists film_streaming (year, season, episode, rating, resolution, titel, streamUrl, favIcon, cached)"); stmt.close(); } catch (SQLException e1) { e1.printStackTrace(); @@ -144,13 +141,12 @@ public class DBController { System.out.println("films in directory: "+filmsAll.size()); System.out.println("filme in db: "+filmsdbAll.size()); - if(filmsdbAll.size() == 0){ System.out.println("creating entries ..."); try{ - ps = connection.prepareStatement("insert into film_local values (?, ?, ?, ?)"); - psS = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?)"); + ps = connection.prepareStatement("insert into film_local values (?, ?, ?, ?, ?)"); + psS = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){ System.out.println("Kein Pfad angegeben"); //if path == null or "" @@ -161,7 +157,8 @@ public class DBController { ps.setString(2, cutOffEnd(entries[j])); //name as String without ending 2. column ps.setString(3,entries[j]); //path as String 3. column ps.setString(4, "favorite_border_black"); - ps.addBatch(); // add command to prepared statement + ps.setBoolean(5, false); + ps.addBatch(); // add command to prepared statement } } @@ -182,6 +179,7 @@ public class DBController { psS.setString(6, item.asObject().getString("titel","")); psS.setString(7, item.asObject().getString("streamUrl", "")); psS.setString(8, "favorite_border_black"); + psS.setBoolean(9, false); psS.addBatch(); // add command to prepared statement } } catch (IOException e) { @@ -189,7 +187,7 @@ public class DBController { } } } - ps.executeBatch(); //execute statement to write entries into table + ps.executeBatch(); //execute statement to write entries into table psS.executeBatch(); connection.commit(); ps.close(); @@ -203,15 +201,26 @@ public class DBController { try { try { - checkAddEntry(); + checkAddEntry(); //check if added a new file } catch (IOException e) { e.printStackTrace(); - } //check if added a new file - checkRemoveEntry(); //check if removed a file + } + checkRemoveEntry(); //check if removed a file } catch (SQLException e) { e.printStackTrace(); } } + + //start of cache-table + try { + Statement stmt = connection.createStatement(); + stmt.executeUpdate( "create table if not exists cache (streamUrl, Title, Year, Rated, Released, Runtime, Genre, Director, Writer," //streamUrl is primary key + +" Actors, Plot, Language, Country, Awards, Metascore, imdbRating, imdbVotes, imdbID, Type, Poster, Response)"); + stmt.close(); + } catch (SQLException e1) { + e1.printStackTrace(); + } + } //loading data from database to mainWindowController @@ -223,9 +232,9 @@ public class DBController { ResultSet rs = stmt.executeQuery("SELECT * FROM film_local"); while (rs.next()) { if(rs.getString(4).equals("favorite_black")){ - mainWindowController.newData.add( new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black))); + mainWindowController.localFilms.add( new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black),rs.getBoolean(5))); }else{ - mainWindowController.newData.add( new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black))); + mainWindowController.localFilms.add( new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black),rs.getBoolean(5))); } } stmt.close(); @@ -235,9 +244,9 @@ public class DBController { rs = stmt.executeQuery("SELECT * FROM film_streaming;"); while (rs.next()) { if(rs.getString(8).equals("favorite_black")){ - mainWindowController.streamData.add(new streamUiData(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))); + mainWindowController.streamingFilms.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(5))); }else{ - mainWindowController.streamData.add(new streamUiData(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))); + mainWindowController.streamingFilms.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(5))); } } stmt.close(); @@ -259,9 +268,9 @@ public class DBController { stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = '"+name+"';" ); if(rs.getString(4).equals("favorite_black")){ - mainWindowController.newData.set(i, new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black))); + mainWindowController.localFilms.set(i, new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black),rs.getBoolean(5))); }else{ - mainWindowController.newData.set(i, new streamUiData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black))); + mainWindowController.localFilms.set(i, new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_border_black),rs.getBoolean(5))); } stmt.close(); rs.close(); @@ -270,9 +279,9 @@ public class DBController { stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery("SELECT * FROM film_streaming WHERE titel = '"+name+"';" ); if(rs.getString(8).equals("favorite_black")){ - mainWindowController.streamData.set(i,new streamUiData(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))); + mainWindowController.streamingFilms.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(5))); }else{ - mainWindowController.streamData.set(i,new streamUiData(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))); + mainWindowController.streamingFilms.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(5))); } stmt.close(); rs.close(); @@ -313,13 +322,13 @@ public class DBController { System.out.println("checking for entrys to add to DB ..."); String[] entries = new File(mainWindowController.getPath()).list(); Statement stmt = connection.createStatement(); - PreparedStatement ps = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?)");; + PreparedStatement ps = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?, ?, ?)"); int i=0; for(int a=0; a treeTableViewfilm; + private TreeTableView treeTableViewfilm; @FXML - private TableView tableViewStreamingdata; + private TableView tableViewStreamingdata; @FXML JFXTextArea ta1; @FXML @@ -159,28 +159,28 @@ public class MainWindowController { private ImageView imv1; @FXML - TreeItem root = new TreeItem<>(new streamUiData(1, 1, 1, 5.0,"1", "filme","1", imv1)); + TreeItem root = new TreeItem<>(new tableData(1, 1, 1, 5.0,"1", "filme","1", imv1, false)); @FXML - TreeTableColumn columnRating = new TreeTableColumn<>("Rating"); + TreeTableColumn columnRating = new TreeTableColumn<>("Rating"); @FXML - TreeTableColumn columnTitel = new TreeTableColumn<>("Titel"); + TreeTableColumn columnTitel = new TreeTableColumn<>("Titel"); @FXML - TreeTableColumn columnStreamUrl = new TreeTableColumn<>("File Name"); + TreeTableColumn columnStreamUrl = new TreeTableColumn<>("File Name"); @FXML - TreeTableColumn columnResolution = new TreeTableColumn<>("Resolution"); + TreeTableColumn columnResolution = new TreeTableColumn<>("Resolution"); @FXML - TreeTableColumn columnYear = new TreeTableColumn<>("Year"); + TreeTableColumn columnYear = new TreeTableColumn<>("Year"); @FXML - TreeTableColumn columnSeason = new TreeTableColumn<>("Season"); + TreeTableColumn columnSeason = new TreeTableColumn<>("Season"); @FXML - TreeTableColumn columnEpisode = new TreeTableColumn<>("Episode"); + TreeTableColumn columnEpisode = new TreeTableColumn<>("Episode"); @FXML - private TreeItem streamingRoot =new TreeItem<>(new streamUiData(1 ,1 ,1 ,1.0 ,"1" ,"filme" ,"1", imv1)); + private TreeItem streamingRoot =new TreeItem<>(new tableData(1 ,1 ,1 ,1.0 ,"1" ,"filme" ,"1", imv1, false)); @FXML - private TableColumn dataNameColumn = new TableColumn<>("Datei Name"); + private TableColumn dataNameColumn = new TableColumn<>("Datei Name"); @FXML - private TableColumn dataNameEndColumn = new TableColumn<>("Datei Name mit Endung"); + private TableColumn dataNameEndColumn = new TableColumn<>("Datei Name mit Endung"); private boolean menutrue = false; //saves the position of menubtn (opened or closed) @@ -189,7 +189,7 @@ public class MainWindowController { static boolean firststart = false; private int hashA = -2055934614; private String version = "0.5.0"; - private String buildNumber = "117"; + private String buildNumber = "119"; private String versionName = "plasma cow"; private String buildURL = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/buildNumber.txt"; private String downloadLink = "https://raw.githubusercontent.com/Seil0/Project-HomeFlix/master/updates/downloadLink.txt"; @@ -213,7 +213,7 @@ public class MainWindowController { private String path; private String streamingPath; private String color; - private String Name; + private String name; private String datPath; private String autoUpdate; private String mode; @@ -244,11 +244,11 @@ public class MainWindowController { private File selectedStreamingFolder; ResourceBundle bundle; - private ObservableList filterData = FXCollections.observableArrayList(); + private ObservableList filterData = FXCollections.observableArrayList(); private ObservableList locals = FXCollections.observableArrayList("english (en_US)", "deutsch (de_DE)"); - ObservableList newData = FXCollections.observableArrayList(); //TODO rename to localFilms - ObservableList streamData = FXCollections.observableArrayList(); //TODO rename to streamingFilms - ObservableList streamingData = FXCollections.observableArrayList(); + ObservableList localFilms = FXCollections.observableArrayList(); + ObservableList streamingFilms = FXCollections.observableArrayList(); + ObservableList streamingData = FXCollections.observableArrayList(); private ImageView menu_icon_black = new ImageView(new Image("recources/icons/menu_icon_black.png")); private ImageView menu_icon_white = new ImageView(new Image("recources/icons/menu_icon_white.png")); private ImageView skip_previous_white = new ImageView(new Image("recources/icons/ic_skip_previous_white_18dp_1x.png")); @@ -338,7 +338,7 @@ public class MainWindowController { } }else if(mode.equals("streaming")){ try { - Desktop.getDesktop().browse(new URI(datPath)); //open the streaming Url in browser (TODO other option?) + Desktop.getDesktop().browse(new URI(datPath)); //open the streaming URL in browser (TODO other option?) } catch (URISyntaxException | IOException e) { showErrorMsg(errorOpenStream, (IOException) e); } @@ -519,8 +519,8 @@ public class MainWindowController { //"Main" Method called in Main.java main() when starting void setMain(Main main) { Updater = new updater(this,buildURL, downloadLink, aktBuildNumber, buildNumber); - ApiQuery = new apiQuery(this); dbController = new DBController(this); + ApiQuery = new apiQuery(this, dbController); } //Initialize the tables (treeTableViewfilm and tableViewStreamingdata) @@ -554,15 +554,30 @@ public class MainWindowController { //Change-listener for TreeTable treeTableViewfilm.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { @Override - public void changed(ObservableValue observable, Object oldVal, Object newVal) { + 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 + name = columnTitel.getCellData(selected); //get name of selected item datPath = columnStreamUrl.getCellData(selected); //get file path of selected item ta1.setText(""); //delete text in ta1 - ApiQuery.startQuery(Name); // start api query + + if(mode.equals("local")){ + if(localFilms.get(selected).getCached()==true){ + System.out.println("loading from cache: "+name); + dbController.readCache(datPath); + }else{ + ApiQuery.startQuery(name,datPath); // start api query + } + }else{ + if(streamingFilms.get(selected).getCached()==true){ + System.out.println("loading from cache: "+name); + dbController.readCache(datPath); + }else{ + ApiQuery.startQuery(name,datPath); // start api query + } + } ta1.positionCaret(0); //set cursor position in ta1 } }); @@ -584,14 +599,14 @@ public class MainWindowController { tfsearch.textProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable,String oldValue, String newValue) { - ObservableList helpData; + ObservableList helpData; filterData.removeAll(filterData); root.getChildren().remove(0,root.getChildren().size()); if(mode.equals("local")){ - helpData = newData; + helpData = localFilms; }else{ - helpData = streamData; + helpData = streamingFilms; } for(int i = 0; i < helpData.size(); i++){ @@ -601,7 +616,7 @@ public class MainWindowController { } for(int i = 0; i < filterData.size(); i++){ - root.getChildren().add(new TreeItem(filterData.get(i))); //add filtered data to root node after search + root.getChildren().add(new TreeItem(filterData.get(i))); //add filtered data to root node after search } if(tfsearch.getText().hashCode() == hashA){ setColor("000000"); @@ -633,13 +648,13 @@ public class MainWindowController { @Override public void handle(ActionEvent event) { if(mode.equals("streaming")){ - dbController.like(Name,streamData.get(selected).getStreamUrl()); + dbController.like(name,streamingFilms.get(selected).getStreamUrl()); }else{ - dbController.like(Name,newData.get(selected).getStreamUrl()); + dbController.like(name,localFilms.get(selected).getStreamUrl()); } - dbController.getFavStatus(Name); + dbController.getFavStatus(name); try { - dbController.refresh(Name, selected); + dbController.refresh(name, selected); } catch (SQLException e) { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Error"); @@ -655,13 +670,13 @@ public class MainWindowController { @Override public void handle(ActionEvent event) { if(mode.equals("streaming")){ - dbController.dislike(Name,streamData.get(selected).getStreamUrl()); + dbController.dislike(name,streamingFilms.get(selected).getStreamUrl()); }else{ - dbController.dislike(Name,newData.get(selected).getStreamUrl()); + dbController.dislike(name,localFilms.get(selected).getStreamUrl()); } - dbController.getFavStatus(Name); + dbController.getFavStatus(name); try { - dbController.refresh(Name, selected); + dbController.refresh(name, selected); } catch (SQLException e) { Alert alert = new Alert(AlertType.ERROR); alert.setTitle("Error"); @@ -682,14 +697,14 @@ public class MainWindowController { System.out.println("NAME Clicked -- sortType = " + paramT1 + ", SortType=" + paramT2); ArrayList fav_true = new ArrayList(); ArrayList fav_false = new ArrayList(); - ObservableList helpData; + ObservableList helpData; filterData.removeAll(filterData); root.getChildren().remove(0,root.getChildren().size()); if(mode.equals("local")){ - helpData = newData; + helpData = localFilms; }else{ - helpData = streamData; + helpData = streamingFilms; } @@ -720,7 +735,7 @@ public class MainWindowController { System.out.println(filterData.size()); for(int i = 0; i < filterData.size(); i++){ // System.out.println(filterData.get(i).getTitel()+"; "+filterData.get(i).getRating()); - root.getChildren().add(new TreeItem(filterData.get(i))); //add filtered data to root node after search + root.getChildren().add(new TreeItem(filterData.get(i))); //add filtered data to root node after search } } }); @@ -754,16 +769,16 @@ public class MainWindowController { private void refreshTable(){ if(mode.equals("local")){ - root.getChildren().set(selected, new TreeItem(newData.get(selected))); + root.getChildren().set(selected, new TreeItem(localFilms.get(selected))); }else if(mode.equals("streaming")){ - root.getChildren().set(selected, new TreeItem(streamData.get(selected))); + root.getChildren().set(selected, new TreeItem(streamingFilms.get(selected))); } } void addDataUI(){ if(mode.equals("local")){ - for(int i = 0; i < newData.size(); i++){ - root.getChildren().add(new TreeItem(newData.get(i))); //add data to root-node + for(int i = 0; i < localFilms.size(); i++){ + root.getChildren().add(new TreeItem(localFilms.get(i))); //add data to root-node } columnRating.setMaxWidth(90); columnTitel.setMaxWidth(290); @@ -772,8 +787,8 @@ public class MainWindowController { treeTableViewfilm.getColumns().get(5).setVisible(false); treeTableViewfilm.getColumns().get(6).setVisible(false); }else if(mode.equals("streaming")){ - for(int i = 0; i < streamData.size(); i++){ - root.getChildren().add(new TreeItem(streamData.get(i))); //add data to root-node + for(int i = 0; i < streamingFilms.size(); i++){ + root.getChildren().add(new TreeItem(streamingFilms.get(i))); //add data to root-node } columnTitel.setMaxWidth(150); columnResolution.setMaxWidth(65); @@ -790,18 +805,18 @@ public class MainWindowController { void loadStreamingSettings(){ if(getStreamingPath().equals("")||getStreamingPath().equals(null)){ - System.out.println("Kein Pfad angegeben"); //falls der Pfad null oder "" ist + System.out.println("Kein Pfad angegeben"); //if path equals "" or null }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 streamUiData(1,1,1,5.0,"1",titel ,data, imv1)); + 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(streamingData.get(i))); //fügt daten zur Rootnode hinzu + streamingRoot.getChildren().add( new TreeItem(streamingData.get(i))); //adds data to root-node } } } diff --git a/src/application/apiQuery.java b/src/application/apiQuery.java index dc66933..1fc9c6b 100644 --- a/src/application/apiQuery.java +++ b/src/application/apiQuery.java @@ -1,13 +1,12 @@ /** * apiQuery for Project HomeFlix * sends a query to the omdb api - * - * TODO build in a caching function */ package application; -import java.io.DataInputStream; +import java.io.BufferedReader; import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URL; import java.util.Scanner; @@ -22,19 +21,21 @@ import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; +@SuppressWarnings("unused") //TODO public class apiQuery{ - public apiQuery(MainWindowController m){ + public apiQuery(MainWindowController m, DBController db){ mainWindowController=m; + dbController=db; } private MainWindowController mainWindowController; + private DBController dbController; private Image im; private int fontSize = 20; private String fontFamily = "System"; - @SuppressWarnings("deprecation") //TODO - void startQuery(String input){ + void startQuery(String titel, String streamUrl){ URL url = null; Scanner sc = null; String apiurl = "https://www.omdbapi.com/?"; //API URL @@ -42,13 +43,13 @@ public class apiQuery{ String dataurl = null; String retdata = null; InputStream is = null; - DataInputStream dis = null; + BufferedReader br = null; try { //get film title sc = new Scanner(System.in); - moviename = input; + moviename = titel; // in case of no or "" Film title if (moviename == null || moviename.equals("")) { @@ -66,10 +67,10 @@ public class apiQuery{ url = new URL(dataurl); is = url.openStream(); - dis = new DataInputStream(is); + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); // lesen der Daten aus dem Antwort Stream - while ((retdata = dis.readLine()) != null) { + while ((retdata = br.readLine()) != null) { //retdata in json object parsen und anschließend das json Objekt "zerschneiden" System.out.println(retdata); JsonObject object = Json.parse(retdata).asObject(); @@ -89,15 +90,18 @@ public class apiQuery{ String metascoreV = object.getString("Metascore", ""); String imdbRatingV = object.getString("imdbRating", ""); - @SuppressWarnings("unused") String imdbVotesV = object.getString("imdbVotes", ""); - @SuppressWarnings("unused") String imdbIDV = object.getString("imdbID", ""); String typeV = object.getString("Type", ""); String posterURL = object.getString("Poster", ""); String response = object.getString("Response", ""); + dbController.addCache( streamUrl, titelV, yearV, ratedV, releasedV, runtimeV, genreV, directorV, writerV, actorsV, plotV, languageV, countryV, + awardsV, metascoreV, imdbRatingV, imdbVotesV, imdbIDV, typeV, posterURL, response); + dbController.setCached(streamUrl); + + // Text titelR = new Text (object.getString("Title", "")+"\n"); // titelR.setFont(Font.font (fontFamily, fontSize)); // Text yearR = new Text (object.getString("Year", "")+"\n"); @@ -221,8 +225,8 @@ public class apiQuery{ } finally { //closes datainputStream, InputStream,Scanner if not already done try { - if (dis != null) { - dis.close(); + if (br != null) { + br.close(); } if (is != null) { diff --git a/src/application/streamUiData.java b/src/application/tableData.java similarity index 81% rename from src/application/streamUiData.java rename to src/application/tableData.java index 8f801c5..1ea97ef 100644 --- a/src/application/streamUiData.java +++ b/src/application/tableData.java @@ -1,7 +1,9 @@ package application; +import javafx.beans.property.BooleanProperty; import javafx.beans.property.DoubleProperty; import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleObjectProperty; @@ -9,8 +11,7 @@ import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.scene.image.ImageView; -public class streamUiData { - +public class tableData { private final IntegerProperty year = new SimpleIntegerProperty(); private final IntegerProperty season = new SimpleIntegerProperty(); private final IntegerProperty episode = new SimpleIntegerProperty(); @@ -19,9 +20,10 @@ public class streamUiData { private final StringProperty titel = new SimpleStringProperty(); private final StringProperty streamUrl = new SimpleStringProperty(); private final SimpleObjectProperty image = new SimpleObjectProperty<>(); + private final BooleanProperty cached = new SimpleBooleanProperty(); - //uiData ist der Typ der Daten in der TreeTabelView - public streamUiData (final int year, final int season, final int episode, final double rating, final String resolution, final String titel, final String streamUrl, final ImageView image) { + //tableData is the data-type of tree-table-view + public tableData (final int year, final int season, final int episode, final double rating, final String resolution, final String titel, final String streamUrl, final ImageView image, final boolean cached) { this.year.set(year); this.season.set(season); this.episode.set(episode); @@ -30,6 +32,7 @@ public class streamUiData { this.titel.set(titel); this.streamUrl.set(streamUrl); this.image.set(image); + this.cached.set(cached); } public IntegerProperty yearProperty(){ @@ -64,6 +67,10 @@ public class streamUiData { return image; } + public BooleanProperty cachedProperty(){ + return cached; + } + public final int getYear() { return yearProperty().get(); @@ -96,6 +103,10 @@ public class streamUiData { public final ImageView getImage() { return imageProperty().get(); } + + public final boolean getCached(){ + return cachedProperty().get(); + } public final void setYear(int year) { @@ -129,4 +140,8 @@ public class streamUiData { public final void setImage(ImageView image) { imageProperty().set(image); } + + public final void setCached(boolean cached){ + cachedProperty().set(cached); + } }