bug fixes
* fixed loading cache only after restart * fixed loading cache for rootNodes * fixed default image if api doesn't have a poster * updated JFoenix 9.0.8 -> 9.0.9
This commit is contained in:
parent
4ff8b7819f
commit
4d503546ff
2
pom.xml
2
pom.xml
@ -51,7 +51,7 @@
|
||||
<dependency>
|
||||
<groupId>com.jfoenix</groupId>
|
||||
<artifactId>jfoenix</artifactId>
|
||||
<version>9.0.8</version>
|
||||
<version>9.0.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -146,7 +146,7 @@ public class MainWindowController {
|
||||
@FXML private TreeTableColumn<FilmTabelDataType, ImageView> columnFavorite;
|
||||
@FXML private TreeTableColumn<FilmTabelDataType, String> columnSeason;
|
||||
@FXML private TreeTableColumn<FilmTabelDataType, String> columnEpisode;
|
||||
@FXML private TreeItem<FilmTabelDataType> filmRoot = new TreeItem<>(new FilmTabelDataType("", "", "", "", false, null, null));
|
||||
@FXML private TreeItem<FilmTabelDataType> filmRoot = new TreeItem<>(new FilmTabelDataType("", "", "", "", false, null));
|
||||
|
||||
|
||||
@FXML private ScrollPane textScrollPane;
|
||||
@ -180,7 +180,7 @@ public class MainWindowController {
|
||||
private int indexTable;
|
||||
private int indexList;
|
||||
private int next;
|
||||
private FilmTabelDataType currentTableFilm = new FilmTabelDataType("", "", "", "", false, null, null);
|
||||
private FilmTabelDataType currentTableFilm = new FilmTabelDataType("", "", "", "", false, null);
|
||||
|
||||
private ObservableList<String> languages = FXCollections.observableArrayList("English (en_US)", "Deutsch (de_DE)");
|
||||
private ObservableList<String> branches = FXCollections.observableArrayList("stable", "beta");
|
||||
@ -394,7 +394,8 @@ public class MainWindowController {
|
||||
}
|
||||
}
|
||||
|
||||
if ((currentTableFilm.getCached().isAfter(lastValidCache)) && dbController.searchCacheByURL(getCurrentStreamUrl())) {
|
||||
if ((dbController.getCached(getCurrentStreamUrl()).isAfter(lastValidCache) || getCurrentStreamUrl().contains("_rootNode"))
|
||||
&& dbController.searchCacheByURL(getCurrentStreamUrl())) {
|
||||
LOGGER.info("loading from cache: " + getCurrentTitle());
|
||||
setSelectedFilmInfo(dbController.readCache(getCurrentStreamUrl()));
|
||||
} else {
|
||||
@ -607,12 +608,12 @@ public class MainWindowController {
|
||||
TreeItem<FilmTabelDataType> episodeNode = new TreeItem<>(
|
||||
new FilmTabelDataType(element.getStreamUrl(), element.getTitle(),
|
||||
element.getSeason(), element.getEpisode(), element.getFavorite(),
|
||||
element.getCached(), element.getImage()));
|
||||
element.getImage()));
|
||||
filmRoot.getChildren().get(i).getChildren().add(episodeNode);
|
||||
} else if (filmRoot.getChildren().get(i).nextSibling() == null) {
|
||||
TreeItem<FilmTabelDataType> seriesRootNode = new TreeItem<>(
|
||||
new FilmTabelDataType(element.getTitle() + "_rootNode", element.getTitle(), "", "",
|
||||
element.getFavorite(), element.getCached(), element.getImage()));
|
||||
element.getFavorite(), element.getImage()));
|
||||
filmRoot.getChildren().add(seriesRootNode);
|
||||
}
|
||||
}
|
||||
@ -620,13 +621,13 @@ public class MainWindowController {
|
||||
// add new root node
|
||||
TreeItem<FilmTabelDataType> seriesRootNode = new TreeItem<>(
|
||||
new FilmTabelDataType(element.getTitle() + "_rootNode", element.getTitle(), "", "",
|
||||
element.getFavorite(), element.getCached(), element.getImage()));
|
||||
element.getFavorite(), element.getImage()));
|
||||
filmRoot.getChildren().add(seriesRootNode);
|
||||
|
||||
// add new element
|
||||
TreeItem<FilmTabelDataType> episodeNode = new TreeItem<>(new FilmTabelDataType(
|
||||
element.getStreamUrl(), element.getTitle(), element.getSeason(), element.getEpisode(),
|
||||
element.getFavorite(), element.getCached(), element.getImage()));
|
||||
element.getFavorite(), element.getImage()));
|
||||
filmRoot.getChildren().get(0).getChildren().add(episodeNode);
|
||||
}
|
||||
|
||||
@ -836,7 +837,7 @@ public class MainWindowController {
|
||||
try {
|
||||
posterImageView.setImage(new Image(new File(cacheData[20]).toURI().toString()));
|
||||
} catch (Exception e) {
|
||||
posterImageView.setImage(new Image(cacheData[20]));
|
||||
posterImageView.setImage(new Image("icons/Homeflix_Poster.png"));
|
||||
LOGGER.error("No Poster found, useing default.");
|
||||
}
|
||||
} else {
|
||||
|
@ -32,6 +32,7 @@ import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -130,7 +131,7 @@ public class DBController {
|
||||
while (rs.next()) {
|
||||
databaseStreams.add(new DatabaseDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"),
|
||||
rs.getInt("favorite"), rs.getDate("cached"), rs.getDouble("currentTime")));
|
||||
rs.getInt("favorite"), rs.getDouble("currentTime")));
|
||||
}
|
||||
stmt.close();
|
||||
rs.close();
|
||||
@ -140,7 +141,7 @@ public class DBController {
|
||||
}
|
||||
|
||||
/**
|
||||
* load all sources
|
||||
* load all source streams
|
||||
*/
|
||||
private void loadSources() {
|
||||
SourcesController sourcesController = new SourcesController();
|
||||
@ -163,7 +164,7 @@ public class DBController {
|
||||
ImageView imageView = rs.getBoolean("favorite") ? new ImageView(favorite_black) : new ImageView(favorite_border_black);
|
||||
filmsList.add(new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode") ,rs.getBoolean("favorite"),
|
||||
rs.getDate("cached").toLocalDate(), imageView));
|
||||
imageView));
|
||||
}
|
||||
stmt.close();
|
||||
rs.close();
|
||||
@ -191,7 +192,7 @@ public class DBController {
|
||||
ImageView imageView = rs.getBoolean("favorite") ? new ImageView(favorite_black) : new ImageView(favorite_border_black);
|
||||
film = new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getDate("cached").toLocalDate(), imageView);
|
||||
imageView);
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
@ -322,7 +323,7 @@ public class DBController {
|
||||
ps.setString(3, sourceStreamEntry.getSeason());
|
||||
ps.setString(4, sourceStreamEntry.getEpisode());
|
||||
ps.setInt(5, sourceStreamEntry.getFavorite());
|
||||
ps.setDate(6, sourceStreamEntry.getCached());
|
||||
ps.setDate(6, new Date(0));
|
||||
ps.setDouble(7, sourceStreamEntry.getCurrentTime());
|
||||
ps.addBatch(); // adds the entry
|
||||
LOGGER.info("Added \"" + sourceStreamEntry.getTitle() + "\" to database");
|
||||
@ -411,6 +412,30 @@ public class DBController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the cached date for the film
|
||||
* @param streamUrl URL of the film
|
||||
*/
|
||||
public LocalDate getCached(String streamUrl) {
|
||||
LocalDate cacheDate = LocalDate.now().minusDays(31);
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement("SELECT cached FROM films WHERE streamUrl = ?");
|
||||
ps.setString(1, streamUrl);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
cacheDate = rs.getDate("cached").toLocalDate();
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Ups! an error occured!", e);
|
||||
}
|
||||
|
||||
return cacheDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* add the received data to the cache table
|
||||
* @param streamUrl URL of the film
|
||||
@ -537,7 +562,7 @@ public class DBController {
|
||||
while (rs.next()) {
|
||||
notCachedEntries.add(new FilmTabelDataType(rs.getString("streamUrl"),
|
||||
rs.getString("title"), rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getDate("cached").toLocalDate(), new ImageView(favorite_border_black)));
|
||||
new ImageView(favorite_border_black)));
|
||||
}
|
||||
stmt.close();
|
||||
rs.close();
|
||||
@ -622,7 +647,7 @@ public class DBController {
|
||||
// at this point we have found the correct episode
|
||||
nextFilm = new FilmTabelDataType(rs.getString("streamUrl"), rs.getString("title"),
|
||||
rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getDate("cached").toLocalDate(), new ImageView());
|
||||
new ImageView());
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
@ -648,7 +673,7 @@ public class DBController {
|
||||
while (rs.next()) {
|
||||
nextFilm = new FilmTabelDataType(rs.getString("streamUrl"), rs.getString("title"),
|
||||
rs.getString("season"), rs.getString("episode"), rs.getBoolean("favorite"),
|
||||
rs.getDate("cached").toLocalDate(), new ImageView());
|
||||
new ImageView());
|
||||
// get the first episode where currentTime != 0
|
||||
if (rs.getDouble("currentTime") > lastCurrentTime) {
|
||||
break;
|
||||
|
@ -130,18 +130,23 @@ public class OMDbAPIController implements Runnable {
|
||||
omdbResponse.setWebsite(object.getString("Website", ""));
|
||||
omdbResponse.setResponse(object.getString("Response", ""));
|
||||
|
||||
// resize the image to fit in the posterImageView and add it to the cache
|
||||
try {
|
||||
BufferedImage originalImage = ImageIO.read(new URL(object.getString("Poster", "")));
|
||||
// change path to where file is located
|
||||
omdbResponse.setPoster(XMLController.getPosterCache() + "/" + omdbResponse.getTitle() + ".png");
|
||||
ImageIO.write(originalImage, "png", new File(omdbResponse.getPoster()));
|
||||
LOGGER.info("adding poster to cache: " + omdbResponse.getPoster());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
// if a poster exist try resizing it to fit in the posterImageView and add it to the cache, else use the default
|
||||
if (omdbResponse.getPoster() != null) {
|
||||
try {
|
||||
BufferedImage originalImage = ImageIO.read(new URL(object.getString("Poster", "")));
|
||||
// change path to where file is located
|
||||
omdbResponse.setPoster(XMLController.getPosterCache() + "/" + omdbResponse.getTitle() + ".png");
|
||||
ImageIO.write(originalImage, "png", new File(omdbResponse.getPoster()));
|
||||
LOGGER.info("adding poster to cache: " + omdbResponse.getPoster());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
} else {
|
||||
omdbResponse.setPoster("icons/Homeflix_Poster.png");
|
||||
}
|
||||
|
||||
|
||||
|
||||
synchronized (this) {
|
||||
// adding to cache
|
||||
dbController.addCache(currentTableFilm.getStreamUrl(), omdbResponse);
|
||||
|
@ -26,7 +26,6 @@ import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.sql.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -89,7 +88,7 @@ public class SourcesController {
|
||||
for (File file : new File(path).listFiles()) {
|
||||
// if it's valid file add it to the sourceStreams
|
||||
if (isValidFile(file)) {
|
||||
sourceStreams.add(new DatabaseDataType(file.getPath(), cutOffEnd(file.getName()), "", "", 0, new Date(0), 0.0));
|
||||
sourceStreams.add(new DatabaseDataType(file.getPath(), cutOffEnd(file.getName()), "", "", 0, 0.0));
|
||||
} else if(file.isDirectory()) {
|
||||
// get all directories (series), root and season must be directories
|
||||
int sn = 1;
|
||||
@ -100,7 +99,7 @@ public class SourcesController {
|
||||
// check whether the episode is a valid file
|
||||
if (isValidFile(episode)) {
|
||||
sourceStreams.add(new DatabaseDataType(episode.getPath(), cutOffEnd(file.getName()),
|
||||
Integer.toString(sn), Integer.toString(ep), 0, new Date(0), 0.0));
|
||||
Integer.toString(sn), Integer.toString(ep), 0, 0.0));
|
||||
ep++;
|
||||
}
|
||||
}
|
||||
@ -122,7 +121,7 @@ public class SourcesController {
|
||||
sourceStreams.add(new DatabaseDataType(item.asObject().getString("streamUrl", ""),
|
||||
item.asObject().getString("title", ""),
|
||||
item.asObject().getString("season", ""),
|
||||
item.asObject().getString("episode", ""), 0, new Date(0), 0.0));
|
||||
item.asObject().getString("episode", ""), 0, 0.0));
|
||||
}
|
||||
LOGGER.info("added " + items.size() +" stream entries from: " + path);
|
||||
} catch (IOException e) {
|
||||
|
@ -22,8 +22,6 @@
|
||||
|
||||
package kellerkinder.HomeFlix.datatypes;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
public class DatabaseDataType {
|
||||
|
||||
private String streamUrl;
|
||||
@ -31,20 +29,18 @@ public class DatabaseDataType {
|
||||
private String season;
|
||||
private String episode;
|
||||
private int favorite;
|
||||
private Date cached;
|
||||
private double currentTime;
|
||||
|
||||
public DatabaseDataType() {
|
||||
// constructor stub
|
||||
}
|
||||
|
||||
public DatabaseDataType(String streamUrl, String title, String season, String episode, int favorite, Date cached, double currentTime) {
|
||||
public DatabaseDataType(String streamUrl, String title, String season, String episode, int favorite, double currentTime) {
|
||||
this.streamUrl = streamUrl;
|
||||
this.title = title;
|
||||
this.season = season;
|
||||
this.episode = episode;
|
||||
this.favorite = favorite;
|
||||
this.cached = cached;
|
||||
this.currentTime = currentTime;
|
||||
}
|
||||
|
||||
@ -88,14 +84,6 @@ public class DatabaseDataType {
|
||||
this.favorite = favorite;
|
||||
}
|
||||
|
||||
public Date getCached() {
|
||||
return cached;
|
||||
}
|
||||
|
||||
public void setCached(Date cached) {
|
||||
this.cached = cached;
|
||||
}
|
||||
|
||||
public double getCurrentTime() {
|
||||
return currentTime;
|
||||
}
|
||||
|
@ -20,8 +20,6 @@
|
||||
*/
|
||||
package kellerkinder.HomeFlix.datatypes;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
@ -35,7 +33,6 @@ public class FilmTabelDataType {
|
||||
private final StringProperty season = new SimpleStringProperty();
|
||||
private final StringProperty episode = new SimpleStringProperty();
|
||||
private final BooleanProperty favorite = new SimpleBooleanProperty();
|
||||
private final SimpleObjectProperty<LocalDate> cached = new SimpleObjectProperty<>();
|
||||
private final SimpleObjectProperty<ImageView> image = new SimpleObjectProperty<>();
|
||||
|
||||
/**
|
||||
@ -49,13 +46,12 @@ public class FilmTabelDataType {
|
||||
* @param image favorite icon
|
||||
*/
|
||||
public FilmTabelDataType(final String streamUrl, final String title, final String season, final String episode,
|
||||
final boolean favorite, final LocalDate cached, final ImageView image) {
|
||||
final boolean favorite, final ImageView image) {
|
||||
this.streamUrl.set(streamUrl);
|
||||
this.title.set(title);
|
||||
this.season.set(season);
|
||||
this.episode.set(episode);
|
||||
this.favorite.set(favorite);
|
||||
this.cached.set(cached);
|
||||
this.image.set(image);
|
||||
}
|
||||
|
||||
@ -79,10 +75,6 @@ public class FilmTabelDataType {
|
||||
return favorite;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<LocalDate> cachedProperty(){
|
||||
return cached;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<ImageView> imageProperty(){
|
||||
return image;
|
||||
}
|
||||
@ -108,10 +100,6 @@ public class FilmTabelDataType {
|
||||
return favoriteProperty().get();
|
||||
}
|
||||
|
||||
public final LocalDate getCached(){
|
||||
return cachedProperty().get();
|
||||
}
|
||||
|
||||
public final ImageView getImage() {
|
||||
return imageProperty().get();
|
||||
}
|
||||
@ -137,10 +125,6 @@ public class FilmTabelDataType {
|
||||
favoriteProperty().set(favorite);
|
||||
}
|
||||
|
||||
public final void setCached(LocalDate cached){
|
||||
cachedProperty().set(cached);
|
||||
}
|
||||
|
||||
public final void setImage(ImageView image) {
|
||||
imageProperty().set(image);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user