worked on dbcontroller part 5
finished work on dbcontroller, one remaining bug in mainWindowController
This commit is contained in:
@ -1,12 +1,13 @@
|
||||
/**
|
||||
* DBController for Project HomeFlix
|
||||
* connection is in manual commit!
|
||||
* TODO <EFBFBD>berpr<EFBFBD>fen ob neue filme hinzu gekommen sind
|
||||
* TODO arraylists not string -> streamUIData
|
||||
*/
|
||||
|
||||
package application;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
@ -31,11 +32,15 @@ public class DBController {
|
||||
|
||||
private MainWindowController mainWindowController;
|
||||
private String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; // der Pfad der Datenbank-Datei
|
||||
private List<String> filmsdb = new ArrayList<String>();
|
||||
private List<String> filmsdbAll = new ArrayList<String>();
|
||||
private List<String> filmsdbLocal = new ArrayList<String>();
|
||||
private List<String> filmsdbStream = new ArrayList<String>();
|
||||
private List<String> filmsdbStreamURL = new ArrayList<String>();
|
||||
private List<String> filmsAll = new ArrayList<String>();
|
||||
private List<String> filmsDir = new ArrayList<String>();
|
||||
private List<String> filmsStream = new ArrayList<String>();
|
||||
private List<Integer> counter = new ArrayList<Integer>();
|
||||
private List<String> filmsStreamURL = new ArrayList<String>();
|
||||
private List<String> filmsStreamData = new ArrayList<String>();
|
||||
Connection connection = null;
|
||||
|
||||
public void main() {
|
||||
@ -67,7 +72,6 @@ public class DBController {
|
||||
|
||||
PreparedStatement ps;
|
||||
PreparedStatement psS;
|
||||
String[] entries = new File(mainWindowController.getPath()).list();
|
||||
|
||||
try {
|
||||
Statement stmt = connection.createStatement();
|
||||
@ -82,23 +86,24 @@ public class DBController {
|
||||
Statement stmt = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
|
||||
while (rs.next()) {
|
||||
filmsdb.add(rs.getString(2));
|
||||
filmsdbLocal.add(rs.getString(2));
|
||||
}
|
||||
stmt.close();
|
||||
rs.close();
|
||||
|
||||
rs = stmt.executeQuery("SELECT * FROM film_streaming;");
|
||||
while (rs.next()) {
|
||||
filmsdb.add(rs.getString(6));
|
||||
filmsdbStream.add(rs.getString(6));
|
||||
filmsdbStreamURL.add(rs.getString(7));
|
||||
}
|
||||
stmt.close();
|
||||
rs.close();
|
||||
}catch (SQLException ea){
|
||||
//TODO
|
||||
System.err.println("Ups! an error occured!");
|
||||
ea.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("filme in db: "+filmsdb.size());
|
||||
|
||||
|
||||
String[] entries = new File(mainWindowController.getPath()).list();
|
||||
for(int i=0;i!=entries.length;i++){
|
||||
filmsDir.add(cutOffEnd(entries[i]));
|
||||
}
|
||||
@ -110,6 +115,8 @@ public class DBController {
|
||||
JsonArray items = object.get("entries").asArray();
|
||||
for (JsonValue item : items) {
|
||||
filmsStream.add(item.asObject().getString("titel",""));
|
||||
filmsStreamURL.add(item.asObject().getString("streamUrl",""));
|
||||
filmsStreamData.add(fileName);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -117,10 +124,13 @@ public class DBController {
|
||||
}
|
||||
filmsAll.addAll(filmsDir);
|
||||
filmsAll.addAll(filmsStream);
|
||||
filmsdbAll.addAll(filmsdbLocal);
|
||||
filmsdbAll.addAll(filmsdbStream);
|
||||
System.out.println("films in directory: "+filmsAll.size());
|
||||
System.out.println("filme in db: "+filmsdbAll.size());
|
||||
|
||||
|
||||
if(filmsdb.size() == 0){
|
||||
if(filmsdbAll.size() == 0){
|
||||
System.out.println("creating entries ...");
|
||||
|
||||
try{
|
||||
@ -167,49 +177,19 @@ public class DBController {
|
||||
System.err.println("Konnte nicht ausgef<65>hrt werden");
|
||||
ea.printStackTrace();
|
||||
}
|
||||
}else if(filmsdb.size() == filmsAll.size()){
|
||||
for(int i=0;i<filmsAll.size();i++){
|
||||
if(filmsAll.contains(filmsdb.get(i))){
|
||||
}else{ //calls updateDB if there is a different name between db and dir
|
||||
int l=0;
|
||||
try {
|
||||
Statement stmt = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local");
|
||||
while (rs.next()) {
|
||||
if(filmsDir.contains(rs.getString(2))){
|
||||
l++;
|
||||
System.out.println("gleich L"+l);
|
||||
}else{
|
||||
l++;
|
||||
counter.add(l);
|
||||
System.out.println("ungleich L");
|
||||
}
|
||||
}
|
||||
stmt.close();
|
||||
rs.close();
|
||||
|
||||
rs = stmt.executeQuery("SELECT * FROM film_streaming;");
|
||||
while (rs.next()) {
|
||||
if(filmsStream.contains(rs.getString(6))){
|
||||
l++;
|
||||
System.out.println("gleich S"+l);
|
||||
}else{
|
||||
l++;
|
||||
counter.add(l);
|
||||
System.out.println("ungleich S");
|
||||
}
|
||||
}
|
||||
stmt.close();
|
||||
rs.close();
|
||||
System.out.println(counter);
|
||||
updateDB();
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}else {
|
||||
|
||||
|
||||
try {
|
||||
try {
|
||||
checkAddEntry();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} //check if added a new file
|
||||
checkRemoveEntry(); //check if removed a file
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else{
|
||||
addEntry(); //TODO calls updateDB if there is a different size between db and dir
|
||||
}
|
||||
}
|
||||
|
||||
@ -241,9 +221,11 @@ public class DBController {
|
||||
}
|
||||
|
||||
//refreshs the data in mainWindowController.newDaten and mainWindowController.streamData
|
||||
//TODO it seems that there is an issue at the moment with streaming refreshing wrong entry if there is more than one with the same name
|
||||
void refresh(String name,int i) throws SQLException{
|
||||
System.out.println("refresh ...");
|
||||
Statement stmt;
|
||||
Statement stmt;
|
||||
|
||||
try {
|
||||
stmt = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = '"+name+"';" );
|
||||
@ -264,34 +246,78 @@ public class DBController {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDB(){
|
||||
System.out.println("updating DB ...");
|
||||
for(int i=0; i<counter.size();i++){
|
||||
String ending = "";
|
||||
try{
|
||||
|
||||
Statement stmt = connection.createStatement();
|
||||
ResultSet rs = stmt.executeQuery("SELECT streamUrl FROM film_local WHERE titel='"+filmsdb.get(counter.get(i)-1)+"';");
|
||||
while (rs.next()) {
|
||||
ending=rs.getString(1);
|
||||
int pos = ending.lastIndexOf(".");
|
||||
ending = ending.substring(pos);
|
||||
System.out.println(pos);
|
||||
System.out.println(ending);
|
||||
}
|
||||
|
||||
stmt.executeUpdate("UPDATE film_local SET titel='"+filmsAll.get(counter.get(i)-1)+"', streamUrl='"+filmsAll.get(counter.get(i)-1)+ending+"' WHERE titel='"+filmsdb.get(counter.get(i)-1)+"';");
|
||||
private void checkRemoveEntry() throws SQLException{
|
||||
System.out.println("checking for entrys to remove to DB ...");
|
||||
Statement stmt = connection.createStatement();
|
||||
|
||||
for(int a=0; a<filmsdbLocal.size(); a++){
|
||||
if(filmsDir.contains(filmsdbLocal.get(a))){
|
||||
}else{
|
||||
stmt.executeUpdate("delete from film_local where titel = '"+filmsdbLocal.get(a)+"'");
|
||||
connection.commit();
|
||||
stmt.close();
|
||||
}catch(SQLException e){
|
||||
System.out.println("Ups! an error occured!");
|
||||
e.printStackTrace();
|
||||
System.out.println("removed \""+filmsdbLocal.get(a)+"\" from databsae");
|
||||
}
|
||||
}
|
||||
|
||||
for(int b=0; b<filmsdbStreamURL.size(); b++){
|
||||
if(filmsStreamURL.contains(filmsdbStreamURL.get(b))){
|
||||
}else{
|
||||
stmt.executeUpdate("delete from film_streaming where titel = '"+filmsdbStream.get(b)+"'");
|
||||
connection.commit();
|
||||
stmt.close();
|
||||
System.out.println("removed \""+filmsdbStream.get(b)+"\" from databsae");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void addEntry(){
|
||||
System.out.println("adding entry to DB ...");
|
||||
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException{ //m<>ssen noch alphabetisch sortiert werden
|
||||
System.out.println("checking for entrys to add to DB ...");
|
||||
String[] entries = new File(mainWindowController.getPath()).list();
|
||||
Statement stmt = connection.createStatement();
|
||||
PreparedStatement ps = connection.prepareStatement("insert into film_streaming values (?, ?, ?, ?, ?, ?, ?)");;
|
||||
int i=0;
|
||||
|
||||
for(int a=0; a<filmsDir.size(); a++){
|
||||
if(filmsdbLocal.contains(filmsDir.get(a))){
|
||||
}else{
|
||||
stmt.executeUpdate("insert into film_local values (0, '"+cutOffEnd(entries[a])+"', '"+entries[a]+"')");
|
||||
connection.commit();
|
||||
stmt.close();
|
||||
System.out.println("added \""+filmsDir.get(a)+"\" to databsae");
|
||||
}
|
||||
}
|
||||
|
||||
for(int b=0; b<filmsStreamURL.size(); b++){
|
||||
if(filmsdbStreamURL.contains(filmsStreamURL.get(b))){
|
||||
}else{
|
||||
JsonObject object = Json.parse(new FileReader(filmsStreamData.get(b))).asObject();
|
||||
JsonArray items = object.get("entries").asArray();
|
||||
System.out.println(items.size()+", "+i);
|
||||
String streamURL = items.get(i).asObject().getString("streamUrl","");
|
||||
String titel = items.get(i).asObject().getString("titel","");
|
||||
|
||||
if(streamURL.equals(filmsStreamURL.get(b))){
|
||||
System.out.println("hinzuf<EFBFBD>gen \""+titel+"\"");
|
||||
|
||||
ps.setInt(1, items.get(i).asObject().getInt("year", 0));
|
||||
ps.setInt(2, items.get(i).asObject().getInt("season", 0));
|
||||
ps.setInt(3, items.get(i).asObject().getInt("episode", 0));
|
||||
ps.setInt(4, 0);
|
||||
ps.setString(5, items.get(i).asObject().getString("resolution", ""));
|
||||
ps.setString(6, items.get(i).asObject().getString("titel",""));
|
||||
ps.setString(7, items.get(i).asObject().getString("streamUrl", ""));
|
||||
ps.addBatch(); // adds the entry
|
||||
|
||||
// stmt.executeUpdate("insert into film_streaming values ("+items.get(i).asObject().getInt("year", 0)+", "+items.get(i).asObject().getInt("season", 0)+", "+items.get(i).asObject().getInt("episode", 0)+", 0, '"+items.get(i).asObject().getString("resolution", ""+"', '"+items.get(i).asObject().getString("titel","")+"', '"+items.get(i).asObject().getString("streamUrl", "")+"')"));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
ps.executeBatch();
|
||||
connection.commit();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
void ausgeben(){
|
||||
@ -323,7 +349,7 @@ public class DBController {
|
||||
rs.close();
|
||||
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Konnte nicht ausgef<65>hrt werden");
|
||||
System.err.println("Ups! an error occured!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -351,7 +377,7 @@ public class DBController {
|
||||
|
||||
}
|
||||
//setzt die Defavorisierung eines bestimmten Films
|
||||
void dislike(String name){
|
||||
void dislike(String name,String streamUrl){
|
||||
System.out.println("defavorisieren ...");
|
||||
try{
|
||||
Statement stmt = connection.createStatement();
|
||||
@ -364,7 +390,7 @@ public class DBController {
|
||||
}
|
||||
try {
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.executeUpdate("UPDATE film_streaming SET rating=0 WHERE titel='"+name+"';");
|
||||
stmt.executeUpdate("UPDATE film_streaming SET rating=0 WHERE streamUrl='"+streamUrl+"';");
|
||||
connection.commit();
|
||||
stmt.close();
|
||||
} catch (SQLException e1) {
|
||||
@ -373,7 +399,7 @@ public class DBController {
|
||||
}
|
||||
}
|
||||
//setzt die Favorisierung eines bestimmten Films
|
||||
void like(String name){
|
||||
void like(String name,String streamUrl){
|
||||
System.out.println("favorisieren ...");
|
||||
try{
|
||||
Statement stmt = connection.createStatement();
|
||||
@ -386,7 +412,7 @@ public class DBController {
|
||||
}
|
||||
try {
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.executeUpdate("UPDATE film_streaming SET rating=1 WHERE titel='"+name+"';");
|
||||
stmt.executeUpdate("UPDATE film_streaming SET rating=1 WHERE streamUrl='"+streamUrl+"';");
|
||||
connection.commit();
|
||||
stmt.close();
|
||||
} catch (SQLException e1) {
|
||||
@ -406,254 +432,3 @@ public class DBController {
|
||||
|
||||
}
|
||||
|
||||
// private static final DBController dbcontroller = new DBController();
|
||||
// private static Connection connection;
|
||||
// private static final String DB_PATH = System.getProperty("user.home") + "\\Documents\\HomeFlix" + "\\" + "Homeflix.db"; // der Pfad der Datenbank-Datei
|
||||
// private String path;
|
||||
// File f;
|
||||
// File file[]; //ArrayList f<>r die Dateien
|
||||
//
|
||||
// public DBController(MainWindowController m){
|
||||
// mainWindowController=m;
|
||||
// }
|
||||
//
|
||||
// private MainWindowController mainWindowController;
|
||||
//
|
||||
// static {
|
||||
// try {
|
||||
// Class.forName("org.sqlite.JDBC"); //Datenbanktreiber
|
||||
// } catch (ClassNotFoundException e) {
|
||||
// System.err.println("Fehler beim Laden des JDBC-Treibers");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static void main(String input) {
|
||||
// DBController datenbank = DBController.getInstance(); //neues Datenbank-Objekt wird erstellt
|
||||
// datenbank.setPath(input); // Pfad zuweisen
|
||||
// datenbank.f = new File(datenbank.getPath()); // f<>r Datenbank-Datei einlesen
|
||||
// datenbank.file = datenbank.f.listFiles(); // f<>r Datenbank-Datei einlesen
|
||||
// datenbank.verbindeDatenbank();
|
||||
// datenbank.fuelleDatenbank();
|
||||
// //datenbank.defavorisieren("Frozen");
|
||||
// //datenbank.favorisieren("Frozen");
|
||||
// //datenbank.ausgebenTitel();
|
||||
// //System.out.println("Pfad: " + datenbank.getPfad("Frozen"));
|
||||
// //System.out.println("Bewertung: " + datenbank.getFavStatus("Frozen"));
|
||||
// }
|
||||
//
|
||||
// DBController(){
|
||||
// }
|
||||
//
|
||||
// private static DBController getInstance(){
|
||||
// return dbcontroller;
|
||||
// }
|
||||
//// Die Datenbak wird mit Hilfe des JDBC-Treibers eingebunden
|
||||
// public void verbindeDatenbank() {
|
||||
// try {
|
||||
// if (connection != null)
|
||||
// return;
|
||||
// System.out.println("Erstelle Verbindung zur Datenbank...");
|
||||
// connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
|
||||
// if (!connection.isClosed())
|
||||
// System.out.println("...Verbindung hergestellt");
|
||||
// } catch (SQLException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
//
|
||||
// Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
// public void run() {
|
||||
// try {
|
||||
// if (!connection.isClosed() && connection != null) {
|
||||
// connection.close();
|
||||
// if (connection.isClosed())
|
||||
// System.out.println("Verbindung getrennt");
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
//// Die Dateien werden in die Datenbank geschrieben
|
||||
// public void fuelleDatenbank() {
|
||||
//
|
||||
// try {
|
||||
// System.out.println("Erstelle Eintr<74>ge local");
|
||||
// Statement stmt = connection.createStatement();
|
||||
// stmt.executeUpdate("DROP TABLE IF EXISTS film_local;");
|
||||
// stmt.executeUpdate("CREATE TABLE film_local (rating, titel, streamUrl);"); // Tabelle "filme" und die Spalten "titel", "pfad", "bewertung" erstellen
|
||||
//
|
||||
// PreparedStatement ps = connection.prepareStatement("INSERT INTO film_local VALUES (?, ?, ?);"); // SQL Befehl
|
||||
// PreparedStatement psS = connection.prepareStatement("INSERT INTO film_streaming VALUES (?, ?, ?, ?, ?, ?, ?);"); // SQL Befehl
|
||||
//
|
||||
// System.out.println("Size: "+file.length);
|
||||
//
|
||||
// for(int i=0;i!=file.length;i++) // Geht alle Dateien im Verzeichniss durch
|
||||
// {
|
||||
// //System.out.println(file[i].getName());
|
||||
// ps.setInt(1, 0); // definiert Bewertung als Integer in der dritten Spalte
|
||||
// ps.setString(2, ohneEndung(file[i].getName())); // definiert Name als String in der ersten Spalte
|
||||
// ps.setString(3,file[i].getName()); // definiert Pfad als String in der zweiten Spalte
|
||||
// ps.addBatch(); // f<>gt den Eintrag hinzu
|
||||
// }
|
||||
//
|
||||
//
|
||||
// System.out.println("Erstelle Eintr<74>ge streaming");
|
||||
// Statement stmtS = connection.createStatement();
|
||||
// stmtS.executeUpdate("DROP TABLE IF EXISTS film_streaming;");
|
||||
// stmtS.executeUpdate("CREATE TABLE film_streaming (year, season, episode, rating, resolution, titel, streamUrl);"); // Tabelle "filme" und die Spalten "titel", "pfad", "bewertung" erstellen
|
||||
//
|
||||
// System.out.println(mainWindowController.getStreamingPath());
|
||||
// if(mainWindowController.getStreamingPath().equals("")||mainWindowController.getStreamingPath().equals(null)){
|
||||
// System.out.println("Kein Pfad angegeben"); //falls der Pfad null oder "" ist
|
||||
// }else{
|
||||
// for(int i=0; i< mainWindowController.streamingData.size(); i++){
|
||||
// String fileName = mainWindowController.getStreamingPath()+"/"+mainWindowController.streamingData.get(i).getStreamUrl();
|
||||
// try {
|
||||
// JsonObject object = Json.parse(new FileReader(fileName)).asObject();
|
||||
// JsonArray items = object.get("entries").asArray();
|
||||
// for (JsonValue item : items) {
|
||||
// psS.setInt(1, item.asObject().getInt("year", 0));
|
||||
// psS.setInt(2, item.asObject().getInt("season", 0));
|
||||
// psS.setInt(3, item.asObject().getInt("episode", 0));
|
||||
// psS.setInt(4, 0);
|
||||
// psS.setString(5, item.asObject().getString("resolution", ""));
|
||||
// psS.setString(6, item.asObject().getString("titel",""));
|
||||
// psS.setString(7, item.asObject().getString("streamUrl", ""));
|
||||
// psS.addBatch(); // f<>gt den Eintrag hinzu
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// //Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// connection.setAutoCommit(false);
|
||||
// ps.executeBatch(); // scheibt alle Eintr<74>ge in die Datenbank
|
||||
// psS.executeBatch();
|
||||
// connection.setAutoCommit(true);
|
||||
// //connection.close();
|
||||
// } catch (SQLException e) {
|
||||
// System.err.println("Konnte nicht ausgef<65>hrt werden");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void ausgeben(){
|
||||
// System.out.println("Eintr<74>ge ausgeben ... \n");
|
||||
// try {
|
||||
// Statement stmt = connection.createStatement();
|
||||
// mainWindowController = new MainWindowController();
|
||||
// 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)+"\n");
|
||||
// }
|
||||
// rs.close();
|
||||
//
|
||||
// ResultSet rsS = stmt.executeQuery("SELECT * FROM film_streaming;");
|
||||
// while (rsS.next()) {
|
||||
// System.out.println(rsS.getString(1));
|
||||
// System.out.println(rsS.getString(2));
|
||||
// System.out.println(rsS.getString(3)+"\n");
|
||||
// }
|
||||
// rsS.close();
|
||||
//// mainWindowController.initTabel();
|
||||
//
|
||||
//
|
||||
// } catch (SQLException e) {
|
||||
// System.err.println("Konnte nicht ausgef<65>hrt werden");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// }
|
||||
//// Kontroll Methode, ob ein Film wirklich in der Datenbank ist
|
||||
// public String getTitel(String name){
|
||||
// try {
|
||||
// Statement stmt = connection.createStatement();
|
||||
// ResultSet rs = stmt.executeQuery("SELECT titel, pfad FROM filme WHERE titel = '"+name+"';" );
|
||||
// return rs.getString("titel");
|
||||
// } catch (SQLException e) {
|
||||
// System.err.println("Konnte nicht ausgef<65>hrt werden");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return "Error 404";
|
||||
// }
|
||||
//// gibt den Pfad eines bestimmten Films
|
||||
// public String getPfad(String name){
|
||||
// try {
|
||||
// Statement stmt = connection.createStatement();
|
||||
// ResultSet rs = stmt.executeQuery("SELECT titel, pfad FROM filme WHERE titel = '"+name+"';" ); //SQL Befehl
|
||||
// return rs.getString("pfad");
|
||||
// } catch (SQLException e) {
|
||||
// System.err.println("Konnte nicht ausgef<65>hrt werden");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return "Error 404";
|
||||
// }
|
||||
//// gibt die Favorisierung eines bestimmten Films
|
||||
// public boolean getFavStatus(String name){
|
||||
// try {
|
||||
// Statement stmt = connection.createStatement();
|
||||
// ResultSet rs = stmt.executeQuery("SELECT titel, bewertung FROM filme WHERE titel = '"+name+"';" ); //SQL Befehl
|
||||
// System.out.println(rs.getInt("bewertung"));
|
||||
// if((rs.getInt("bewertung")) == 1){
|
||||
// return true;
|
||||
// }
|
||||
// else{
|
||||
// return false;
|
||||
// }
|
||||
// } catch (SQLException e) {
|
||||
// System.err.println("Konnte nicht ausgef<65>hrt werden");
|
||||
// e.printStackTrace();
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
//// setzt die Defavorisierung eines bestimmten Films
|
||||
// public void defavorisieren(String name){
|
||||
// System.out.println("setze Bewertung");
|
||||
// try {
|
||||
// Statement stmt = connection.createStatement();
|
||||
// String sql = ("UPDATE filme SET bewertung=0 WHERE titel='"+name+"';"); //SQL Befehl
|
||||
// stmt.executeUpdate(sql);
|
||||
// connection.setAutoCommit(false);
|
||||
// connection.setAutoCommit(true);
|
||||
// } catch (SQLException e) {
|
||||
// System.err.println("Konnte nicht ausgef<65>hrt werden");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//// setzt die Favorisierung eines bestimmten Films
|
||||
// public void favorisieren(String name){
|
||||
// System.out.println("setze Bewertung");
|
||||
// try {
|
||||
// Statement stmt = connection.createStatement();
|
||||
// String sql = ("UPDATE filme SET bewertung=1 WHERE titel='"+name+"';"); //SQL Befehl
|
||||
// stmt.executeUpdate(sql);
|
||||
// connection.setAutoCommit(false);
|
||||
// connection.setAutoCommit(true);
|
||||
// } catch (SQLException e) {
|
||||
// System.err.println("Konnte nicht ausgef<65>hrt werden");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
////entfernt die Endung
|
||||
// private static String ohneEndung (String str) {
|
||||
//
|
||||
// if (str == null) return null;
|
||||
// int pos = str.lastIndexOf(".");
|
||||
// if (pos == -1) return str;
|
||||
// return str.substring(0, pos);
|
||||
// }
|
||||
//
|
||||
// public String getPath() {
|
||||
// return path;
|
||||
// }
|
||||
//
|
||||
// public void setPath(String path) {
|
||||
// this.path = path.replace("\\", "\\\\");
|
||||
// }
|
||||
//}
|
||||
|
@ -55,6 +55,7 @@ import javafx.animation.ParallelTransition;
|
||||
import javafx.animation.TranslateTransition;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.beans.property.ReadOnlyStringWrapper;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
@ -252,6 +253,10 @@ public class MainWindowController {
|
||||
private ImageView skip_next_black = new ImageView(new Image("recources/icons/ic_skip_next_black_18dp_1x.png"));
|
||||
private ImageView play_arrow_white = new ImageView(new Image("recources/icons/ic_play_arrow_white_18dp_1x.png"));
|
||||
private ImageView play_arrow_black = new ImageView(new Image("recources/icons/ic_play_arrow_black_18dp_1x.png"));
|
||||
@SuppressWarnings("unused")
|
||||
private ImageView favorite_black = new ImageView(new Image("recources/icons/ic_favorite_black_18dp_1x.png"));
|
||||
@SuppressWarnings("unused")
|
||||
private ImageView favorite_border_black = new ImageView(new Image("recources/icons/ic_favorite_border_black_18dp_1x.png"));
|
||||
private DirectoryChooser directoryChooser = new DirectoryChooser();
|
||||
private ContextMenu menu = new ContextMenu();
|
||||
private MenuItem like = new MenuItem("like");
|
||||
@ -432,13 +437,6 @@ public class MainWindowController {
|
||||
|
||||
@FXML
|
||||
private void debugBtnclicked(){
|
||||
System.out.println(columnRating.getSortType());
|
||||
// System.out.println(newDaten.get(selected).getTitel()+","+newDaten.get(selected).getRating());
|
||||
// dbController.getFavStatus("Zootopia");
|
||||
// dbController.like("Zootopia");
|
||||
// dbController.getFavStatus("House of Cards");
|
||||
// dbController.dislike("Zootopia");
|
||||
// dbController.getFavStatus("Zootopia");
|
||||
//for testing
|
||||
}
|
||||
|
||||
@ -532,8 +530,8 @@ public class MainWindowController {
|
||||
// columnRating.setSortType(TreeTableColumn.SortType.ASCENDING);
|
||||
// }
|
||||
|
||||
debugBtn.setDisable(false); //debugging btn for tests
|
||||
debugBtn.setVisible(true);
|
||||
debugBtn.setDisable(true); //debugging btn for tests
|
||||
debugBtn.setVisible(false);
|
||||
|
||||
tfPath.setText(getPath());
|
||||
|
||||
@ -644,6 +642,10 @@ public class MainWindowController {
|
||||
for(int i = 0; i < filterData.size(); i++){
|
||||
root.getChildren().addAll(new TreeItem<streamUiData>(filterData.get(i))); //f<>gt daten zur Rootnode hinzu
|
||||
}
|
||||
if(tfsearch.getText().equals("Notflix_glowing_cow")){
|
||||
setColor("000000");
|
||||
applyColor();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -668,12 +670,19 @@ public class MainWindowController {
|
||||
like.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
dbController.like(Name);
|
||||
if(mode.equals("streaming")){
|
||||
dbController.like(Name,streamData.get(selected).getStreamUrl());
|
||||
}else{
|
||||
dbController.like(Name,streamData.get(0).getStreamUrl());
|
||||
}
|
||||
dbController.getFavStatus(Name);
|
||||
try {
|
||||
dbController.refresh(Name, selected);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block error msg
|
||||
Alert alert = new Alert(AlertType.ERROR);
|
||||
alert.setTitle("Error");
|
||||
alert.setHeaderText("");
|
||||
alert.setContentText("There should be an error message in the future (like problem)\nIt seems as a cat has stolen the like-methode");
|
||||
e.printStackTrace();
|
||||
}
|
||||
refreshTable();
|
||||
@ -683,12 +692,19 @@ public class MainWindowController {
|
||||
dislike.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
dbController.dislike(Name);
|
||||
if(mode.equals("streaming")){
|
||||
dbController.dislike(Name,streamData.get(selected).getStreamUrl());
|
||||
}else{
|
||||
dbController.dislike(Name,streamData.get(0).getStreamUrl());
|
||||
}
|
||||
dbController.getFavStatus(Name);
|
||||
try {
|
||||
dbController.refresh(Name, selected);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block error msg
|
||||
Alert alert = new Alert(AlertType.ERROR);
|
||||
alert.setTitle("Error");
|
||||
alert.setHeaderText("");
|
||||
alert.setContentText("There should be an error message in the future (dislike problem)");
|
||||
e.printStackTrace();
|
||||
}
|
||||
refreshTable();
|
||||
@ -697,58 +713,13 @@ public class MainWindowController {
|
||||
}
|
||||
|
||||
private void refreshTable(){
|
||||
if(mode.equals("local")){
|
||||
root.getChildren().set(selected, new TreeItem<streamUiData>(newDaten.get(selected)));
|
||||
}else if(mode.equals("streaming")){
|
||||
root.getChildren().set(selected, new TreeItem<streamUiData>(streamData.get(selected)));
|
||||
}
|
||||
}
|
||||
|
||||
//l<>dt die Daten im angegeben Ordner in newDaten
|
||||
// void loadData(){
|
||||
// //load local Data
|
||||
// if(getPath().equals("")||getPath().equals(null)){
|
||||
// System.out.println("Kein Pfad angegeben"); //falls der Pfad null oder "" ist
|
||||
// }else{
|
||||
// String[] entries = new File(getPath()).list();
|
||||
// for(int i = 0; i < entries.length; i++){
|
||||
// String titel = ohneEndung(entries[i]);
|
||||
// String data = entries[i];
|
||||
// newDaten.add(new streamUiData(1, 1, 1, 5.0, "1", titel, data));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// //load streaming Data TODO pr<70>fen ob streaming daten vorhanden -> momentan evtl. fehler
|
||||
// String titel = null;
|
||||
// String resolution = null;
|
||||
// String streamUrl = null;
|
||||
// int season;
|
||||
// int episode;
|
||||
// int year;
|
||||
// double rating = 5.0;
|
||||
// if(getStreamingPath().equals("")||getStreamingPath().equals(null)){
|
||||
// System.out.println("Kein Pfad angegeben"); //falls der Pfad null oder "" ist
|
||||
// }else{
|
||||
// for(int i=0; i< streamingData.size(); i++){
|
||||
// String fileName = streamingPath+"/"+streamingData.get(i).getStreamUrl();
|
||||
// try {
|
||||
// JsonObject object = Json.parse(new FileReader(fileName)).asObject();
|
||||
// JsonArray items = object.get("entries").asArray();
|
||||
//
|
||||
// for (JsonValue item : items) {
|
||||
// titel = item.asObject().getString("titel","");
|
||||
// season = item.asObject().getInt("season", 0);
|
||||
// episode = item.asObject().getInt("episode", 0);
|
||||
// year = item.asObject().getInt("year", 0);
|
||||
// resolution = item.asObject().getString("resolution", "");
|
||||
// streamUrl = item.asObject().getString("streamUrl", "");
|
||||
// streamData.add(new streamUiData(year, season, episode, rating, resolution, titel, streamUrl));
|
||||
// }
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// //Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
void addDataUI(){
|
||||
if(mode.equals("local")){
|
||||
for(int i = 0; i < newDaten.size(); i++){
|
||||
|
@ -16,7 +16,7 @@ import com.eclipsesource.json.JsonObject;
|
||||
|
||||
import javafx.scene.image.Image;
|
||||
|
||||
public class apiQuery {
|
||||
public class apiQuery{
|
||||
|
||||
public apiQuery(MainWindowController m){
|
||||
mainWindowController=m;
|
||||
|
Reference in New Issue
Block a user