added support for local series

* HomeFlix now support local saved series, streaming series support will come soon. For more information see: https://github.com/Seil0/Project-HomeFlix/wiki/Documentation#series-support
This commit is contained in:
Jannik 2018-03-06 20:41:52 +01:00
parent 189bd515b1
commit ad63d566c9
3 changed files with 138 additions and 82 deletions

View File

@ -211,7 +211,7 @@ public class MainWindowController {
private ImageView imv1; private ImageView imv1;
@FXML @FXML
private TreeItem<FilmTabelDataType> filmRoot = new TreeItem<>(new FilmTabelDataType(1, 1, 5.0, "filme", "1", imv1, false)); private TreeItem<FilmTabelDataType> filmRoot = new TreeItem<>(new FilmTabelDataType("", "", 0, 0, 0, false, imv1));
@FXML @FXML
TreeTableColumn<FilmTabelDataType, ImageView> columnRating = new TreeTableColumn<>("Rating"); TreeTableColumn<FilmTabelDataType, ImageView> columnRating = new TreeTableColumn<>("Rating");
@FXML @FXML
@ -245,7 +245,6 @@ public class MainWindowController {
// text strings // text strings
private String errorPlay; private String errorPlay;
private String errorOpenStream; private String errorOpenStream;
private String errorMode;
private String errorLoad; private String errorLoad;
private String errorSave; private String errorSave;
private String infoText; private String infoText;
@ -554,7 +553,8 @@ public class MainWindowController {
} }
@FXML @FXML
private void playbtnclicked(){ private void playbtnclicked() {
// TODO open streams with desktop player, works at least with vlc under linux, part of #19
if (mode.equals("streaming")) { if (mode.equals("streaming")) {
if (Desktop.isDesktopSupported()) { if (Desktop.isDesktopSupported()) {
new Thread(() -> { new Thread(() -> {
@ -568,7 +568,7 @@ public class MainWindowController {
} else { } else {
LOGGER.info("Desktop not supported"); LOGGER.info("Desktop not supported");
} }
}else if (mode.equals("local")) { }else {
if(System.getProperty("os.name").contains("Linux")){ if(System.getProperty("os.name").contains("Linux")){
String line; String line;
String output = ""; String output = "";
@ -603,9 +603,6 @@ public class MainWindowController {
} else { } else {
LOGGER.error(System.getProperty("os.name") + ", OS is not supported, please contact a developer! "); LOGGER.error(System.getProperty("os.name") + ", OS is not supported, please contact a developer! ");
} }
} else {
IOException e = new IOException("error");
showErrorMsg(errorMode, e);
} }
} }
@ -735,9 +732,32 @@ public class MainWindowController {
public void addDataUI() { public void addDataUI() {
if (mode.equals("local")) { if (mode.equals("local")) {
for (int i = 0; i < localFilms.size(); i++) { for (FilmTabelDataType element : localFilms) {
filmRoot.getChildren().add(new TreeItem<FilmTabelDataType>(localFilms.get(i))); // add data to root-node 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
}
} }
columnRating.setMaxWidth(85); columnRating.setMaxWidth(85);
columnTitle.setMaxWidth(290); columnTitle.setMaxWidth(290);
treeTableViewfilm.getColumns().get(3).setVisible(false); treeTableViewfilm.getColumns().get(3).setVisible(false);
@ -887,7 +907,6 @@ public class MainWindowController {
columnSeason.setText(getBundle().getString("columnSeason")); columnSeason.setText(getBundle().getString("columnSeason"));
errorPlay = getBundle().getString("errorPlay"); errorPlay = getBundle().getString("errorPlay");
errorOpenStream = getBundle().getString("errorOpenStream"); errorOpenStream = getBundle().getString("errorOpenStream");
errorMode = getBundle().getString("errorMode");
errorLoad = getBundle().getString("errorLoad"); errorLoad = getBundle().getString("errorLoad");
errorSave = getBundle().getString("errorSave"); errorSave = getBundle().getString("errorSave");
infoText = getBundle().getString("infoText"); infoText = getBundle().getString("infoText");

View File

@ -100,6 +100,7 @@ public class DBController {
private void createDatabase() { private void createDatabase() {
try { try {
Statement stmt = connection.createStatement(); 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_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 film_str (streamUrl, title, season, episode, rating, cached)");
stmt.executeUpdate("create table if not exists cache (" stmt.executeUpdate("create table if not exists cache ("
@ -120,6 +121,7 @@ public class DBController {
ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc"); ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc");
while (rs.next()) { while (rs.next()) {
filmsdbDir.add(rs.getString("title")); filmsdbDir.add(rs.getString("title"));
filmsdbStreamURL.add(rs.getString("streamUrl"));
} }
stmt.close(); stmt.close();
rs.close(); rs.close();
@ -171,9 +173,6 @@ public class DBController {
for (JsonValue item : items) { for (JsonValue item : items) {
filmsAll.add(item.asObject().getString("title", "")); filmsAll.add(item.asObject().getString("title", ""));
filmsStreamURL.add(item.asObject().getString("streamUrl", "")); filmsStreamURL.add(item.asObject().getString("streamUrl", ""));
// TODO check if all this is needed, maybe only use one table!
// System.out.println(item.asObject().getString("title", ""));
// System.out.println(item.asObject().getString("streamUrl", ""));
} }
LOGGER.info("added films from: " + path); LOGGER.info("added films from: " + path);
} catch (IOException e) { } catch (IOException e) {
@ -195,11 +194,13 @@ public class DBController {
ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc ORDER BY title"); ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc ORDER BY title");
while (rs.next()) { while (rs.next()) {
if (rs.getInt("rating") == 1) { if (rs.getInt("rating") == 1) {
mainWindowController.getLocalFilms().add(new FilmTabelDataType(1, 1, rs.getDouble("rating"), rs.getString("title"), mainWindowController.getLocalFilms().add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("streamUrl"), new ImageView(favorite_black), rs.getBoolean("cached"))); rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_black)));
} else { } else {
mainWindowController.getLocalFilms().add(new FilmTabelDataType(1, 1, rs.getDouble("rating"), rs.getString("title"), mainWindowController.getLocalFilms().add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("streamUrl"), new ImageView(favorite_border_black), rs.getBoolean("cached"))); rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_border_black)));
} }
} }
stmt.close(); stmt.close();
@ -209,13 +210,13 @@ public class DBController {
rs = stmt.executeQuery("SELECT * FROM film_str ORDER BY title;"); rs = stmt.executeQuery("SELECT * FROM film_str ORDER BY title;");
while (rs.next()) { while (rs.next()) {
if (rs.getInt("rating") == 1) { if (rs.getInt("rating") == 1) {
mainWindowController.getStreamingFilms().add(new FilmTabelDataType(rs.getInt("season"), mainWindowController.getStreamingFilms().add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getInt("episode"), rs.getDouble("rating"), rs.getString("title"), rs.getString("streamUrl"), rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
new ImageView(favorite_black), rs.getBoolean("cached"))); rs.getBoolean("cached"), new ImageView(favorite_black)));
} else { } else {
mainWindowController.getStreamingFilms().add(new FilmTabelDataType(rs.getInt("season"), mainWindowController.getStreamingFilms().add(new FilmTabelDataType(rs.getString("streamUrl"),
rs.getInt("episode"),rs.getDouble("rating"), rs.getString("title"),rs.getString("streamUrl"), rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
new ImageView(favorite_border_black), rs.getBoolean("cached"))); rs.getBoolean("cached"), new ImageView(favorite_border_black)));
} }
} }
stmt.close(); stmt.close();
@ -230,9 +231,8 @@ public class DBController {
/** /**
* refresh data in mainWindowController localFilms and streamingFilms * refresh data in mainWindowController localFilms and streamingFilms
* @param title of the film * @param streamUrl of the film
* @param i index of the film in LocalFilms list * @param index of the film in LocalFilms list
* @throws SQLException
*/ */
public void refresh(String streamUrl, int index) { public void refresh(String streamUrl, int index) {
LOGGER.info("refresh ..."); LOGGER.info("refresh ...");
@ -242,23 +242,25 @@ public class DBController {
if (mainWindowController.getMode().equals("local")) { if (mainWindowController.getMode().equals("local")) {
ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc WHERE streamUrl = \"" + streamUrl + "\";"); ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc WHERE streamUrl = \"" + streamUrl + "\";");
if (rs.getInt("rating") == 1) { if (rs.getInt("rating") == 1) {
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(1, 1, rs.getDouble("rating"), mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getString("streamUrl"), new ImageView(favorite_black), rs.getBoolean("cached"))); rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
rs.getBoolean("cached"), new ImageView(favorite_black)));
} else { } else {
mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(1, 1, rs.getDouble("rating"), mainWindowController.getLocalFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getString("title"), rs.getString("streamUrl"), new ImageView(favorite_border_black), rs.getBoolean("cached"))); rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
} rs.getBoolean("cached"), new ImageView(favorite_border_black)));
}
rs.close(); rs.close();
} else { } else {
ResultSet rs = stmt.executeQuery("SELECT * FROM film_str WHERE streamUrl = \"" + streamUrl + "\";"); ResultSet rs = stmt.executeQuery("SELECT * FROM film_str WHERE streamUrl = \"" + streamUrl + "\";");
if (rs.getInt("rating") == 1) { if (rs.getInt("rating") == 1) {
mainWindowController.getStreamingFilms().set(index, new FilmTabelDataType(rs.getInt("season"), mainWindowController.getStreamingFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getInt("episode"), rs.getDouble("rating"), rs.getString("title"), rs.getString("streamUrl"), rs.getString("title"), rs.getInt("season"), rs.getInt("episode") ,rs.getDouble("rating"),
new ImageView(favorite_black), rs.getBoolean("cached"))); rs.getBoolean("cached"), new ImageView(favorite_black)));
} else { } else {
mainWindowController.getStreamingFilms().set(index, new FilmTabelDataType(rs.getInt("season"), mainWindowController.getStreamingFilms().set(index, new FilmTabelDataType(rs.getString("streamUrl"),
rs.getInt("episode"), rs.getDouble("rating"), rs.getString("title"), rs.getString("streamUrl"), rs.getString("title"), rs.getInt("season"), rs.getInt("episode"), rs.getDouble("rating"),
new ImageView(favorite_border_black), rs.getBoolean("cached"))); rs.getBoolean("cached"), new ImageView(favorite_border_black)));
} }
rs.close(); rs.close();
} }
@ -289,7 +291,7 @@ public class DBController {
try { try {
checkAddEntry(); checkAddEntry();
checkRemoveEntry(); // checkRemoveEntry();
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("Error while refreshing the database", e); LOGGER.error("Error while refreshing the database", e);
} }
@ -303,8 +305,10 @@ public class DBController {
} }
/** /**
* TODO needs reworking currently broken
* check if there are any entries that have been removed from the film-directory * check if there are any entries that have been removed from the film-directory
*/ */
@SuppressWarnings("unused")
private void checkRemoveEntry() { private void checkRemoveEntry() {
LOGGER.info("checking for entrys to remove to DB ..."); LOGGER.info("checking for entrys to remove to DB ...");
@ -348,19 +352,50 @@ public class DBController {
for (SourceDataType source : mainWindowController.getSourcesList()) { for (SourceDataType source : mainWindowController.getSourcesList()) {
// if it's a local source check the folder for new film // if it's a local source check the folder for new film
if (source.getMode().equals("local")) { if (source.getMode().equals("local")) {
for (String file : new File(source.getPath()).list()) { for (File file : new File(source.getPath()).listFiles()) {
if (!filmsdbAll.contains(cutOffEnd(file))) {
stmt.executeUpdate("insert into film_loc values (" if (file.isFile()) {
+ "'" + source.getPath() + "/" + file + "'," // get all files (films)
+ "'" + cutOffEnd(file) + "', 0, 0, 0, 0)"); if (!filmsdbStreamURL.contains(file.getPath())) {
connection.commit(); stmt.executeUpdate("insert into film_loc values ("
stmt.close(); + "'" + file.getPath() + "',"
LOGGER.info("added \"" + file + "\" to database"); + "'" + cutOffEnd(file.getName()) + "', 0, 0, 0, 0)");
filmsAll.add(cutOffEnd(file)); connection.commit();
stmt.close();
LOGGER.info("Added \"" + file.getName() + "\" to database");
filmsAll.add(cutOffEnd(file.getName()));
}
} else {
// get all folders (series)
int sn = 1;
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 ("
+ "'" + episode.getPath() + "',"
+ "'" + cutOffEnd(file.getName()) + "',"+ sn + "," + ep + ", 0, 0)");
connection.commit();
stmt.close();
filmsdbStreamURL.add(episode.getPath());
ep++;
}
}
sn++;
}
}
} }
} }
} else { } else {
// if it's a streaming source check the file for new films // if it's a streaming source check the file for new films // TODO implement series support
for (String entry : filmsStreamURL) { for (String entry : filmsStreamURL) {
if (!filmsdbStreamURL.contains(entry)) { if (!filmsdbStreamURL.contains(entry)) {
JsonArray items = Json.parse(new FileReader(source.getPath())).asObject().get("entries").asArray(); JsonArray items = Json.parse(new FileReader(source.getPath())).asObject().get("entries").asArray();
@ -378,7 +413,7 @@ public class DBController {
ps.setInt(5, 0); ps.setInt(5, 0);
ps.setBoolean(6, false); ps.setBoolean(6, false);
ps.addBatch(); // adds the entry ps.addBatch(); // adds the entry
LOGGER.info("added \"" + title + "\" to database"); LOGGER.info("Added \"" + title + "\" to database");
filmsAll.add(cutOffEnd(title)); filmsAll.add(cutOffEnd(title));
} }
} }

View File

@ -43,22 +43,31 @@ public class FilmTabelDataType {
/** TODO rating boolean /** TODO rating boolean
* tableData is the data-type of tree-table-view * tableData is the data-type of tree-table-view
* @param streamUrl the concrete path to the file or the URL
* @param title title of the film
* @param season season if it's a series * @param season season if it's a series
* @param episode episode if it's a series * @param episode episode if it's a series
* @param rating indicator for favorites, used for sorting the items * @param rating indicator for favorites, used for sorting the items
* @param title title of the film
* @param streamUrl the concrete path to the file or the URL
* @param cached indicator for caching status * @param cached indicator for caching status
* @param image favorite icon
*/ */
public FilmTabelDataType(final int season, final int episode, final double rating, final String title, public FilmTabelDataType(final String streamUrl, final String title, final int season, final int episode,
final String streamUrl, final ImageView image, final boolean cached) { final double rating, final boolean cached, final ImageView image) {
this.streamUrl.set(streamUrl);
this.title.set(title);
this.season.set(season); this.season.set(season);
this.episode.set(episode); this.episode.set(episode);
this.rating.set(rating); this.rating.set(rating);
this.title.set(title);
this.streamUrl.set(streamUrl);
this.image.set(image);
this.cached.set(cached); this.cached.set(cached);
this.image.set(image);
}
public StringProperty streamUrlProperty(){
return streamUrl;
}
public StringProperty titleProperty(){
return title;
} }
public IntegerProperty seasonProperty(){ public IntegerProperty seasonProperty(){
@ -73,22 +82,22 @@ public class FilmTabelDataType {
return rating; return rating;
} }
public StringProperty titleProperty(){ public BooleanProperty cachedProperty(){
return title; return cached;
}
public StringProperty streamUrlProperty(){
return streamUrl;
} }
public SimpleObjectProperty<ImageView> imageProperty(){ public SimpleObjectProperty<ImageView> imageProperty(){
return image; return image;
} }
public BooleanProperty cachedProperty(){
return cached; public final String getStreamUrl() {
return streamUrlProperty().get();
} }
public final String getTitle() {
return titleProperty().get();
}
public final int getSeason() { public final int getSeason() {
return seasonProperty().get(); return seasonProperty().get();
@ -102,23 +111,22 @@ public class FilmTabelDataType {
return ratingProperty().get(); return ratingProperty().get();
} }
public final String getTitle() { public final boolean getCached(){
return titleProperty().get(); return cachedProperty().get();
}
public final String getStreamUrl() {
return streamUrlProperty().get();
} }
public final ImageView getImage() { public final ImageView getImage() {
return imageProperty().get(); return imageProperty().get();
} }
public final boolean getCached(){
return cachedProperty().get(); public final void setStreamUrl(String streamUrl) {
streamUrlProperty().set(streamUrl);
} }
public final void setTitle(String title) {
titleProperty().set(title);
}
public final void setSeason(int season) { public final void setSeason(int season) {
seasonProperty().set(season); seasonProperty().set(season);
@ -132,19 +140,13 @@ public class FilmTabelDataType {
ratingProperty().set(rating); ratingProperty().set(rating);
} }
public final void setTitle(String title) { public final void setCached(boolean cached){
titleProperty().set(title); cachedProperty().set(cached);
}
public final void setStreamUrl(String streamUrl) {
streamUrlProperty().set(streamUrl);
} }
public final void setImage(ImageView image) { public final void setImage(ImageView image) {
imageProperty().set(image); imageProperty().set(image);
} }
public final void setCached(boolean cached){
cachedProperty().set(cached);
}
} }