minor fixes
* fixed some issues with the DBController * added an api key as workaround for no (rework of apiQuery is still planed)
This commit is contained in:
parent
70a6485a36
commit
ae525f6c49
Binary file not shown.
Binary file not shown.
|
@ -115,16 +115,20 @@ public class DBController {
|
||||||
ea.printStackTrace();
|
ea.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//getting all files from the selected directory TODO rework
|
||||||
String[] entries = new File(mainWindowController.getPath()).list();
|
String[] entries = new File(mainWindowController.getPath()).list();
|
||||||
if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){
|
if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){
|
||||||
System.out.println("Kein Pfad angegeben"); //if path == null or ""
|
System.out.println("Kein Pfad angegeben"); //if path == null or ""
|
||||||
}else{
|
}else if(new File(mainWindowController.getPath()).exists()) {
|
||||||
System.out.println(entries.length);
|
System.out.println(entries.length);
|
||||||
for(int i=0;i!=entries.length;i++){
|
for(int i=0;i!=entries.length;i++){
|
||||||
filmsDir.add(cutOffEnd(entries[i]));
|
filmsDir.add(cutOffEnd(entries[i]));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
System.out.println(mainWindowController.getPath() + "dosen't exist!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//getting all entries from the streaming lists
|
||||||
for(int v=0; v< mainWindowController.streamingData.size(); v++){
|
for(int v=0; v< mainWindowController.streamingData.size(); v++){
|
||||||
String fileName = mainWindowController.getStreamingPath()+"/"+mainWindowController.streamingData.get(v).getStreamUrl();
|
String fileName = mainWindowController.getStreamingPath()+"/"+mainWindowController.streamingData.get(v).getStreamUrl();
|
||||||
try {
|
try {
|
||||||
|
@ -138,7 +142,9 @@ public class DBController {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//add all entries to filmsAll and filmsdbAl, for later comparing
|
||||||
filmsAll.addAll(filmsDir);
|
filmsAll.addAll(filmsDir);
|
||||||
filmsAll.addAll(filmsStream);
|
filmsAll.addAll(filmsStream);
|
||||||
filmsdbAll.addAll(filmsdbLocal);
|
filmsdbAll.addAll(filmsdbLocal);
|
||||||
|
@ -146,6 +152,11 @@ public class DBController {
|
||||||
System.out.println("films in directory: "+filmsAll.size());
|
System.out.println("films in directory: "+filmsAll.size());
|
||||||
System.out.println("filme in db: "+filmsdbAll.size());
|
System.out.println("filme in db: "+filmsdbAll.size());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* if filmsdbAll.size() == 0 database is empty, we need to fill it
|
||||||
|
* else check if there is something to remove or to add
|
||||||
|
* TODO separate local and streaming for better error handling
|
||||||
|
*/
|
||||||
if(filmsdbAll.size() == 0){
|
if(filmsdbAll.size() == 0){
|
||||||
System.out.println("creating entries ...");
|
System.out.println("creating entries ...");
|
||||||
|
|
||||||
|
@ -155,7 +166,7 @@ public class DBController {
|
||||||
|
|
||||||
if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){
|
if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){
|
||||||
System.out.println("Kein Pfad angegeben"); //if path == null or ""
|
System.out.println("Kein Pfad angegeben"); //if path == null or ""
|
||||||
}else{
|
}else if(new File(mainWindowController.getPath()).exists()){
|
||||||
for(int j=0;j!=entries.length;j++) //goes through all the files in the directory
|
for(int j=0;j!=entries.length;j++) //goes through all the files in the directory
|
||||||
{
|
{
|
||||||
ps.setInt(1, 0); //rating as integer 1. column
|
ps.setInt(1, 0); //rating as integer 1. column
|
||||||
|
@ -198,12 +209,10 @@ public class DBController {
|
||||||
ps.close();
|
ps.close();
|
||||||
psS.close();
|
psS.close();
|
||||||
}catch (SQLException ea) {
|
}catch (SQLException ea) {
|
||||||
System.err.println("Konnte nicht ausgef<65>hrt werden");
|
System.err.println("Ups! an error occured!");
|
||||||
ea.printStackTrace();
|
ea.printStackTrace();
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
try {
|
try {
|
||||||
checkAddEntry(); //check if added a new file
|
checkAddEntry(); //check if added a new file
|
||||||
|
@ -271,7 +280,7 @@ public class DBController {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
stmt = connection.createStatement();
|
stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = '"+name+"';" );
|
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = \""+name+"\";" );
|
||||||
if(rs.getString(4).equals("favorite_black")){
|
if(rs.getString(4).equals("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)));
|
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{
|
}else{
|
||||||
|
@ -282,7 +291,7 @@ public class DBController {
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
try {
|
try {
|
||||||
stmt = connection.createStatement();
|
stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_streaming WHERE titel = '"+name+"';" );
|
ResultSet rs = stmt.executeQuery("SELECT * FROM film_streaming WHERE titel = \""+name+"\";" );
|
||||||
if(rs.getString(8).equals("favorite_black")){
|
if(rs.getString(8).equals("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(9)));
|
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(9)));
|
||||||
}else{
|
}else{
|
||||||
|
@ -305,25 +314,30 @@ public class DBController {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
|
|
||||||
for(int a=0; a<filmsdbLocal.size(); a++){
|
for(int a=0; a<filmsdbLocal.size(); a++){
|
||||||
if(filmsDir.contains(filmsdbLocal.get(a))){
|
if(!filmsDir.contains(filmsdbLocal.get(a))){
|
||||||
}else{
|
try {
|
||||||
stmt.executeUpdate("delete from film_local where titel = '"+filmsdbLocal.get(a)+"'");
|
stmt.executeUpdate("delete from film_local where titel = \""+filmsdbLocal.get(a) + "\"");
|
||||||
connection.commit();
|
connection.commit();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
System.out.println("removed \""+filmsdbLocal.get(a)+"\" from databsae");
|
System.out.println("removed \""+filmsdbLocal.get(a)+"\" from databsae");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int b=0; b<filmsdbStreamURL.size(); b++){
|
for(int b=0; b<filmsdbStreamURL.size(); b++){
|
||||||
if(filmsStreamURL.contains(filmsdbStreamURL.get(b))){
|
if(!filmsStreamURL.contains(filmsdbStreamURL.get(b))){
|
||||||
}else{
|
try {
|
||||||
stmt.executeUpdate("delete from film_streaming where titel = '"+filmsdbStream.get(b)+"'");
|
stmt.executeUpdate("delete from film_streaming where titel = \"" + filmsdbStream.get(b) + "\"");
|
||||||
connection.commit();
|
connection.commit();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
System.out.println("removed \""+filmsdbStream.get(b)+"\" from databsae");
|
System.out.println("removed \""+filmsdbStream.get(b)+"\" from databsae");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -342,9 +356,8 @@ public class DBController {
|
||||||
int i=0;
|
int i=0;
|
||||||
|
|
||||||
for(int a=0; a<filmsDir.size(); a++){
|
for(int a=0; a<filmsDir.size(); a++){
|
||||||
if(filmsdbLocal.contains(filmsDir.get(a))){
|
if(!filmsdbLocal.contains(filmsDir.get(a))){
|
||||||
}else{
|
stmt.executeUpdate("insert into film_local values (0, \""+cutOffEnd(entries[a])+"\", \""+entries[a]+"\",\"favorite_border_black\",0)");
|
||||||
stmt.executeUpdate("insert into film_local values (0, '"+cutOffEnd(entries[a])+"', '"+entries[a]+"','favorite_border_black',0)");
|
|
||||||
connection.commit();
|
connection.commit();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
System.out.println("added \""+filmsDir.get(a)+"\" to databsae");
|
System.out.println("added \""+filmsDir.get(a)+"\" to databsae");
|
||||||
|
@ -361,23 +374,23 @@ public class DBController {
|
||||||
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();
|
||||||
System.out.println(items.size()+", "+i+"; "+b);
|
System.out.println(items.size()+", "+i+"; "+b);
|
||||||
String streamURL = items.get(i).asObject().getString("streamUrl","");
|
String streamURL = items.get(i).asObject().getString("streamUrl","");
|
||||||
String titel = items.get(i).asObject().getString("titel","");
|
String titel = items.get(i).asObject().getString("titel","");
|
||||||
|
|
||||||
|
if(streamURL.equals(filmsStreamURL.get(b))){
|
||||||
|
System.out.println("added \""+titel+"\"");
|
||||||
|
|
||||||
if(streamURL.equals(filmsStreamURL.get(b))){
|
ps.setInt(1, items.get(i).asObject().getInt("year", 0));
|
||||||
System.out.println("hinzuf<EFBFBD>gen \""+titel+"\"");
|
ps.setInt(2, items.get(i).asObject().getInt("season", 0));
|
||||||
|
ps.setInt(3, items.get(i).asObject().getInt("episode", 0));
|
||||||
ps.setInt(1, items.get(i).asObject().getInt("year", 0));
|
ps.setInt(4, 0);
|
||||||
ps.setInt(2, items.get(i).asObject().getInt("season", 0));
|
ps.setString(5, items.get(i).asObject().getString("resolution", ""));
|
||||||
ps.setInt(3, items.get(i).asObject().getInt("episode", 0));
|
ps.setString(6, items.get(i).asObject().getString("titel",""));
|
||||||
ps.setInt(4, 0);
|
ps.setString(7, items.get(i).asObject().getString("streamUrl", ""));
|
||||||
ps.setString(5, items.get(i).asObject().getString("resolution", ""));
|
ps.setString(8, "favorite_border_black");
|
||||||
ps.setString(6, items.get(i).asObject().getString("titel",""));
|
ps.setBoolean(9, false);
|
||||||
ps.setString(7, items.get(i).asObject().getString("streamUrl", ""));
|
ps.addBatch(); // adds the entry
|
||||||
ps.setString(8, "favorite_border_black");
|
}
|
||||||
ps.setBoolean(9, false);
|
|
||||||
ps.addBatch(); // adds the entry
|
|
||||||
}
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -428,14 +441,14 @@ public class DBController {
|
||||||
void getFavStatus(String name){
|
void getFavStatus(String name){
|
||||||
try{
|
try{
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT titel, rating, favIcon FROM film_local WHERE titel = '"+name+"';" ); //SQL Befehl
|
ResultSet rs = stmt.executeQuery("SELECT titel, rating, favIcon FROM film_local WHERE titel = \""+name+"\";" ); //SQL Befehl
|
||||||
System.out.println("local:"+rs.getString("rating")+", "+rs.getString("titel")+", "+rs.getString("favIcon"));
|
System.out.println("local:"+rs.getString("rating")+", "+rs.getString("titel")+", "+rs.getString("favIcon"));
|
||||||
stmt.close();
|
stmt.close();
|
||||||
rs.close();
|
rs.close();
|
||||||
}catch(SQLException e){
|
}catch(SQLException e){
|
||||||
try {
|
try {
|
||||||
Statement stmtS = connection.createStatement();
|
Statement stmtS = connection.createStatement();
|
||||||
ResultSet rsS = stmtS.executeQuery("SELECT titel, rating, favIcon FROM film_streaming WHERE titel = '"+name+"';" );
|
ResultSet rsS = stmtS.executeQuery("SELECT titel, rating, favIcon FROM film_streaming WHERE titel = \""+name+"\";" );
|
||||||
System.out.println("streaming:"+rsS.getString("rating")+", "+rsS.getString("titel")+", "+rsS.getString("favIcon"));
|
System.out.println("streaming:"+rsS.getString("rating")+", "+rsS.getString("titel")+", "+rsS.getString("favIcon"));
|
||||||
stmtS.close();
|
stmtS.close();
|
||||||
rsS.close();
|
rsS.close();
|
||||||
|
@ -451,7 +464,7 @@ public class DBController {
|
||||||
System.out.println("defavorisieren ...");
|
System.out.println("defavorisieren ...");
|
||||||
try{
|
try{
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("UPDATE film_local SET rating=0,favIcon='favorite_border_black' WHERE titel='"+name+"';");
|
stmt.executeUpdate("UPDATE film_local SET rating=0,favIcon='favorite_border_black' WHERE titel=\""+name+"\";");
|
||||||
connection.commit();
|
connection.commit();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
}catch(SQLException e){
|
}catch(SQLException e){
|
||||||
|
@ -460,7 +473,7 @@ public class DBController {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("UPDATE film_streaming SET rating=0,favIcon='favorite_border_black' WHERE streamUrl='"+streamUrl+"';");
|
stmt.executeUpdate("UPDATE film_streaming SET rating=0,favIcon='favorite_border_black' WHERE streamUrl=\""+streamUrl+"\";");
|
||||||
connection.commit();
|
connection.commit();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (SQLException e1) {
|
} catch (SQLException e1) {
|
||||||
|
@ -473,7 +486,7 @@ public class DBController {
|
||||||
System.out.println("favorisieren ...");
|
System.out.println("favorisieren ...");
|
||||||
try{
|
try{
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("UPDATE film_local SET rating=1,favIcon='favorite_black' WHERE titel='"+name+"';");
|
stmt.executeUpdate("UPDATE film_local SET rating=1,favIcon='favorite_black' WHERE titel=\""+name+"\";");
|
||||||
connection.commit();
|
connection.commit();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
}catch(SQLException e){
|
}catch(SQLException e){
|
||||||
|
@ -482,7 +495,7 @@ public class DBController {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("UPDATE film_streaming SET rating=1,favIcon='favorite_black' WHERE streamUrl='"+streamUrl+"';");
|
stmt.executeUpdate("UPDATE film_streaming SET rating=1,favIcon='favorite_black' WHERE streamUrl=\""+streamUrl+"\";");
|
||||||
connection.commit();
|
connection.commit();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (SQLException e1) {
|
} catch (SQLException e1) {
|
||||||
|
@ -494,7 +507,7 @@ public class DBController {
|
||||||
void setCached(String streamUrl) throws SQLException{
|
void setCached(String streamUrl) throws SQLException{
|
||||||
try{
|
try{
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("UPDATE film_local SET cached=1 WHERE streamUrl='"+streamUrl+"';");
|
stmt.executeUpdate("UPDATE film_local SET cached=1 WHERE streamUrl=\""+streamUrl+"\";");
|
||||||
connection.commit();
|
connection.commit();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
}catch(SQLException e){
|
}catch(SQLException e){
|
||||||
|
@ -503,7 +516,7 @@ public class DBController {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("UPDATE film_streaming SET cached=1 WHERE streamUrl='"+streamUrl+"';");
|
stmt.executeUpdate("UPDATE film_streaming SET cached=1 WHERE streamUrl=\""+streamUrl+"\";");
|
||||||
connection.commit();
|
connection.commit();
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (SQLException e1) {
|
} catch (SQLException e1) {
|
||||||
|
@ -549,7 +562,7 @@ public class DBController {
|
||||||
void readCache(String streamUrl){
|
void readCache(String streamUrl){
|
||||||
try{
|
try{
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM cache WHERE streamUrl='"+streamUrl+"';");
|
ResultSet rs = stmt.executeQuery("SELECT * FROM cache WHERE streamUrl=\""+streamUrl+"\";");
|
||||||
ArrayList<Text> nameText = new ArrayList<Text>();
|
ArrayList<Text> nameText = new ArrayList<Text>();
|
||||||
ArrayList<Text> responseText = new ArrayList<Text>();
|
ArrayList<Text> responseText = new ArrayList<Text>();
|
||||||
String fontFamily = main.getFONT_FAMILY();
|
String fontFamily = main.getFONT_FAMILY();
|
||||||
|
|
|
@ -38,7 +38,8 @@ public class apiQuery{
|
||||||
private Image im;
|
private Image im;
|
||||||
private String[] responseString = new String[20];
|
private String[] responseString = new String[20];
|
||||||
private String posterCache;
|
private String posterCache;
|
||||||
private String apiURL = "https://www.omdbapi.com/?";
|
private String apiURL = "https://www.omdbapi.com/?apikey=";
|
||||||
|
private String apiKey = "b9f9fd23";
|
||||||
ArrayList<Text> responseText = new ArrayList<Text>();
|
ArrayList<Text> responseText = new ArrayList<Text>();
|
||||||
ArrayList<Text> nameText = new ArrayList<Text>();
|
ArrayList<Text> nameText = new ArrayList<Text>();
|
||||||
|
|
||||||
|
@ -75,7 +76,7 @@ public class apiQuery{
|
||||||
moviename = moviename.replace(" ", "+");
|
moviename = moviename.replace(" ", "+");
|
||||||
|
|
||||||
//queryURL is apiURL and additional parameters, response-types: http,json,xml (must be json, since the response is processed with minimal-json )
|
//queryURL is apiURL and additional parameters, response-types: http,json,xml (must be json, since the response is processed with minimal-json )
|
||||||
queryURL = new URL(apiURL + "t=" + moviename + "&plot=full&r=json");
|
queryURL = new URL(apiURL + apiKey + "&t=" + moviename + "&plot=full&r=json");
|
||||||
is = queryURL.openStream();
|
is = queryURL.openStream();
|
||||||
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ public class apiQuery{
|
||||||
}
|
}
|
||||||
|
|
||||||
//if response == false then show mainWindowController.noFilmFound else create new Texts and add them to flowText
|
//if response == false then show mainWindowController.noFilmFound else create new Texts and add them to flowText
|
||||||
if(responseString[19].equals("False")){
|
if(retdata.contains("\"Response\":\"False\"")){ //TODO + FIXME
|
||||||
mainWindowController.textFlow.getChildren().add(new Text(mainWindowController.noFilmFound));
|
mainWindowController.textFlow.getChildren().add(new Text(mainWindowController.noFilmFound));
|
||||||
im = new Image("resources/icons/close_black_2048x2048.png");
|
im = new Image("resources/icons/close_black_2048x2048.png");
|
||||||
mainWindowController.image1.setImage(im);
|
mainWindowController.image1.setImage(im);
|
||||||
|
|
Loading…
Reference in New Issue