|
|
|
@@ -1,12 +1,13 @@
|
|
|
|
|
/**
|
|
|
|
|
* DBController for Project HomeFlix
|
|
|
|
|
* connection is in manual commit!
|
|
|
|
|
* TODO überprü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ü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ü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ü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ä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ä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äge in die Datenbank
|
|
|
|
|
// psS.executeBatch();
|
|
|
|
|
// connection.setAutoCommit(true);
|
|
|
|
|
// //connection.close();
|
|
|
|
|
// } catch (SQLException e) {
|
|
|
|
|
// System.err.println("Konnte nicht ausgeführt werden");
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// public void ausgeben(){
|
|
|
|
|
// System.out.println("Einträ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ü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ü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ü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ü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ü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ü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("\\", "\\\\");
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|