removed streaming mode, all films are now in one mode

* removed streaming mode, all films are now in one mode. This will make it easiere to maintain HomeFlix
* fixed a bug that caused series to be periodicaly removed
* added season and episode column to the film table
* lots of code cleanup
This commit is contained in:
Jannik 2018-03-07 00:20:14 +01:00
parent ad63d566c9
commit d23a3bbe4e
4 changed files with 125 additions and 341 deletions

View File

@ -63,7 +63,6 @@ public class Main extends Application {
private String path;
private String FONT_FAMILY = "System";
private String mode = "local"; //local or streaming TODO
private String local = System.getProperty("user.language")+"_"+System.getProperty("user.country");
private double FONT_SIZE = 17;
private ResourceBundle bundle;
@ -112,7 +111,6 @@ public class Main extends Application {
mainWindowController.setSize(FONT_SIZE);
mainWindowController.setAutoUpdate(false);
mainWindowController.setLocal(local);
mainWindowController.setMode(mode);
mainWindowController.saveSettings();
try {
Runtime.getRuntime().exec("java -jar ProjectHomeFlix.jar"); // start again (preventing Bugs) TODO is this really needed

View File

@ -37,8 +37,6 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Properties;
@ -145,9 +143,6 @@ public class MainWindowController {
@FXML
private JFXButton settingsBtn;
@FXML
private JFXButton switchBtn;
@FXML
private JFXButton debugBtn;
@ -237,25 +232,22 @@ public class MainWindowController {
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
private int hashA = -647380320;
private String version = "0.5.2";
private String buildNumber = "131";
private String version = "0.5.99";
private String buildNumber = "137";
private String versionName = "solidify cow";
private String dialogBtnStyle;
private String color;
private String title;
private String streamUrl;
private String ratingSortType;
private String local;
// text strings
private String errorPlay;
private String errorOpenStream;
private String errorLoad;
private String errorSave;
private String infoText;
private String vlcNotInstalled;
private String streamingPath;
private String color;
private String title;
private String streamUrl;
private String mode;
private String ratingSortType;
private String local;
public double size;
private int last;
@ -267,7 +259,6 @@ public class MainWindowController {
private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
private ObservableList<FilmTabelDataType> localFilms = FXCollections.observableArrayList();
private ObservableList<FilmTabelDataType> streamingFilms = FXCollections.observableArrayList();
private ObservableList<SourceDataType> sourcesList = FXCollections.observableArrayList();
private ImageView skip_previous_white = new ImageView(new Image("icons/ic_skip_previous_white_18dp_1x.png"));
private ImageView skip_previous_black = new ImageView(new Image("icons/ic_skip_previous_black_18dp_1x.png"));
@ -309,6 +300,10 @@ public class MainWindowController {
// film Table
columnStreamUrl.setMaxWidth(0);
columnTitle.setMaxWidth(215);
columnRating.setMaxWidth(60);
columnSeason.setMaxWidth(55);
columnEpisode.setMaxWidth(64);
columnRating.setStyle("-fx-alignment: CENTER;");
treeTableViewfilm.setRoot(filmRoot);
@ -323,12 +318,12 @@ public class MainWindowController {
columnEpisode.setCellValueFactory(cellData -> cellData.getValue().getValue().episodeProperty().asObject());
// add columns to treeTableViewfilm
treeTableViewfilm.getColumns().add(columnStreamUrl);
treeTableViewfilm.getColumns().add(columnTitle);
treeTableViewfilm.getColumns().add(columnRating);
treeTableViewfilm.getColumns().add(columnStreamUrl);
treeTableViewfilm.getColumns().add(columnSeason);
treeTableViewfilm.getColumns().add(columnEpisode);
treeTableViewfilm.getColumns().get(2).setVisible(false); //hide columnStreamUrl (column with file URL, important for opening a file/stream)
treeTableViewfilm.getColumns().get(0).setVisible(false); //hide columnStreamUrl (column with file URL, important for opening a file/stream)
// context menu for treeTableViewfilm
treeTableViewfilm.setContextMenu(menu);
@ -369,11 +364,8 @@ public class MainWindowController {
filterData.removeAll(filterData);
filmRoot.getChildren().removeAll(filmRoot.getChildren());
if (mode.equals("local")) {
helpData = localFilms;
} else {
helpData = streamingFilms;
}
helpData = localFilms;
for (int i = 0; i < helpData.size(); i++) {
if (helpData.get(i).getTitle().toLowerCase().contains(searchTextField.getText().toLowerCase())) {
@ -458,11 +450,7 @@ public class MainWindowController {
// treeTableViewfilm.getSelectionModel().clearSelection(selected);
filmRoot.getChildren().removeAll(filmRoot.getChildren());
if (mode.equals("local")) {
helpData = localFilms;
} else {
helpData = streamingFilms;
}
helpData = localFilms;
for (int i = 0; i < helpData.size(); i++) {
if (helpData.get(i).getRating() == 1.0) {
@ -508,20 +496,11 @@ public class MainWindowController {
title = columnTitle.getCellData(selected); // get name of selected item
streamUrl = columnStreamUrl.getCellData(selected); // get file path of selected item
if (mode.equals("local")) {
if (localFilms.get(selected).getCached() == true) {
LOGGER.info("loading from cache: " + title);
dbController.readCache(streamUrl);
} else {
ApiQuery.startQuery(title, streamUrl); // start api query
}
if (localFilms.get(selected).getCached() == true) {
LOGGER.info("loading from cache: " + title);
dbController.readCache(streamUrl);
} else {
if (streamingFilms.get(selected).getCached() == true) {
LOGGER.info("loading from cache: " + title);
dbController.readCache(streamUrl);
} else {
ApiQuery.startQuery(title, streamUrl); // start api query
}
ApiQuery.startQuery(title, streamUrl); // start api query
}
}
});
@ -529,7 +508,6 @@ public class MainWindowController {
// initialize UI elements
private void initUI() {
LOGGER.info("Mode: " + mode); // TODO debugging
debugBtn.setDisable(true); // debugging button for tests
debugBtn.setVisible(false);
@ -554,55 +532,42 @@ public class MainWindowController {
@FXML
private void playbtnclicked() {
// TODO open streams with desktop player, works at least with vlc under linux, part of #19
if (mode.equals("streaming")) {
if (Desktop.isDesktopSupported()) {
new Thread(() -> {
try {
Desktop.getDesktop().browse(new URI(streamUrl)); //open the streaming URL in browser
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
showErrorMsg(errorOpenStream, (IOException) e);
}
}).start();
} else {
LOGGER.info("Desktop not supported");
// TODO rework when #19 is coming
if (System.getProperty("os.name").contains("Linux")) {
String line;
String output = "";
Process p;
try {
p = Runtime.getRuntime().exec("which vlc");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output = line;
}
LOGGER.info(output);
input.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}else {
if(System.getProperty("os.name").contains("Linux")){
String line;
String output = "";
Process p;
if (output.contains("which: no vlc") || output == "") {
JFXInfoDialog vlcInfoDialog = new JFXInfoDialog("Info", vlcNotInstalled, dialogBtnStyle, 350, 200, main.getPane());
vlcInfoDialog.show();
} else {
try {
p = Runtime.getRuntime().exec("which vlc");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output = line;
}
LOGGER.info(output);
input.close();
} catch (IOException e1) {
e1.printStackTrace();
Runtime.getRuntime().exec(new String[] { "vlc", streamUrl }); // TODO switch to ProcessBuilder
} catch (IOException e) {
showErrorMsg(errorPlay, e);
}
if(output.contains("which: no vlc")||output == ""){
JFXInfoDialog vlcInfoDialog = new JFXInfoDialog("Info", vlcNotInstalled, dialogBtnStyle, 350, 200, main.getPane());
vlcInfoDialog.show();
}else{
try {
Runtime.getRuntime().exec(new String[] { "vlc", streamUrl}); // TODO switch to ProcessBuilder
} catch (IOException e) {
showErrorMsg(errorPlay,e);
}
}
}else if(System.getProperty("os.name").contains("Windows") || System.getProperty("os.name").contains("Mac OS X")){
try {
Desktop.getDesktop().open(new File(streamUrl));
} catch (IOException e) {
showErrorMsg(errorPlay,e);
}
} else {
LOGGER.error(System.getProperty("os.name") + ", OS is not supported, please contact a developer! ");
}
} else if (System.getProperty("os.name").contains("Windows") || System.getProperty("os.name").contains("Mac OS X")) {
try {
Desktop.getDesktop().open(new File(streamUrl));
} catch (IOException e) {
showErrorMsg(errorPlay, e);
}
} else {
LOGGER.error(System.getProperty("os.name") + ", OS is not supported, please contact a developer! ");
}
}
@ -648,24 +613,6 @@ public class MainWindowController {
}
}
@FXML
private void switchBtnclicked(){
if(mode.equals("local")){ //switch to streaming mode
setMode("streaming");
switchBtn.setText("local");
}else if(mode.equals("streaming")){ //switch to local mode
setMode("local");
switchBtn.setText("streaming");
}
saveSettings();
filmRoot.getChildren().removeAll(filmRoot.getChildren());
addDataUI();
settingsScrollPane.setVisible(false);
sideMenuSlideOut(); //disables side-menu
menuTrue = false;
settingsTrue = false;
}
@FXML
private void debugBtnclicked(){
//for testing
@ -721,57 +668,35 @@ public class MainWindowController {
// refresh the selected child of the root node
private void refreshTable() {
if (mode.equals("local")) {
filmRoot.getChildren().get(selected).setValue(localFilms.get(selected));
} else {
filmRoot.getChildren().get(selected).setValue(streamingFilms.get(selected));
}
filmRoot.getChildren().get(selected).setValue(localFilms.get(selected));
}
// TODO rework
public void addDataUI() {
if (mode.equals("local")) {
for (FilmTabelDataType element : localFilms) {
if (element.getSeason() != 0) {
// System.out.println("Found Series: " + element.getTitle());
// check if there is a series node to add the item
for (int i = 0; i < filmRoot.getChildren().size(); i++) {
if (filmRoot.getChildren().get(i).getValue().getTitle().equals(element.getTitle())) {
// System.out.println("Found a root node to add child");
// System.out.println("Adding: " + element.getStreamUrl());
TreeItem<FilmTabelDataType> episodeNode = new TreeItem<>(new FilmTabelDataType(element.getStreamUrl(),
element.getTitle(), element.getSeason(), element.getEpisode(), element.getRating(),
element.getCached(), element.getImage()));
filmRoot.getChildren().get(i).getChildren().add(episodeNode);
} else if (i == filmRoot.getChildren().size() - 1) {
// System.out.println("Create a root node to add child");
// System.out.println("Adding: " + element.getStreamUrl());
TreeItem<FilmTabelDataType> seriesRootNode = new TreeItem<>(new FilmTabelDataType(element.getStreamUrl(),
element.getTitle(), 0, 0, element.getRating(), element.getCached(), element.getImage()));
filmRoot.getChildren().add(seriesRootNode);
}
for (FilmTabelDataType element : localFilms) {
if (element.getSeason() != 0) {
// System.out.println("Found Series: " + element.getTitle());
// check if there is a series node to add the item
for (int i = 0; i < filmRoot.getChildren().size(); i++) {
if (filmRoot.getChildren().get(i).getValue().getTitle().equals(element.getTitle())) {
// System.out.println("Found a root node to add child");
// System.out.println("Adding: " + element.getStreamUrl());
TreeItem<FilmTabelDataType> episodeNode = new TreeItem<>(new FilmTabelDataType(element.getStreamUrl(),
element.getTitle(), element.getSeason(), element.getEpisode(), element.getRating(),
element.getCached(), element.getImage()));
filmRoot.getChildren().get(i).getChildren().add(episodeNode);
} else if (i == filmRoot.getChildren().size() - 1) {
// System.out.println("Create a root node to add child");
// System.out.println("Adding: " + element.getStreamUrl());
TreeItem<FilmTabelDataType> seriesRootNode = new TreeItem<>(new FilmTabelDataType(element.getStreamUrl(),
element.getTitle(), 0, 0, element.getRating(), element.getCached(), element.getImage()));
filmRoot.getChildren().add(seriesRootNode);
}
} else {
filmRoot.getChildren().add(new TreeItem<FilmTabelDataType>(element)); // add data to root-node
}
} else {
filmRoot.getChildren().add(new TreeItem<FilmTabelDataType>(element)); // add data to root-node
}
columnRating.setMaxWidth(85);
columnTitle.setMaxWidth(290);
treeTableViewfilm.getColumns().get(3).setVisible(false);
treeTableViewfilm.getColumns().get(4).setVisible(false);
} else {
for (int i = 0; i < streamingFilms.size(); i++) {
filmRoot.getChildren().add(new TreeItem<FilmTabelDataType>(streamingFilms.get(i))); // add data to root-node
}
columnTitle.setMaxWidth(215);
columnRating.setMaxWidth(60);
columnSeason.setMaxWidth(55);
columnEpisode.setMaxWidth(64);
treeTableViewfilm.getColumns().get(3).setVisible(true);
treeTableViewfilm.getColumns().get(4).setVisible(true);
}
}
@ -816,7 +741,6 @@ public class MainWindowController {
if (icolor.compareTo(ccolor) == -1) {
dialogBtnStyle = btnStyleWhite;
settingsBtn.setStyle("-fx-text-fill: WHITE;");
switchBtn.setStyle("-fx-text-fill: WHITE;");
aboutBtn.setStyle("-fx-text-fill: WHITE;");
debugBtn.setStyle("-fx-text-fill: WHITE;");
addDirectoryBtn.setStyle(btnStyleWhite);
@ -833,7 +757,6 @@ public class MainWindowController {
} else {
dialogBtnStyle = btnStyleBlack;
settingsBtn.setStyle("-fx-text-fill: BLACK;");
switchBtn.setStyle("-fx-text-fill: BLACK;");
aboutBtn.setStyle("-fx-text-fill: BLACK;");
debugBtn.setStyle("-fx-text-fill: BLACK;");
addDirectoryBtn.setStyle(btnStyleBlack);
@ -848,12 +771,6 @@ public class MainWindowController {
forwardBtn.setGraphic(skip_next_black);
menuHam.getStyleClass().add("jfx-hamburgerB");
}
if (mode.equals("local")) {
switchBtn.setText("streaming");
} else if (mode.equals("streaming")) {
switchBtn.setText("local");
}
}
// slide in in 400ms
@ -906,7 +823,6 @@ public class MainWindowController {
columnStreamUrl.setText(getBundle().getString("columnStreamUrl"));
columnSeason.setText(getBundle().getString("columnSeason"));
errorPlay = getBundle().getString("errorPlay");
errorOpenStream = getBundle().getString("errorOpenStream");
errorLoad = getBundle().getString("errorLoad");
errorSave = getBundle().getString("errorSave");
infoText = getBundle().getString("infoText");
@ -955,8 +871,6 @@ public class MainWindowController {
props.setProperty("useBeta", String.valueOf(isUseBeta()));
props.setProperty("size", getSize().toString());
props.setProperty("local", getLocal());
props.setProperty("streamingPath", getStreamingPath());
props.setProperty("mode", getMode());
props.setProperty("ratingSortType", columnRating.getSortType().toString());
OutputStream outputStream = new FileOutputStream(main.getConfigFile()); // new output-stream
@ -975,13 +889,6 @@ public class MainWindowController {
InputStream inputStream = new FileInputStream(main.getConfigFile());
props.loadFromXML(inputStream); // new input-stream from .xml
try {
setStreamingPath(props.getProperty("streamingPath"));
} catch (Exception e) {
LOGGER.error("cloud not load streamingPath", e);
setStreamingPath("");
}
try {
setColor(props.getProperty("color"));
} catch (Exception e) {
@ -1024,23 +931,6 @@ public class MainWindowController {
setRatingSortType("");
}
try {
switch (props.getProperty("mode")) {
case "local":
setMode("local");
break;
case "streaming":
setMode("streaming");
break;
default:
setMode("local");
break;
}
} catch (Exception e) {
setMode("local");
LOGGER.error("cloud not load mode", e);
}
inputStream.close();
} catch (IOException e) {
LOGGER.error(errorSave, e);
@ -1081,14 +971,6 @@ public class MainWindowController {
return color;
}
public void setStreamingPath(String input) {
this.streamingPath = input;
}
public String getStreamingPath() {
return streamingPath;
}
public void setSize(Double input) {
this.size = input;
}
@ -1121,14 +1003,6 @@ public class MainWindowController {
return local;
}
public void setMode(String input) {
this.mode = input;
}
public String getMode() {
return mode;
}
public ObservableList<FilmTabelDataType> getLocalFilms() {
return localFilms;
}
@ -1137,14 +1011,6 @@ public class MainWindowController {
this.localFilms = localFilms;
}
public ObservableList<FilmTabelDataType> getStreamingFilms() {
return streamingFilms;
}
public void setStreamingFilms(ObservableList<FilmTabelDataType> streamingFilms) {
this.streamingFilms = streamingFilms;
}
public ObservableList<SourceDataType> getSourcesList() {
return sourcesList;
}

View File

@ -65,9 +65,8 @@ public class DBController {
private Image favorite_black = new Image("icons/ic_favorite_black_18dp_1x.png");
private Image favorite_border_black = new Image("icons/ic_favorite_border_black_18dp_1x.png");
private List<String> filmsdbAll = new ArrayList<String>();
private List<String> filmsdbDir = new ArrayList<String>(); // needed
private List<String> filmsdbDir = new ArrayList<String>();
private List<String> filmsdbStreamURL = new ArrayList<String>(); // needed
private List<String> filmsAll = new ArrayList<String>();
private List<String> filmsStreamURL = new ArrayList<String>(); // needed
private Connection connection = null;
private static final Logger LOGGER = LogManager.getLogger(DBController.class.getName());
@ -100,9 +99,7 @@ public class DBController {
private void createDatabase() {
try {
Statement stmt = connection.createStatement();
// TODO use only one table
stmt.executeUpdate("create table if not exists film_loc (streamUrl, title, season, episode, rating, cached)");
stmt.executeUpdate("create table if not exists film_str (streamUrl, title, season, episode, rating, cached)");
stmt.executeUpdate("create table if not exists films (streamUrl, title, season, episode, rating, cached)");
stmt.executeUpdate("create table if not exists cache ("
+ "streamUrl, Title, Year, Rated, Released, Runtime, Genre, Director, Writer,"
+ " Actors, Plot, Language, Country, Awards, Metascore, imdbRating, imdbVotes,"
@ -114,33 +111,24 @@ public class DBController {
}
private void loadDatabase() {
// get all entries from the tables
// get all entries from the table
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc");
ResultSet rs = stmt.executeQuery("SELECT * FROM films");
while (rs.next()) {
filmsdbDir.add(rs.getString("title"));
filmsdbStreamURL.add(rs.getString("streamUrl"));
}
stmt.close();
rs.close();
rs = stmt.executeQuery("SELECT * FROM film_str;");
while (rs.next()) {
filmsdbAll.add(rs.getString("title"));
filmsdbStreamURL.add(rs.getString("streamUrl"));
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("Ups! an error occured!", e);
}
// add all entries to filmsAll and filmsdbAl, for later comparing
filmsdbAll.addAll(filmsdbDir);
LOGGER.info("films in directory: " + filmsAll.size());
LOGGER.info("filme in db: " + filmsdbAll.size());
LOGGER.info("films in directory: " + filmsStreamURL.size());
LOGGER.info("filme in db: " + filmsdbStreamURL.size());
}
// load the sources from sources.json
@ -156,22 +144,30 @@ public class DBController {
String mode = source.asObject().getString("mode", "");
mainWindowController.addSourceToTable(path, mode); // add source to source-table
if (mode.equals("local")) {
// getting all files from the selected directory
if (new File(path).exists()) {
for (String entry : new File(path).list()) {
filmsAll.add(cutOffEnd(entry));
for (File file : new File(path).listFiles()) {
if (file.isFile()) {
// get all files (films)
filmsStreamURL.add(file.getPath());
} else {
// get all folders (series)
for (File season : file.listFiles()) {
if (season.isDirectory()) {
for (File episode : season.listFiles()) {
if (!filmsdbStreamURL.contains(episode.getPath())) {
filmsStreamURL.add(episode.getPath());
}
}
}
}
}
LOGGER.info("added files from: " + path);
} else {
LOGGER.error(path + "dosen't exist!");
}
LOGGER.info("added files from: " + path);
} else {
// getting all entries from the streaming lists
try {
JsonObject object = Json.parse(new FileReader(path)).asObject();
JsonArray items = object.get("entries").asArray();
for (JsonValue item : items) {
filmsAll.add(item.asObject().getString("title", ""));
filmsStreamURL.add(item.asObject().getString("streamUrl", ""));
}
LOGGER.info("added films from: " + path);
@ -191,7 +187,7 @@ public class DBController {
try {
//load local Data
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc ORDER BY title");
ResultSet rs = stmt.executeQuery("SELECT * FROM films ORDER BY title");
while (rs.next()) {
if (rs.getInt("rating") == 1) {
mainWindowController.getLocalFilms().add(new FilmTabelDataType(rs.getString("streamUrl"),
@ -205,22 +201,6 @@ public class DBController {
}
stmt.close();
rs.close();
//load streaming Data
rs = stmt.executeQuery("SELECT * FROM film_str ORDER BY title;");
while (rs.next()) {
if (rs.getInt("rating") == 1) {
mainWindowController.getStreamingFilms().add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_black)));
} else {
mainWindowController.getStreamingFilms().add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_border_black)));
}
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("Ups! an error occured!", e);
}
@ -238,32 +218,18 @@ public class DBController {
LOGGER.info("refresh ...");
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM films WHERE streamUrl = \"" + streamUrl + "\";");
if (mainWindowController.getMode().equals("local")) {
ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc WHERE streamUrl = \"" + streamUrl + "\";");
if (rs.getInt("rating") == 1) {
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_black)));
} else {
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_border_black)));
}
rs.close();
if (rs.getInt("rating") == 1) {
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_black)));
} else {
ResultSet rs = stmt.executeQuery("SELECT * FROM film_str WHERE streamUrl = \"" + streamUrl + "\";");
if (rs.getInt("rating") == 1) {
mainWindowController.getStreamingFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_black)));
} else {
mainWindowController.getStreamingFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_border_black)));
}
rs.close();
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_border_black)));
}
rs.close();
stmt.close();
} catch (Exception e) {
LOGGER.error("Ups! error while refreshing mwc!", e);
@ -282,7 +248,6 @@ public class DBController {
filmsdbAll.removeAll(filmsdbAll);
filmsdbDir.removeAll(filmsdbDir);
filmsdbStreamURL.removeAll(filmsdbStreamURL);
filmsAll.removeAll(filmsAll);
filmsStreamURL.removeAll(filmsStreamURL);
loadSources(); // reload all sources
@ -291,43 +256,34 @@ public class DBController {
try {
checkAddEntry();
// checkRemoveEntry();
checkRemoveEntry();
} catch (Exception e) {
LOGGER.error("Error while refreshing the database", e);
}
// remove all films from the mwc lists
mainWindowController.getLocalFilms().removeAll(mainWindowController.getLocalFilms());
mainWindowController.getStreamingFilms().removeAll(mainWindowController.getStreamingFilms());
mainWindowController.getFilmRoot().getChildren().removeAll(mainWindowController.getFilmRoot().getChildren());
loadDataToMWC(); // load the new data to the mwc
}
/**
* TODO needs reworking currently broken
* check if there are any entries that have been removed from the film-directory
*/
@SuppressWarnings("unused")
private void checkRemoveEntry() {
LOGGER.info("checking for entrys to remove to DB ...");
try {
Statement stmt = connection.createStatement();
for (String entry : filmsdbDir) {
if (!filmsAll.contains(entry)) {
stmt.executeUpdate("delete from film_loc where title = \"" + entry + "\"");
connection.commit();
LOGGER.info("removed \"" + entry + "\" from loc database");
}
}
for (String entry : filmsdbStreamURL) {
if (!filmsStreamURL.contains(entry)) {
stmt.executeUpdate("delete from film_str where streamUrl = \"" + entry + "\"");
System.out.println(filmsdbStreamURL + "\n");
System.out.println(filmsStreamURL);
stmt.executeUpdate("delete from films where streamUrl = \"" + entry + "\"");
connection.commit();
LOGGER.info("removed \"" + entry + "\" from str database");
LOGGER.info("removed \"" + entry + "\" from database");
}
}
@ -345,7 +301,7 @@ public class DBController {
*/
private void checkAddEntry() throws SQLException, FileNotFoundException, IOException {
Statement stmt = connection.createStatement();
PreparedStatement ps = connection.prepareStatement("insert into film_str values (?, ?, ?, ?, ?, ?)");
PreparedStatement ps = connection.prepareStatement("insert into films values (?, ?, ?, ?, ?, ?)");
LOGGER.info("checking for entrys to add to DB ...");
// source is a single source of the sources list
@ -357,13 +313,13 @@ public class DBController {
if (file.isFile()) {
// get all files (films)
if (!filmsdbStreamURL.contains(file.getPath())) {
stmt.executeUpdate("insert into film_loc values ("
stmt.executeUpdate("insert into films values ("
+ "'" + file.getPath() + "',"
+ "'" + cutOffEnd(file.getName()) + "', 0, 0, 0, 0)");
connection.commit();
stmt.close();
LOGGER.info("Added \"" + file.getName() + "\" to database");
filmsAll.add(cutOffEnd(file.getName()));
filmsdbStreamURL.add(file.getPath());
}
} else {
// get all folders (series)
@ -371,19 +327,15 @@ public class DBController {
for (File season : file.listFiles()) {
if (season.isDirectory()) {
int ep = 1;
LOGGER.info("Added \"" + file.getName() + "\", Season " + sn + " to database");
// System.out.println("Series name: " + file.getName() + " <=========");
// System.out.println("Season found: " + season + " <=========");
for (File episode : season.listFiles()) {
if (!filmsdbStreamURL.contains(episode.getPath())) {
// System.out.println("Found episode: " + episode);
// System.out.println("Season: " + sn + "; Episod: " + ep);
stmt.executeUpdate("insert into film_loc values ("
LOGGER.info("Added \"" + file.getName() + "\", Episode: " + episode.getName() + " to database");
stmt.executeUpdate("insert into films values ("
+ "'" + episode.getPath() + "',"
+ "'" + cutOffEnd(file.getName()) + "',"+ sn + "," + ep + ", 0, 0)");
connection.commit();
stmt.close();
filmsStreamURL.add(episode.getPath());
filmsdbStreamURL.add(episode.getPath());
ep++;
}
@ -414,7 +366,7 @@ public class DBController {
ps.setBoolean(6, false);
ps.addBatch(); // adds the entry
LOGGER.info("Added \"" + title + "\" to database");
filmsAll.add(cutOffEnd(title));
filmsdbStreamURL.add(streamUrl);
}
}
}
@ -431,7 +383,7 @@ public class DBController {
System.out.println("Outputting all entries ... \n");
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc");
ResultSet rs = stmt.executeQuery("SELECT * FROM films");
while (rs.next()) {
System.out.println(rs.getString("streamUrl"));
System.out.println(rs.getString("title"));
@ -442,21 +394,6 @@ public class DBController {
}
stmt.close();
rs.close();
System.out.println("Streaming Entries: \n");
rs = stmt.executeQuery("SELECT * FROM film_str;");
while (rs.next()) {
System.out.println(rs.getString("streamUrl"));
System.out.println(rs.getString("title"));
System.out.println(rs.getString("season"));
System.out.println(rs.getString("episode"));
System.out.println(rs.getString("rating"));
System.out.println(rs.getString("cached") + "\n");
}
stmt.close();
rs.close();
} catch (SQLException e) {
LOGGER.error("An error occured, while printing all entries", e);
}
@ -471,11 +408,7 @@ public class DBController {
LOGGER.info("dislike " + streamUrl);
try {
Statement stmt = connection.createStatement();
if (mainWindowController.getMode().equals("local")) {
stmt.executeUpdate("UPDATE film_loc SET rating=0 WHERE streamUrl=\"" + streamUrl + "\";");
} else {
stmt.executeUpdate("UPDATE film_str SET rating=0 WHERE streamUrl=\"" + streamUrl + "\";");
}
stmt.executeUpdate("UPDATE films SET rating=0 WHERE streamUrl=\"" + streamUrl + "\";");
connection.commit();
stmt.close();
} catch (SQLException e) {
@ -492,11 +425,7 @@ public class DBController {
LOGGER.info("like " + streamUrl);
try {
Statement stmt = connection.createStatement();
if (mainWindowController.getMode().equals("local")) {
stmt.executeUpdate("UPDATE film_loc SET rating=1 WHERE streamUrl=\"" + streamUrl + "\";");
} else {
stmt.executeUpdate("UPDATE film_str SET rating=1 WHERE streamUrl=\"" + streamUrl + "\";");
}
stmt.executeUpdate("UPDATE films SET rating=1 WHERE streamUrl=\"" + streamUrl + "\";");
connection.commit();
stmt.close();
} catch (SQLException e) {
@ -511,11 +440,7 @@ public class DBController {
void setCached(String streamUrl) {
try {
Statement stmt = connection.createStatement();
if (mainWindowController.getMode().equals("local")) {
stmt.executeUpdate("UPDATE film_loc SET cached=1 WHERE streamUrl=\"" + streamUrl + "\";");
} else {
stmt.executeUpdate("UPDATE film_str SET cached=1 WHERE streamUrl=\"" + streamUrl + "\";");
}
stmt.executeUpdate("UPDATE films SET cached=1 WHERE streamUrl=\"" + streamUrl + "\";");
connection.commit();
stmt.close();
} catch (SQLException e) {

View File

@ -69,11 +69,6 @@
<Font name="System Bold" size="15.0" />
</font>
</JFXButton>
<JFXButton fx:id="switchBtn" onAction="#switchBtnclicked" prefHeight="32.0" prefWidth="150.0" textAlignment="CENTER">
<font>
<Font name="System Bold" size="15.0" />
</font>
</JFXButton>
<JFXButton fx:id="debugBtn" onAction="#debugBtnclicked" prefHeight="32.0" prefWidth="150.0" text="debugging" textAlignment="CENTER">
<font>
<Font name="System Bold" size="15.0" />