worked on dbcontroller part 5

finished work on dbcontroller, one remaining bug in mainWindowController
This commit is contained in:
Seil0 2017-01-11 20:24:29 +01:00
parent d809b1ff9b
commit 3e2443ce5c
21 changed files with 375 additions and 408 deletions

View File

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Project HomeFlix</name>
<comment></comment>
<projects>
</projects>
<comment />
<projects />
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
<arguments />
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
<arguments />
</buildCommand>
</buildSpec>
<natures>

Binary file not shown.

View File

@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,19 @@
Copyright (c) 2013, 2014 EclipseSource
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Binary file not shown.

View File

@ -1,4 +1,4 @@
# HomeFlix-Local_de_DE.properties German Local
# HomeFlix-Local_de_DE.properties German Local
info = Info
settings = Einstellungen
streamingSettings = Stream Einst.
@ -28,7 +28,7 @@ errorSave = Beim speichern der Einstellungen ist ein Fehler aufgetreten!
noFilmFound = Kein Film mit diesem Titel gefunden!
linuxBug = Zurzeit werden unter Linux leider keine Dateien mit Leerzeichen unterst\u00FCtzt!
vlcNotInstalled = Um einen Film abspielen wird der VLC Media Player ben\u00F6tigt!
infoText = \nMaintainer: seilo@kellerkinder.xyz und \nhendrik.schutter@coptersicht.de \n(c) 2016 Kellerkinder www.kellerkinder.xyz
infoText = \nMaintainer: seilo@kellerkinder.xyz und \nhendrik.schutter@coptersicht.de \n(c) 2016-2017 Kellerkinder www.kellerkinder.xyz
title = Titel
year = Jahr
rating = Einstufung

View File

@ -28,7 +28,7 @@ errorSave = An error occurred while saving the settings!
noFilmFound = No film with this title found!
linuxBug = Currently no files are supported with additional space under Linux unfortunately!
vlcNotInstalled = VLC Media Player is required to play a movie!
infoText = \nMaintainer: seilo@kellerkinder.xyz and \nhendrik.schutter@coptersicht.de \n(c) 2016 Kellerkinder www.kellerkinder.xyz
infoText = \nMaintainer: seilo@kellerkinder.xyz and \nhendrik.schutter@coptersicht.de \n(c) 2016-2017 Kellerkinder www.kellerkinder.xyz
title = Title
year = Year
rating = Rating

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

View File

@ -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("\\", "\\\\");
// }
//}

View File

@ -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ü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++){

View File

@ -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;

View File

@ -1,4 +1,4 @@
# HomeFlix-Local_de_DE.properties German Local
# HomeFlix-Local_de_DE.properties German Local
info = Info
settings = Einstellungen
streamingSettings = Stream Einst.
@ -28,7 +28,7 @@ errorSave = Beim speichern der Einstellungen ist ein Fehler aufgetreten!
noFilmFound = Kein Film mit diesem Titel gefunden!
linuxBug = Zurzeit werden unter Linux leider keine Dateien mit Leerzeichen unterst\u00FCtzt!
vlcNotInstalled = Um einen Film abspielen wird der VLC Media Player ben\u00F6tigt!
infoText = \nMaintainer: seilo@kellerkinder.xyz und \nhendrik.schutter@coptersicht.de \n(c) 2016 Kellerkinder www.kellerkinder.xyz
infoText = \nMaintainer: seilo@kellerkinder.xyz und \nhendrik.schutter@coptersicht.de \n(c) 2016-2017 Kellerkinder www.kellerkinder.xyz
title = Titel
year = Jahr
rating = Einstufung

View File

@ -28,7 +28,7 @@ errorSave = An error occurred while saving the settings!
noFilmFound = No film with this title found!
linuxBug = Currently no files are supported with additional space under Linux unfortunately!
vlcNotInstalled = VLC Media Player is required to play a movie!
infoText = \nMaintainer: seilo@kellerkinder.xyz and \nhendrik.schutter@coptersicht.de \n(c) 2016 Kellerkinder www.kellerkinder.xyz
infoText = \nMaintainer: seilo@kellerkinder.xyz and \nhendrik.schutter@coptersicht.de \n(c) 2016-2017 Kellerkinder www.kellerkinder.xyz
title = Title
year = Year
rating = Rating