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:
parent
189bd515b1
commit
ad63d566c9
|
@ -211,7 +211,7 @@ public class MainWindowController {
|
|||
private ImageView imv1;
|
||||
|
||||
@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
|
||||
TreeTableColumn<FilmTabelDataType, ImageView> columnRating = new TreeTableColumn<>("Rating");
|
||||
@FXML
|
||||
|
@ -245,7 +245,6 @@ public class MainWindowController {
|
|||
// text strings
|
||||
private String errorPlay;
|
||||
private String errorOpenStream;
|
||||
private String errorMode;
|
||||
private String errorLoad;
|
||||
private String errorSave;
|
||||
private String infoText;
|
||||
|
@ -554,7 +553,8 @@ public class MainWindowController {
|
|||
}
|
||||
|
||||
@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 (Desktop.isDesktopSupported()) {
|
||||
new Thread(() -> {
|
||||
|
@ -568,7 +568,7 @@ public class MainWindowController {
|
|||
} else {
|
||||
LOGGER.info("Desktop not supported");
|
||||
}
|
||||
}else if (mode.equals("local")) {
|
||||
}else {
|
||||
if(System.getProperty("os.name").contains("Linux")){
|
||||
String line;
|
||||
String output = "";
|
||||
|
@ -603,9 +603,6 @@ public class MainWindowController {
|
|||
} else {
|
||||
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() {
|
||||
|
||||
if (mode.equals("local")) {
|
||||
for (int i = 0; i < localFilms.size(); i++) {
|
||||
filmRoot.getChildren().add(new TreeItem<FilmTabelDataType>(localFilms.get(i))); // add data to root-node
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
columnRating.setMaxWidth(85);
|
||||
columnTitle.setMaxWidth(290);
|
||||
treeTableViewfilm.getColumns().get(3).setVisible(false);
|
||||
|
@ -887,7 +907,6 @@ public class MainWindowController {
|
|||
columnSeason.setText(getBundle().getString("columnSeason"));
|
||||
errorPlay = getBundle().getString("errorPlay");
|
||||
errorOpenStream = getBundle().getString("errorOpenStream");
|
||||
errorMode = getBundle().getString("errorMode");
|
||||
errorLoad = getBundle().getString("errorLoad");
|
||||
errorSave = getBundle().getString("errorSave");
|
||||
infoText = getBundle().getString("infoText");
|
||||
|
|
|
@ -100,6 +100,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 cache ("
|
||||
|
@ -120,6 +121,7 @@ public class DBController {
|
|||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc");
|
||||
while (rs.next()) {
|
||||
filmsdbDir.add(rs.getString("title"));
|
||||
filmsdbStreamURL.add(rs.getString("streamUrl"));
|
||||
}
|
||||
stmt.close();
|
||||
rs.close();
|
||||
|
@ -171,9 +173,6 @@ public class DBController {
|
|||
for (JsonValue item : items) {
|
||||
filmsAll.add(item.asObject().getString("title", ""));
|
||||
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);
|
||||
} catch (IOException e) {
|
||||
|
@ -195,11 +194,13 @@ public class DBController {
|
|||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_loc ORDER BY title");
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("rating") == 1) {
|
||||
mainWindowController.getLocalFilms().add(new FilmTabelDataType(1, 1, rs.getDouble("rating"), rs.getString("title"),
|
||||
rs.getString("streamUrl"), new ImageView(favorite_black), rs.getBoolean("cached")));
|
||||
mainWindowController.getLocalFilms().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.getLocalFilms().add(new FilmTabelDataType(1, 1, rs.getDouble("rating"), rs.getString("title"),
|
||||
rs.getString("streamUrl"), new ImageView(favorite_border_black), rs.getBoolean("cached")));
|
||||
mainWindowController.getLocalFilms().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();
|
||||
|
@ -209,13 +210,13 @@ public class DBController {
|
|||
rs = stmt.executeQuery("SELECT * FROM film_str ORDER BY title;");
|
||||
while (rs.next()) {
|
||||
if (rs.getInt("rating") == 1) {
|
||||
mainWindowController.getStreamingFilms().add(new FilmTabelDataType(rs.getInt("season"),
|
||||
rs.getInt("episode"), rs.getDouble("rating"), rs.getString("title"), rs.getString("streamUrl"),
|
||||
new ImageView(favorite_black), rs.getBoolean("cached")));
|
||||
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.getInt("season"),
|
||||
rs.getInt("episode"),rs.getDouble("rating"), rs.getString("title"),rs.getString("streamUrl"),
|
||||
new ImageView(favorite_border_black), rs.getBoolean("cached")));
|
||||
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();
|
||||
|
@ -230,9 +231,8 @@ public class DBController {
|
|||
|
||||
/**
|
||||
* refresh data in mainWindowController localFilms and streamingFilms
|
||||
* @param title of the film
|
||||
* @param i index of the film in LocalFilms list
|
||||
* @throws SQLException
|
||||
* @param streamUrl of the film
|
||||
* @param index of the film in LocalFilms list
|
||||
*/
|
||||
public void refresh(String streamUrl, int index) {
|
||||
LOGGER.info("refresh ...");
|
||||
|
@ -242,23 +242,25 @@ public class DBController {
|
|||
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(1, 1, rs.getDouble("rating"),
|
||||
rs.getString("title"), rs.getString("streamUrl"), new ImageView(favorite_black), rs.getBoolean("cached")));
|
||||
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(1, 1, rs.getDouble("rating"),
|
||||
rs.getString("title"), rs.getString("streamUrl"), new ImageView(favorite_border_black), rs.getBoolean("cached")));
|
||||
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();
|
||||
} else {
|
||||
ResultSet rs = stmt.executeQuery("SELECT * FROM film_str WHERE streamUrl = \"" + streamUrl + "\";");
|
||||
if (rs.getInt("rating") == 1) {
|
||||
mainWindowController.getStreamingFilms().set(index, new FilmTabelDataType(rs.getInt("season"),
|
||||
rs.getInt("episode"), rs.getDouble("rating"), rs.getString("title"), rs.getString("streamUrl"),
|
||||
new ImageView(favorite_black), rs.getBoolean("cached")));
|
||||
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.getInt("season"),
|
||||
rs.getInt("episode"), rs.getDouble("rating"), rs.getString("title"), rs.getString("streamUrl"),
|
||||
new ImageView(favorite_border_black), rs.getBoolean("cached")));
|
||||
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();
|
||||
}
|
||||
|
@ -289,7 +291,7 @@ public class DBController {
|
|||
|
||||
try {
|
||||
checkAddEntry();
|
||||
checkRemoveEntry();
|
||||
// checkRemoveEntry();
|
||||
} catch (Exception 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
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private void checkRemoveEntry() {
|
||||
LOGGER.info("checking for entrys to remove to DB ...");
|
||||
|
||||
|
@ -348,19 +352,50 @@ public class DBController {
|
|||
for (SourceDataType source : mainWindowController.getSourcesList()) {
|
||||
// if it's a local source check the folder for new film
|
||||
if (source.getMode().equals("local")) {
|
||||
for (String file : new File(source.getPath()).list()) {
|
||||
if (!filmsdbAll.contains(cutOffEnd(file))) {
|
||||
for (File file : new File(source.getPath()).listFiles()) {
|
||||
|
||||
if (file.isFile()) {
|
||||
// get all files (films)
|
||||
if (!filmsdbStreamURL.contains(file.getPath())) {
|
||||
stmt.executeUpdate("insert into film_loc values ("
|
||||
+ "'" + source.getPath() + "/" + file + "',"
|
||||
+ "'" + cutOffEnd(file) + "', 0, 0, 0, 0)");
|
||||
+ "'" + file.getPath() + "',"
|
||||
+ "'" + cutOffEnd(file.getName()) + "', 0, 0, 0, 0)");
|
||||
connection.commit();
|
||||
stmt.close();
|
||||
LOGGER.info("added \"" + file + "\" to database");
|
||||
filmsAll.add(cutOffEnd(file));
|
||||
}
|
||||
LOGGER.info("Added \"" + file.getName() + "\" to database");
|
||||
filmsAll.add(cutOffEnd(file.getName()));
|
||||
}
|
||||
} else {
|
||||
// if it's a streaming source check the file for new films
|
||||
// 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 {
|
||||
// if it's a streaming source check the file for new films // TODO implement series support
|
||||
for (String entry : filmsStreamURL) {
|
||||
if (!filmsdbStreamURL.contains(entry)) {
|
||||
JsonArray items = Json.parse(new FileReader(source.getPath())).asObject().get("entries").asArray();
|
||||
|
@ -378,7 +413,7 @@ public class DBController {
|
|||
ps.setInt(5, 0);
|
||||
ps.setBoolean(6, false);
|
||||
ps.addBatch(); // adds the entry
|
||||
LOGGER.info("added \"" + title + "\" to database");
|
||||
LOGGER.info("Added \"" + title + "\" to database");
|
||||
filmsAll.add(cutOffEnd(title));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,22 +43,31 @@ public class FilmTabelDataType {
|
|||
|
||||
/** TODO rating boolean
|
||||
* 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 episode episode if it's a series
|
||||
* @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 image favorite icon
|
||||
*/
|
||||
public FilmTabelDataType(final int season, final int episode, final double rating, final String title,
|
||||
final String streamUrl, final ImageView image, final boolean cached) {
|
||||
public FilmTabelDataType(final String streamUrl, final String title, final int season, final int episode,
|
||||
final double rating, final boolean cached, final ImageView image) {
|
||||
this.streamUrl.set(streamUrl);
|
||||
this.title.set(title);
|
||||
this.season.set(season);
|
||||
this.episode.set(episode);
|
||||
this.rating.set(rating);
|
||||
this.title.set(title);
|
||||
this.streamUrl.set(streamUrl);
|
||||
this.image.set(image);
|
||||
this.cached.set(cached);
|
||||
this.image.set(image);
|
||||
}
|
||||
|
||||
public StringProperty streamUrlProperty(){
|
||||
return streamUrl;
|
||||
}
|
||||
|
||||
public StringProperty titleProperty(){
|
||||
return title;
|
||||
}
|
||||
|
||||
public IntegerProperty seasonProperty(){
|
||||
|
@ -73,22 +82,22 @@ public class FilmTabelDataType {
|
|||
return rating;
|
||||
}
|
||||
|
||||
public StringProperty titleProperty(){
|
||||
return title;
|
||||
}
|
||||
|
||||
public StringProperty streamUrlProperty(){
|
||||
return streamUrl;
|
||||
public BooleanProperty cachedProperty(){
|
||||
return cached;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<ImageView> imageProperty(){
|
||||
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() {
|
||||
return seasonProperty().get();
|
||||
|
@ -102,23 +111,22 @@ public class FilmTabelDataType {
|
|||
return ratingProperty().get();
|
||||
}
|
||||
|
||||
public final String getTitle() {
|
||||
return titleProperty().get();
|
||||
}
|
||||
|
||||
public final String getStreamUrl() {
|
||||
return streamUrlProperty().get();
|
||||
public final boolean getCached(){
|
||||
return cachedProperty().get();
|
||||
}
|
||||
|
||||
public final ImageView getImage() {
|
||||
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) {
|
||||
seasonProperty().set(season);
|
||||
|
@ -132,19 +140,13 @@ public class FilmTabelDataType {
|
|||
ratingProperty().set(rating);
|
||||
}
|
||||
|
||||
public final void setTitle(String title) {
|
||||
titleProperty().set(title);
|
||||
}
|
||||
|
||||
public final void setStreamUrl(String streamUrl) {
|
||||
streamUrlProperty().set(streamUrl);
|
||||
public final void setCached(boolean cached){
|
||||
cachedProperty().set(cached);
|
||||
}
|
||||
|
||||
public final void setImage(ImageView image) {
|
||||
imageProperty().set(image);
|
||||
}
|
||||
|
||||
public final void setCached(boolean cached){
|
||||
cachedProperty().set(cached);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue