HomeFLix now shows the plot for each episode of a series
* added episode plot support * fixed omdb api search not working correctly
This commit is contained in:
parent
391ef59f70
commit
74e8783082
|
@ -215,7 +215,7 @@ public class MainWindowController {
|
||||||
private boolean autoplay = false;
|
private boolean autoplay = false;
|
||||||
|
|
||||||
private final String version = "0.7.0";
|
private final String version = "0.7.0";
|
||||||
private final String buildNumber = "151";
|
private final String buildNumber = "155";
|
||||||
private final String versionName = "toothless dragon";
|
private final String versionName = "toothless dragon";
|
||||||
private String btnStyle;
|
private String btnStyle;
|
||||||
private String color;
|
private String color;
|
||||||
|
@ -482,7 +482,7 @@ public class MainWindowController {
|
||||||
last = indexTable - 1;
|
last = indexTable - 1;
|
||||||
next = indexTable + 1;
|
next = indexTable + 1;
|
||||||
|
|
||||||
if (currentTableFilm.getCached() || dbController.searchCache(getCurrentStreamUrl())) {
|
if (currentTableFilm.getCached() || dbController.searchCacheByURL(getCurrentStreamUrl())) {
|
||||||
LOGGER.info("loading from cache: " + getCurrentTitle());
|
LOGGER.info("loading from cache: " + getCurrentTitle());
|
||||||
dbController.readCache(getCurrentStreamUrl());
|
dbController.readCache(getCurrentStreamUrl());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -42,6 +42,8 @@ import com.eclipsesource.json.JsonArray;
|
||||||
import com.eclipsesource.json.JsonObject;
|
import com.eclipsesource.json.JsonObject;
|
||||||
import com.eclipsesource.json.JsonValue;
|
import com.eclipsesource.json.JsonValue;
|
||||||
|
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.scene.Node;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.ImageView;
|
import javafx.scene.image.ImageView;
|
||||||
import javafx.scene.text.Font;
|
import javafx.scene.text.Font;
|
||||||
|
@ -51,6 +53,7 @@ import kellerkinder.HomeFlix.application.Main;
|
||||||
import kellerkinder.HomeFlix.application.MainWindowController;
|
import kellerkinder.HomeFlix.application.MainWindowController;
|
||||||
import kellerkinder.HomeFlix.datatypes.SourceDataType;
|
import kellerkinder.HomeFlix.datatypes.SourceDataType;
|
||||||
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
|
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
|
||||||
|
import kellerkinder.HomeFlix.datatypes.OMDbAPIResponseDataType;
|
||||||
|
|
||||||
public class DBController {
|
public class DBController {
|
||||||
|
|
||||||
|
@ -112,14 +115,14 @@ public class DBController {
|
||||||
* films table: streamUrl is primary key
|
* films table: streamUrl is primary key
|
||||||
* cache table: streamUrl is primary key
|
* cache table: streamUrl is primary key
|
||||||
*/
|
*/
|
||||||
private void createDatabase() {
|
private void createDatabase() {
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
stmt.executeUpdate("create table if not exists films (streamUrl, title, season, episode, favorite, cached, currentTime)");
|
stmt.executeUpdate("create table if not exists films (streamUrl, title, season, episode, favorite, cached, currentTime)");
|
||||||
stmt.executeUpdate("create table if not exists cache ("
|
stmt.executeUpdate("create table if not exists cache ("
|
||||||
+ "streamUrl, Title, Year, Rated, Released, Runtime, Genre, Director, Writer,"
|
+ "streamUrl, Title, Year, Rated, Released, Season, Episode ,Runtime, Genre, Director, Writer,"
|
||||||
+ " Actors, Plot, Language, Country, Awards, Metascore, imdbRating, imdbVotes,"
|
+ " Actors, Plot, Language, Country, Awards, Poster, Metascore, imdbRating, imdbVotes,"
|
||||||
+ " imdbID, Type, Poster, Response)");
|
+ " imdbID, Type, dvd, BoxOffice, Website, Response)");
|
||||||
stmt.close();
|
stmt.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.error(e);
|
LOGGER.error(e);
|
||||||
|
@ -481,62 +484,45 @@ public class DBController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* add the received data to the cache table
|
* add the received data to the cache table
|
||||||
* @param streamUrl URL of the film
|
* @param streamUrl URL of the film
|
||||||
* @param Title
|
* @param omdbResponse the response data from omdbAPI
|
||||||
* @param Year
|
|
||||||
* @param Rated
|
|
||||||
* @param Released
|
|
||||||
* @param Runtime
|
|
||||||
* @param Genre
|
|
||||||
* @param Director
|
|
||||||
* @param Writer
|
|
||||||
* @param Actors
|
|
||||||
* @param Plot
|
|
||||||
* @param Language
|
|
||||||
* @param Country
|
|
||||||
* @param Awards
|
|
||||||
* @param Metascore
|
|
||||||
* @param imdbRating
|
|
||||||
* @param Type
|
|
||||||
* @param imdbVotes
|
|
||||||
* @param imdbID
|
|
||||||
* @param Poster
|
|
||||||
* @param Response
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
*/
|
||||||
void addCache( String streamUrl, String Title, String Year, String Rated, String Released, String Runtime, String Genre, String Director,
|
void addCache(String streamUrl, OMDbAPIResponseDataType omdbResponse) {
|
||||||
String Writer, String Actors, String Plot, String Language, String Country, String Awards, String Metascore, String imdbRating,
|
|
||||||
String Type, String imdbVotes, String imdbID, String Poster, String Response) {
|
|
||||||
try {
|
try {
|
||||||
PreparedStatement ps = connection.prepareStatement("insert into cache values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
PreparedStatement ps = connection.prepareStatement("insert into cache values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||||
|
|
||||||
LOGGER.info("adding to cache: " + Title);
|
LOGGER.info("adding to cache: " + omdbResponse.getTitle());
|
||||||
ps.setString(1,streamUrl);
|
ps.setString(1,streamUrl);
|
||||||
ps.setString(2,Title);
|
ps.setString(2,omdbResponse.getTitle());
|
||||||
ps.setString(3,Year);
|
ps.setString(3,omdbResponse.getYear());
|
||||||
ps.setString(4,Rated);
|
ps.setString(4,omdbResponse.getRated());
|
||||||
ps.setString(5,Released);
|
ps.setString(5,omdbResponse.getReleased());
|
||||||
ps.setString(6,Runtime);
|
ps.setString(6,omdbResponse.getSeason());
|
||||||
ps.setString(7,Genre);
|
ps.setString(7,omdbResponse.getEpisode());
|
||||||
ps.setString(8,Director);
|
ps.setString(8,omdbResponse.getRuntime());
|
||||||
ps.setString(9,Writer);
|
ps.setString(9,omdbResponse.getGenre());
|
||||||
ps.setString(10,Actors);
|
ps.setString(10,omdbResponse.getDirector());
|
||||||
ps.setString(11,Plot);
|
ps.setString(11,omdbResponse.getWriter());
|
||||||
ps.setString(12,Language);
|
ps.setString(12,omdbResponse.getActors());
|
||||||
ps.setString(13,Country);
|
ps.setString(13,omdbResponse.getPlot());
|
||||||
ps.setString(14,Awards);
|
ps.setString(14,omdbResponse.getLanguage());
|
||||||
ps.setString(15,Metascore);
|
ps.setString(15,omdbResponse.getCountry());
|
||||||
ps.setString(16,imdbRating);
|
ps.setString(16,omdbResponse.getAwards());
|
||||||
ps.setString(17,imdbVotes);
|
ps.setString(17,omdbResponse.getPoster());
|
||||||
ps.setString(18,imdbID);
|
ps.setString(18,omdbResponse.getMetascore());
|
||||||
ps.setString(19,Type);
|
ps.setString(19,omdbResponse.getImdbRating());
|
||||||
ps.setString(20,Poster);
|
ps.setString(20,omdbResponse.getImdbVotes());
|
||||||
ps.setString(21,Response);
|
ps.setString(21,omdbResponse.getImdbID());
|
||||||
|
ps.setString(22,omdbResponse.getType());
|
||||||
|
ps.setString(23,omdbResponse.getDvd());
|
||||||
|
ps.setString(24,omdbResponse.getBoxOffice());
|
||||||
|
ps.setString(25,omdbResponse.getWebsite());
|
||||||
|
ps.setString(26,omdbResponse.getResponse());
|
||||||
|
|
||||||
ps.addBatch();
|
ps.addBatch();
|
||||||
ps.executeBatch();
|
ps.executeBatch();
|
||||||
connection.commit();
|
connection.commit();
|
||||||
ps.close();
|
ps.close();
|
||||||
LOGGER.info("done!");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e);
|
LOGGER.error(e);
|
||||||
}
|
}
|
||||||
|
@ -547,7 +533,7 @@ public class DBController {
|
||||||
* @param streamUrl URL of the element
|
* @param streamUrl URL of the element
|
||||||
* @return true if the element is already cached, else false
|
* @return true if the element is already cached, else false
|
||||||
*/
|
*/
|
||||||
public boolean searchCache(String streamUrl) {
|
public boolean searchCacheByURL(String streamUrl) {
|
||||||
boolean retValue = false;
|
boolean retValue = false;
|
||||||
try {
|
try {
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
|
@ -568,62 +554,73 @@ public class DBController {
|
||||||
*/
|
*/
|
||||||
public void readCache(String streamUrl) {
|
public void readCache(String streamUrl) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Statement stmt = connection.createStatement();
|
Statement stmt = connection.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery("SELECT * FROM cache WHERE streamUrl=\"" + streamUrl + "\";");
|
ResultSet rs = stmt.executeQuery("SELECT * FROM cache WHERE streamUrl=\"" + streamUrl + "\";");
|
||||||
|
Font font = Font.font("System", FontWeight.BOLD, (int) Math.round(mainWindowController.getFontSize()));
|
||||||
|
ObservableList<Node> textFlow = mainWindowController.getTextFlow().getChildren();
|
||||||
ArrayList<Text> nameText = new ArrayList<Text>();
|
ArrayList<Text> nameText = new ArrayList<Text>();
|
||||||
ArrayList<Text> responseText = new ArrayList<Text>();
|
|
||||||
Image im;
|
|
||||||
int fontSize = (int) Math.round(mainWindowController.getFontSize());
|
|
||||||
int j = 2;
|
|
||||||
|
|
||||||
nameText.add(0, new Text(mainWindowController.getBundle().getString("title") + ": "));
|
|
||||||
nameText.add(1, new Text(mainWindowController.getBundle().getString("year") + ": "));
|
|
||||||
nameText.add(2, new Text(mainWindowController.getBundle().getString("rating") + ": "));
|
|
||||||
nameText.add(3, new Text(mainWindowController.getBundle().getString("publishedOn") + ": "));
|
|
||||||
nameText.add(4, new Text(mainWindowController.getBundle().getString("duration") + ": "));
|
|
||||||
nameText.add(5, new Text(mainWindowController.getBundle().getString("genre") + ": "));
|
|
||||||
nameText.add(6, new Text(mainWindowController.getBundle().getString("director") + ": "));
|
|
||||||
nameText.add(7, new Text(mainWindowController.getBundle().getString("writer") + ": "));
|
|
||||||
nameText.add(8, new Text(mainWindowController.getBundle().getString("actors") + ": "));
|
|
||||||
nameText.add(9, new Text(mainWindowController.getBundle().getString("plot") + ": "));
|
|
||||||
nameText.add(10, new Text(mainWindowController.getBundle().getString("language") + ": "));
|
|
||||||
nameText.add(11, new Text(mainWindowController.getBundle().getString("country") + ": "));
|
|
||||||
nameText.add(12, new Text(mainWindowController.getBundle().getString("awards") + ": "));
|
|
||||||
nameText.add(13, new Text(mainWindowController.getBundle().getString("metascore") + ": "));
|
|
||||||
nameText.add(14, new Text(mainWindowController.getBundle().getString("imdbRating") + ": "));
|
|
||||||
nameText.add(15, new Text(mainWindowController.getBundle().getString("type") + ": "));
|
|
||||||
|
|
||||||
for (int i = 0; i < 15; i++) {
|
nameText.add(new Text(mainWindowController.getBundle().getString("title") + ": "));
|
||||||
responseText.add(new Text(rs.getString(j) + "\n"));
|
nameText.add(new Text(mainWindowController.getBundle().getString("year") + ": "));
|
||||||
j++;
|
nameText.add(new Text(mainWindowController.getBundle().getString("rated") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("released") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("season") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("episode") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("runtime") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("genre") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("director") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("writer") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("actors") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("plot") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("language") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("country") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("awards") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("metascore") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("imdbRating") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("type") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("boxOffice") + ": "));
|
||||||
|
nameText.add(new Text(mainWindowController.getBundle().getString("website") + ": "));
|
||||||
|
|
||||||
|
// set the correct font for the nameText
|
||||||
|
for (Text text : nameText) {
|
||||||
|
text.setFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
responseText.add(new Text(rs.getString(19) + "\n"));
|
// clear the textFlow and all the new text
|
||||||
im = new Image(new File(rs.getString(20)).toURI().toString());
|
textFlow.clear();
|
||||||
|
textFlow.addAll(nameText.get(0), new Text(rs.getString("Title") + "\n"));
|
||||||
stmt.close();
|
textFlow.addAll(nameText.get(1), new Text(rs.getString("Year") + "\n"));
|
||||||
rs.close();
|
textFlow.addAll(nameText.get(2), new Text(rs.getString("Rated") + "\n"));
|
||||||
|
textFlow.addAll(nameText.get(3), new Text(rs.getString("Released") + "\n"));
|
||||||
for (int i = 0; i < nameText.size(); i++) {
|
textFlow.addAll(nameText.get(4), new Text(rs.getString("Season") + "\n"));
|
||||||
nameText.get(i).setFont(Font.font("System", FontWeight.BOLD, fontSize));
|
textFlow.addAll(nameText.get(5), new Text(rs.getString("Episode") + "\n"));
|
||||||
responseText.get(i).setFont(Font.font("System", fontSize));
|
textFlow.addAll(nameText.get(6), new Text(rs.getString("Runtime") + "\n"));
|
||||||
}
|
textFlow.addAll(nameText.get(7), new Text(rs.getString("Genre") + "\n"));
|
||||||
|
textFlow.addAll(nameText.get(8), new Text(rs.getString("Director") + "\n"));
|
||||||
mainWindowController.getTextFlow().getChildren().remove(0,
|
textFlow.addAll(nameText.get(9), new Text(rs.getString("Writer") + "\n"));
|
||||||
mainWindowController.getTextFlow().getChildren().size());
|
textFlow.addAll(nameText.get(10), new Text(rs.getString("Actors") + "\n"));
|
||||||
|
textFlow.addAll(nameText.get(11), new Text(rs.getString("Plot") + "\n"));
|
||||||
for (int i = 0; i < nameText.size(); i++) {
|
textFlow.addAll(nameText.get(12), new Text(rs.getString("Language") + "\n"));
|
||||||
mainWindowController.getTextFlow().getChildren().addAll(nameText.get(i), responseText.get(i));
|
textFlow.addAll(nameText.get(13), new Text(rs.getString("Country") + "\n"));
|
||||||
}
|
textFlow.addAll(nameText.get(14), new Text(rs.getString("Awards") + "\n"));
|
||||||
|
textFlow.addAll(nameText.get(15), new Text(rs.getString("metascore") + "\n"));
|
||||||
|
textFlow.addAll(nameText.get(16), new Text(rs.getString("imdbRating") + "\n"));
|
||||||
|
textFlow.addAll(nameText.get(17), new Text(rs.getString("Type") + "\n"));
|
||||||
|
textFlow.addAll(nameText.get(18), new Text(rs.getString("BoxOffice") + "\n"));
|
||||||
|
textFlow.addAll(nameText.get(19), new Text(rs.getString("Website") + "\n"));
|
||||||
|
|
||||||
|
mainWindowController.getTextFlow().setStyle("-fx-font-size : " + ((int) Math.round(mainWindowController.getFontSize()) + 1) + "px;");
|
||||||
|
|
||||||
|
// add the image
|
||||||
try {
|
try {
|
||||||
mainWindowController.getPosterImageView().setImage(im);
|
mainWindowController.getPosterImageView().setImage(new Image(new File(rs.getString("Poster")).toURI().toString()));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mainWindowController.getPosterImageView().setImage(new Image("resources/icons/close_black_2048x2048.png"));
|
mainWindowController.getPosterImageView().setImage(new Image("resources/icons/close_black_2048x2048.png"));
|
||||||
LOGGER.error(e);
|
LOGGER.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stmt.close();
|
||||||
|
rs.close();
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
LOGGER.error("Ups! an error occured!", e);
|
LOGGER.error("Ups! an error occured!", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,13 +39,13 @@ import com.eclipsesource.json.JsonValue;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import kellerkinder.HomeFlix.application.Main;
|
import kellerkinder.HomeFlix.application.Main;
|
||||||
import kellerkinder.HomeFlix.application.MainWindowController;
|
import kellerkinder.HomeFlix.application.MainWindowController;
|
||||||
|
import kellerkinder.HomeFlix.datatypes.OMDbAPIResponseDataType;
|
||||||
|
|
||||||
public class OMDbAPIController implements Runnable {
|
public class OMDbAPIController implements Runnable {
|
||||||
|
|
||||||
private MainWindowController mainWindowController;
|
private MainWindowController mainWindowController;
|
||||||
private DBController dbController;
|
private DBController dbController;
|
||||||
private Main main;
|
private Main main;
|
||||||
private String[] responseString = new String[20];
|
|
||||||
private String URL = "https://www.omdbapi.com/?apikey=";
|
private String URL = "https://www.omdbapi.com/?apikey=";
|
||||||
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
|
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
|
||||||
|
|
||||||
|
@ -65,106 +65,125 @@ public class OMDbAPIController implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
String output = null;
|
JsonObject object;
|
||||||
String posterPath = null;
|
object = getByTitle(mainWindowController.getCurrentTitle());
|
||||||
|
if (object == null) return;
|
||||||
|
|
||||||
// get information by title
|
if (object.getString("Error", "").contains("not found!")) {
|
||||||
try {
|
String title = searchByTitle(mainWindowController.getCurrentTitle());
|
||||||
URL apiUrl = new URL(URL + mainWindowController.getOmdbAPIKey() + "&t="
|
if (title.length() > 0) {
|
||||||
+ mainWindowController.getCurrentTitle().replace(" ", "%20"));
|
object = getByTitle(title);
|
||||||
BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream()));
|
|
||||||
output = ina.readLine();
|
|
||||||
ina.close();
|
|
||||||
System.out.println(apiUrl);
|
|
||||||
LOGGER.info("response from '" + URL + "&t=" + mainWindowController.getCurrentTitle() + "' was:" + output);
|
|
||||||
} catch (IOException e) {
|
|
||||||
LOGGER.error("error while making api request or reading response");
|
|
||||||
LOGGER.error("response from '" + URL + "&t=" + mainWindowController.getCurrentTitle() + "' was:" + output, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject object = Json.parse(output).asObject();
|
|
||||||
|
|
||||||
if (object.getString("Error", "").equals("Movie not found!")) {
|
|
||||||
// if the movie was not found try to search it
|
|
||||||
LOGGER.warn("Movie was not found at first try, searching again!");
|
|
||||||
/** TODO
|
|
||||||
* split the name intelligent as it may contain the film title
|
|
||||||
* search for English name
|
|
||||||
* use tmdb
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
URL apiUrl = new URL(URL + mainWindowController.getOmdbAPIKey() + "&s="
|
|
||||||
+ mainWindowController.getCurrentTitle().replace(" ", "%20"));
|
|
||||||
BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream()));
|
|
||||||
output = ina.readLine();
|
|
||||||
ina.close();
|
|
||||||
LOGGER.info("response from '" + URL + "&s=" + mainWindowController.getCurrentTitle() + "' was:" + output);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error("error while making api request or reading response");
|
|
||||||
LOGGER.error("response from '" + URL + "&s=" + mainWindowController.getCurrentTitle() + "' was:" + output, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
JsonObject searchObject = Json.parse(output).asObject();
|
|
||||||
if (searchObject.getString("Response", "").equals("True")) {
|
|
||||||
for (JsonValue movie : searchObject.get("Search").asArray()) {
|
|
||||||
// get first entry from the array and set object = movie
|
|
||||||
object = (JsonObject) movie;
|
|
||||||
System.out.println(movie.toString());
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
System.out.println(object.getString("Title", ""));
|
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("Movie not found! Not adding cache!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add the response to the responseString[]
|
OMDbAPIResponseDataType omdbResponse = new OMDbAPIResponseDataType();
|
||||||
responseString[0] = object.getString("Title", "");
|
omdbResponse.setTitle(object.getString("Title", ""));
|
||||||
responseString[1] = object.getString("Year", "");
|
omdbResponse.setYear(object.getString("Year", ""));
|
||||||
responseString[2] = object.getString("Rated", "");
|
omdbResponse.setRated(object.getString("Rated", ""));
|
||||||
responseString[3] = object.getString("Released", "");
|
omdbResponse.setReleased(object.getString("Release", ""));
|
||||||
responseString[4] = object.getString("Runtime", "");
|
omdbResponse.setSeason(object.getString("Season", ""));
|
||||||
responseString[5] = object.getString("Genre", "");
|
omdbResponse.setEpisode(object.getString("Episode", ""));
|
||||||
responseString[6] = object.getString("Director", "");
|
omdbResponse.setRuntime(object.getString("Runtime", ""));
|
||||||
responseString[7] = object.getString("Writer", "");
|
omdbResponse.setGenre(object.getString("Genre", ""));
|
||||||
responseString[8] = object.getString("Actors", "");
|
omdbResponse.setDirector(object.getString("Director", ""));
|
||||||
responseString[9] = object.getString("Plot", "");
|
omdbResponse.setWriter(object.getString("Writer", ""));
|
||||||
responseString[10] = object.getString("Language", "");
|
omdbResponse.setActors(object.getString("Actors", ""));
|
||||||
responseString[11] = object.getString("Country", "");
|
omdbResponse.setPlot(object.getString("Plot", ""));
|
||||||
responseString[12] = object.getString("Awards", "");
|
omdbResponse.setLanguage(object.getString("Language", ""));
|
||||||
responseString[13] = object.getString("Metascore", "");
|
omdbResponse.setCountry(object.getString("Country", ""));
|
||||||
responseString[14] = object.getString("imdbRating", "");
|
omdbResponse.setAwards(object.getString("Awards", ""));
|
||||||
responseString[15] = object.getString("Type", "");
|
omdbResponse.setMetascore(object.getString("Metascore", ""));
|
||||||
responseString[16] = object.getString("imdbVotes", "");
|
omdbResponse.setImdbRating(object.getString("imdbRating", ""));
|
||||||
responseString[17] = object.getString("imdbID", "");
|
omdbResponse.setImdbVotes(object.getString("imdbVotes", ""));
|
||||||
responseString[18] = object.getString("Poster", "");
|
omdbResponse.setImdbID(object.getString("imdbID", ""));
|
||||||
responseString[19] = object.getString("Response", "");
|
omdbResponse.setType(object.getString("Type", ""));
|
||||||
|
omdbResponse.setDvd(object.getString("DVD", ""));
|
||||||
//resize the image to fit in the posterImageView and add it to the cache
|
omdbResponse.setBoxOffice(object.getString("BoxOffice", ""));
|
||||||
try {
|
omdbResponse.setProduction(object.getString("Production", ""));
|
||||||
BufferedImage originalImage = ImageIO.read(new URL(responseString[18])); //change path to where file is located
|
omdbResponse.setWebsite(object.getString("Website", ""));
|
||||||
posterPath = main.getPosterCache() + "/" + mainWindowController.getCurrentTitle() + ".png";
|
omdbResponse.setResponse(object.getString("Response", ""));
|
||||||
ImageIO.write(originalImage, "png", new File(posterPath));
|
|
||||||
LOGGER.info("adding poster to cache: "+posterPath);
|
// 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(main.getPosterCache() + "/" + mainWindowController.getCurrentTitle() + ".png");
|
||||||
|
ImageIO.write(originalImage, "png", new File(omdbResponse.getPoster()));
|
||||||
|
LOGGER.info("adding poster to cache: " + omdbResponse.getPoster());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e);
|
LOGGER.error(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// adding strings to the cache
|
// adding to cache
|
||||||
dbController.addCache(mainWindowController.getCurrentStreamUrl(), responseString[0], responseString[1],
|
dbController.addCache(mainWindowController.getCurrentStreamUrl(), omdbResponse);
|
||||||
responseString[2], responseString[3], responseString[4], responseString[5], responseString[6],
|
|
||||||
responseString[7], responseString[8], responseString[9], responseString[10], responseString[11],
|
|
||||||
responseString[12], responseString[13], responseString[14], responseString[15], responseString[16],
|
|
||||||
responseString[17], posterPath, responseString[19]);
|
|
||||||
dbController.setCached(mainWindowController.getCurrentStreamUrl());
|
dbController.setCached(mainWindowController.getCurrentStreamUrl());
|
||||||
|
|
||||||
// load data to the MainWindowController
|
// load data to the MainWindowController
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
dbController.readCache(mainWindowController.getCurrentStreamUrl());
|
dbController.readCache(mainWindowController.getCurrentStreamUrl());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonObject getByTitle(String title) {
|
||||||
|
String output = null;
|
||||||
|
URL apiUrl;
|
||||||
|
try {
|
||||||
|
if (mainWindowController.getCurrentTableFilm().getSeason().length() > 0) {
|
||||||
|
apiUrl = new URL(URL + mainWindowController.getOmdbAPIKey() + "&t="
|
||||||
|
+ title.replace(" ", "%20")
|
||||||
|
+ "&Season=" + mainWindowController.getCurrentTableFilm().getSeason()
|
||||||
|
+ "&Episode=" + mainWindowController.getCurrentTableFilm().getEpisode());
|
||||||
|
} else {
|
||||||
|
apiUrl = new URL(URL + mainWindowController.getOmdbAPIKey() + "&t="
|
||||||
|
+ title.replace(" ", "%20"));
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream()));
|
||||||
|
output = ina.readLine();
|
||||||
|
ina.close();
|
||||||
|
LOGGER.info("response from '" + URL + "&t=" + title + "' was:" + output);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("error while making api request or reading response");
|
||||||
|
LOGGER.error("response from '" + URL + "&t=" + title + "' was:" + output, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Json.parse(output).asObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String searchByTitle(String title) {
|
||||||
|
String output = null;
|
||||||
|
// if the movie was not found try to search it
|
||||||
|
LOGGER.warn("Movie was not found at first try, searching again!");
|
||||||
|
/**
|
||||||
|
* TODO split the name intelligent as it may contain the film title search for
|
||||||
|
* English name use tmdb
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
URL apiUrl = new URL(URL + mainWindowController.getOmdbAPIKey() + "&s=" + title.replace(" ", "%20"));
|
||||||
|
BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream()));
|
||||||
|
output = ina.readLine();
|
||||||
|
ina.close();
|
||||||
|
LOGGER.info("response from '" + URL + "&s=" + title + "' was:" + output);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error("error while making api request or reading response");
|
||||||
|
LOGGER.error("response from '" + URL + "&s=" + title + "' was:" + output, e);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonObject searchObject = Json.parse(output).asObject();
|
||||||
|
if (searchObject.getString("Response", "").equals("True")) {
|
||||||
|
for (JsonValue movie : searchObject.get("Search").asArray()) {
|
||||||
|
// get first entry from the array and set object = movie
|
||||||
|
return movie.asObject().getString("Title", "");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("Movie not found! Not adding cache!");
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,267 @@
|
||||||
|
/**
|
||||||
|
* Project-HomeFlix
|
||||||
|
*
|
||||||
|
* Copyright 2018 <@Seil0>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301, USA.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package kellerkinder.HomeFlix.datatypes;
|
||||||
|
|
||||||
|
public class OMDbAPIResponseDataType {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private String year;
|
||||||
|
private String rated;
|
||||||
|
private String released;
|
||||||
|
private String season;
|
||||||
|
private String episode;
|
||||||
|
private String runtime;
|
||||||
|
private String genre;
|
||||||
|
private String director;
|
||||||
|
private String writer;
|
||||||
|
private String actors;
|
||||||
|
private String plot;
|
||||||
|
private String language;
|
||||||
|
private String country;
|
||||||
|
private String awards;
|
||||||
|
private String poster;
|
||||||
|
private String metascore;
|
||||||
|
private String imdbRating;
|
||||||
|
private String imdbVotes;
|
||||||
|
private String imdbID;
|
||||||
|
private String type;
|
||||||
|
private String dvd;
|
||||||
|
private String boxOffice;
|
||||||
|
private String production;
|
||||||
|
private String website;
|
||||||
|
private String response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OMDbAPIResponseDataType is the data-type for the omdbAPI response
|
||||||
|
*/
|
||||||
|
public OMDbAPIResponseDataType() {
|
||||||
|
// Auto-generated constructor stub
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setYear(String year) {
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRated() {
|
||||||
|
return rated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRated(String rated) {
|
||||||
|
this.rated = rated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReleased() {
|
||||||
|
return released;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReleased(String released) {
|
||||||
|
this.released = released;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSeason() {
|
||||||
|
return season;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSeason(String season) {
|
||||||
|
this.season = season;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEpisode() {
|
||||||
|
return episode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEpisode(String episode) {
|
||||||
|
this.episode = episode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRuntime() {
|
||||||
|
return runtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRuntime(String runtime) {
|
||||||
|
this.runtime = runtime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGenre() {
|
||||||
|
return genre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGenre(String genre) {
|
||||||
|
this.genre = genre;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDirector() {
|
||||||
|
return director;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDirector(String director) {
|
||||||
|
this.director = director;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWriter() {
|
||||||
|
return writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWriter(String writer) {
|
||||||
|
this.writer = writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getActors() {
|
||||||
|
return actors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActors(String actors) {
|
||||||
|
this.actors = actors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlot() {
|
||||||
|
return plot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlot(String plot) {
|
||||||
|
this.plot = plot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanguage(String language) {
|
||||||
|
this.language = language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCountry() {
|
||||||
|
return country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCountry(String country) {
|
||||||
|
this.country = country;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAwards() {
|
||||||
|
return awards;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAwards(String awards) {
|
||||||
|
this.awards = awards;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPoster() {
|
||||||
|
return poster;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPoster(String poster) {
|
||||||
|
this.poster = poster;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMetascore() {
|
||||||
|
return metascore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetascore(String metascore) {
|
||||||
|
this.metascore = metascore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImdbRating() {
|
||||||
|
return imdbRating;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImdbRating(String imdbRating) {
|
||||||
|
this.imdbRating = imdbRating;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImdbVotes() {
|
||||||
|
return imdbVotes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImdbVotes(String imdbVotes) {
|
||||||
|
this.imdbVotes = imdbVotes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImdbID() {
|
||||||
|
return imdbID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImdbID(String imdbID) {
|
||||||
|
this.imdbID = imdbID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDvd() {
|
||||||
|
return dvd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDvd(String dvd) {
|
||||||
|
this.dvd = dvd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBoxOffice() {
|
||||||
|
return boxOffice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBoxOffice(String boxOffice) {
|
||||||
|
this.boxOffice = boxOffice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProduction() {
|
||||||
|
return production;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProduction(String production) {
|
||||||
|
this.production = production;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWebsite() {
|
||||||
|
return website;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWebsite(String website) {
|
||||||
|
this.website = website;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResponse() {
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResponse(String response) {
|
||||||
|
this.response = response;
|
||||||
|
}
|
||||||
|
}
|
|
@ -37,9 +37,11 @@ infoText = \nAutoren: \n \u2022 seil0@kellerkinder.xyz \n \u2022 hendrik.schutte
|
||||||
#textFlow translations
|
#textFlow translations
|
||||||
title = Titel
|
title = Titel
|
||||||
year = Jahr
|
year = Jahr
|
||||||
rating = Einstufung
|
rated = Einstufung
|
||||||
publishedOn = Ver\u00F6ffentlicht am
|
released = Ver\u00F6ffentlicht am
|
||||||
duration = Laufzeit
|
season = Staffel
|
||||||
|
episode = Episode
|
||||||
|
runtime = Laufzeit
|
||||||
genre = Gener
|
genre = Gener
|
||||||
director = Regisseur
|
director = Regisseur
|
||||||
writer = Autor
|
writer = Autor
|
||||||
|
@ -51,6 +53,8 @@ awards = Auszeichnungen
|
||||||
metascore = Metascore
|
metascore = Metascore
|
||||||
imdbRating = IMDB-Bewertung
|
imdbRating = IMDB-Bewertung
|
||||||
type = Type
|
type = Type
|
||||||
|
boxOffice = BoxOffice
|
||||||
|
website = Webseite
|
||||||
|
|
||||||
#first start
|
#first start
|
||||||
addSourceHeader = Neue Quelle hinzuf\u00FCgen
|
addSourceHeader = Neue Quelle hinzuf\u00FCgen
|
||||||
|
|
|
@ -37,9 +37,11 @@ infoText = \nMaintainers: \n \u2022 seil0@kellerkinder.xyz \n \u2022 hendrik.sch
|
||||||
#textFlow translations
|
#textFlow translations
|
||||||
title = Title
|
title = Title
|
||||||
year = Year
|
year = Year
|
||||||
rating = Rating
|
rated = Rating
|
||||||
publishedOn = published on
|
released = published on
|
||||||
duration = Duration
|
season = Season
|
||||||
|
episode = Episode
|
||||||
|
runtime = Duration
|
||||||
genre = Gener
|
genre = Gener
|
||||||
director = Director
|
director = Director
|
||||||
writer = Writer
|
writer = Writer
|
||||||
|
@ -51,6 +53,8 @@ awards = Awards
|
||||||
metascore = Metascore
|
metascore = Metascore
|
||||||
imdbRating = IMDB-Rating
|
imdbRating = IMDB-Rating
|
||||||
type = Type
|
type = Type
|
||||||
|
boxOffice = BoxOffice
|
||||||
|
website = Website
|
||||||
|
|
||||||
#first start
|
#first start
|
||||||
addSourceHeader = add a new source
|
addSourceHeader = add a new source
|
||||||
|
|
Loading…
Reference in New Issue