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:
		@ -215,7 +215,7 @@ public class MainWindowController {
 | 
			
		||||
	private boolean autoplay = false;
 | 
			
		||||
 | 
			
		||||
	private final String version = "0.7.0";
 | 
			
		||||
	private final String buildNumber = "151";
 | 
			
		||||
	private final String buildNumber = "155";
 | 
			
		||||
	private final String versionName = "toothless dragon";
 | 
			
		||||
	private String btnStyle;
 | 
			
		||||
	private String color;
 | 
			
		||||
@ -482,7 +482,7 @@ public class MainWindowController {
 | 
			
		||||
				last = indexTable - 1;
 | 
			
		||||
				next = indexTable + 1;
 | 
			
		||||
				
 | 
			
		||||
				if (currentTableFilm.getCached() || dbController.searchCache(getCurrentStreamUrl())) {
 | 
			
		||||
				if (currentTableFilm.getCached() || dbController.searchCacheByURL(getCurrentStreamUrl())) {
 | 
			
		||||
					LOGGER.info("loading from cache: " + getCurrentTitle());
 | 
			
		||||
					dbController.readCache(getCurrentStreamUrl());
 | 
			
		||||
				} else {			
 | 
			
		||||
 | 
			
		||||
@ -42,6 +42,8 @@ import com.eclipsesource.json.JsonArray;
 | 
			
		||||
import com.eclipsesource.json.JsonObject;
 | 
			
		||||
import com.eclipsesource.json.JsonValue;
 | 
			
		||||
 | 
			
		||||
import javafx.collections.ObservableList;
 | 
			
		||||
import javafx.scene.Node;
 | 
			
		||||
import javafx.scene.image.Image;
 | 
			
		||||
import javafx.scene.image.ImageView;
 | 
			
		||||
import javafx.scene.text.Font;
 | 
			
		||||
@ -51,6 +53,7 @@ import kellerkinder.HomeFlix.application.Main;
 | 
			
		||||
import kellerkinder.HomeFlix.application.MainWindowController;
 | 
			
		||||
import kellerkinder.HomeFlix.datatypes.SourceDataType;
 | 
			
		||||
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType;
 | 
			
		||||
import kellerkinder.HomeFlix.datatypes.OMDbAPIResponseDataType;
 | 
			
		||||
 | 
			
		||||
public class DBController {
 | 
			
		||||
	
 | 
			
		||||
@ -117,9 +120,9 @@ public class DBController {
 | 
			
		||||
			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 cache ("
 | 
			
		||||
					+ "streamUrl, Title, Year, Rated, Released, Runtime, Genre, Director, Writer,"
 | 
			
		||||
					+ " Actors, Plot, Language, Country, Awards, Metascore, imdbRating, imdbVotes,"
 | 
			
		||||
					+ " imdbID, Type, Poster, Response)");
 | 
			
		||||
					+ "streamUrl, Title, Year, Rated, Released, Season, Episode ,Runtime, Genre, Director, Writer,"
 | 
			
		||||
					+ " Actors, Plot, Language, Country, Awards, Poster, Metascore, imdbRating, imdbVotes,"
 | 
			
		||||
					+ " imdbID, Type, dvd, BoxOffice, Website, Response)");
 | 
			
		||||
			stmt.close();
 | 
			
		||||
		} catch (SQLException e) {
 | 
			
		||||
			LOGGER.error(e);
 | 
			
		||||
@ -481,62 +484,45 @@ public class DBController {
 | 
			
		||||
	
 | 
			
		||||
	/**
 | 
			
		||||
	 * add the received data to the cache table
 | 
			
		||||
	 * @param streamUrl URL of the film
 | 
			
		||||
	 * @param Title
 | 
			
		||||
	 * @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
 | 
			
		||||
	 * @param streamUrl 	URL of the film
 | 
			
		||||
	 * @param omdbResponse	the response data from omdbAPI
 | 
			
		||||
	 */
 | 
			
		||||
	void addCache(	String streamUrl, String Title, String Year, String Rated, String Released, String Runtime, String Genre, String Director,
 | 
			
		||||
					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) {
 | 
			
		||||
	void addCache(String streamUrl, OMDbAPIResponseDataType omdbResponse) {
 | 
			
		||||
		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(2,Title);
 | 
			
		||||
			ps.setString(3,Year);
 | 
			
		||||
			ps.setString(4,Rated);
 | 
			
		||||
			ps.setString(5,Released);
 | 
			
		||||
			ps.setString(6,Runtime);
 | 
			
		||||
			ps.setString(7,Genre);
 | 
			
		||||
			ps.setString(8,Director);
 | 
			
		||||
			ps.setString(9,Writer);
 | 
			
		||||
			ps.setString(10,Actors);
 | 
			
		||||
			ps.setString(11,Plot);
 | 
			
		||||
			ps.setString(12,Language);
 | 
			
		||||
			ps.setString(13,Country);
 | 
			
		||||
			ps.setString(14,Awards);
 | 
			
		||||
			ps.setString(15,Metascore);
 | 
			
		||||
			ps.setString(16,imdbRating);
 | 
			
		||||
			ps.setString(17,imdbVotes);
 | 
			
		||||
			ps.setString(18,imdbID);
 | 
			
		||||
			ps.setString(19,Type);
 | 
			
		||||
			ps.setString(20,Poster);
 | 
			
		||||
			ps.setString(21,Response);
 | 
			
		||||
			ps.setString(2,omdbResponse.getTitle());
 | 
			
		||||
			ps.setString(3,omdbResponse.getYear());
 | 
			
		||||
			ps.setString(4,omdbResponse.getRated());
 | 
			
		||||
			ps.setString(5,omdbResponse.getReleased());
 | 
			
		||||
			ps.setString(6,omdbResponse.getSeason());
 | 
			
		||||
			ps.setString(7,omdbResponse.getEpisode());
 | 
			
		||||
			ps.setString(8,omdbResponse.getRuntime());
 | 
			
		||||
			ps.setString(9,omdbResponse.getGenre());
 | 
			
		||||
			ps.setString(10,omdbResponse.getDirector());
 | 
			
		||||
			ps.setString(11,omdbResponse.getWriter());
 | 
			
		||||
			ps.setString(12,omdbResponse.getActors());
 | 
			
		||||
			ps.setString(13,omdbResponse.getPlot());
 | 
			
		||||
			ps.setString(14,omdbResponse.getLanguage());
 | 
			
		||||
			ps.setString(15,omdbResponse.getCountry());
 | 
			
		||||
			ps.setString(16,omdbResponse.getAwards());
 | 
			
		||||
			ps.setString(17,omdbResponse.getPoster());
 | 
			
		||||
			ps.setString(18,omdbResponse.getMetascore());
 | 
			
		||||
			ps.setString(19,omdbResponse.getImdbRating());
 | 
			
		||||
			ps.setString(20,omdbResponse.getImdbVotes());
 | 
			
		||||
			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.executeBatch();			
 | 
			
		||||
			connection.commit();
 | 
			
		||||
			ps.close();
 | 
			
		||||
			LOGGER.info("done!");
 | 
			
		||||
		} catch (Exception e) {
 | 
			
		||||
			LOGGER.error(e);
 | 
			
		||||
		}
 | 
			
		||||
@ -547,7 +533,7 @@ public class DBController {
 | 
			
		||||
	 * @param streamUrl URL of the element
 | 
			
		||||
	 * @return true if the element is already cached, else false
 | 
			
		||||
	 */
 | 
			
		||||
	public boolean searchCache(String streamUrl) {
 | 
			
		||||
	public boolean searchCacheByURL(String streamUrl) {
 | 
			
		||||
		boolean retValue = false;
 | 
			
		||||
		try {
 | 
			
		||||
			Statement stmt = connection.createStatement();
 | 
			
		||||
@ -568,62 +554,73 @@ public class DBController {
 | 
			
		||||
	 */
 | 
			
		||||
	public void readCache(String streamUrl) {
 | 
			
		||||
		try {
 | 
			
		||||
			
 | 
			
		||||
			Statement stmt = connection.createStatement();
 | 
			
		||||
			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> 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") + ": "));
 | 
			
		||||
			nameText.add(new Text(mainWindowController.getBundle().getString("title") + ": "));
 | 
			
		||||
			nameText.add(new Text(mainWindowController.getBundle().getString("year") + ": "));
 | 
			
		||||
			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") + ": "));
 | 
			
		||||
			
 | 
			
		||||
			for (int i = 0; i < 15; i++) {
 | 
			
		||||
				responseText.add(new Text(rs.getString(j) + "\n"));
 | 
			
		||||
				j++;
 | 
			
		||||
			// set the correct font for the  nameText
 | 
			
		||||
			for (Text text : nameText) {
 | 
			
		||||
				text.setFont(font);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			responseText.add(new Text(rs.getString(19) + "\n"));
 | 
			
		||||
			im = new Image(new File(rs.getString(20)).toURI().toString());
 | 
			
		||||
			// clear the textFlow and all the new text
 | 
			
		||||
			textFlow.clear();
 | 
			
		||||
			textFlow.addAll(nameText.get(0), new Text(rs.getString("Title") + "\n"));
 | 
			
		||||
			textFlow.addAll(nameText.get(1), new Text(rs.getString("Year") + "\n"));
 | 
			
		||||
			textFlow.addAll(nameText.get(2), new Text(rs.getString("Rated") + "\n"));
 | 
			
		||||
			textFlow.addAll(nameText.get(3), new Text(rs.getString("Released") + "\n"));
 | 
			
		||||
			textFlow.addAll(nameText.get(4), new Text(rs.getString("Season") + "\n"));
 | 
			
		||||
			textFlow.addAll(nameText.get(5), new Text(rs.getString("Episode") + "\n"));
 | 
			
		||||
			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"));
 | 
			
		||||
			textFlow.addAll(nameText.get(9), new Text(rs.getString("Writer") + "\n"));
 | 
			
		||||
			textFlow.addAll(nameText.get(10), new Text(rs.getString("Actors") + "\n"));
 | 
			
		||||
			textFlow.addAll(nameText.get(11), new Text(rs.getString("Plot") + "\n"));
 | 
			
		||||
			textFlow.addAll(nameText.get(12), new Text(rs.getString("Language") + "\n"));
 | 
			
		||||
			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"));
 | 
			
		||||
			
 | 
			
		||||
			stmt.close();
 | 
			
		||||
			rs.close();
 | 
			
		||||
 | 
			
		||||
			for (int i = 0; i < nameText.size(); i++) {
 | 
			
		||||
				nameText.get(i).setFont(Font.font("System", FontWeight.BOLD, fontSize));
 | 
			
		||||
				responseText.get(i).setFont(Font.font("System", fontSize));
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			mainWindowController.getTextFlow().getChildren().remove(0,
 | 
			
		||||
					mainWindowController.getTextFlow().getChildren().size());
 | 
			
		||||
 | 
			
		||||
			for (int i = 0; i < nameText.size(); i++) {
 | 
			
		||||
				mainWindowController.getTextFlow().getChildren().addAll(nameText.get(i), responseText.get(i));
 | 
			
		||||
			}
 | 
			
		||||
			mainWindowController.getTextFlow().setStyle("-fx-font-size : " + ((int) Math.round(mainWindowController.getFontSize()) + 1) + "px;");
 | 
			
		||||
			
 | 
			
		||||
			// add the image
 | 
			
		||||
			try {
 | 
			
		||||
				mainWindowController.getPosterImageView().setImage(im);
 | 
			
		||||
				mainWindowController.getPosterImageView().setImage(new Image(new File(rs.getString("Poster")).toURI().toString()));
 | 
			
		||||
			} catch (Exception e) {
 | 
			
		||||
				mainWindowController.getPosterImageView().setImage(new Image("resources/icons/close_black_2048x2048.png"));
 | 
			
		||||
				LOGGER.error(e);
 | 
			
		||||
			}
 | 
			
		||||
			
 | 
			
		||||
			stmt.close();
 | 
			
		||||
			rs.close();
 | 
			
		||||
		} catch (SQLException e) {
 | 
			
		||||
			LOGGER.error("Ups! an error occured!", e);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -39,13 +39,13 @@ import com.eclipsesource.json.JsonValue;
 | 
			
		||||
import javafx.application.Platform;
 | 
			
		||||
import kellerkinder.HomeFlix.application.Main;
 | 
			
		||||
import kellerkinder.HomeFlix.application.MainWindowController;
 | 
			
		||||
import kellerkinder.HomeFlix.datatypes.OMDbAPIResponseDataType;
 | 
			
		||||
 | 
			
		||||
public class OMDbAPIController implements Runnable {
 | 
			
		||||
	
 | 
			
		||||
	private MainWindowController mainWindowController;
 | 
			
		||||
	private DBController dbController;
 | 
			
		||||
	private Main main;
 | 
			
		||||
	private String[] responseString = new String[20];
 | 
			
		||||
	private String URL = "https://www.omdbapi.com/?apikey=";
 | 
			
		||||
	private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
 | 
			
		||||
	
 | 
			
		||||
@ -65,106 +65,125 @@ public class OMDbAPIController implements Runnable {
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void run() {
 | 
			
		||||
    	String output = null;
 | 
			
		||||
    	String posterPath = null;
 | 
			
		||||
		JsonObject object;
 | 
			
		||||
		object = getByTitle(mainWindowController.getCurrentTitle());
 | 
			
		||||
		if (object == null) return;
 | 
			
		||||
		
 | 
			
		||||
		// get information by title
 | 
			
		||||
		try {
 | 
			
		||||
			URL apiUrl = new URL(URL + mainWindowController.getOmdbAPIKey() + "&t="
 | 
			
		||||
					+ mainWindowController.getCurrentTitle().replace(" ", "%20"));
 | 
			
		||||
			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", ""));
 | 
			
		||||
		if (object.getString("Error", "").contains("not found!")) {
 | 
			
		||||
			String title = searchByTitle(mainWindowController.getCurrentTitle());
 | 
			
		||||
			if (title.length() > 0) {
 | 
			
		||||
				object = getByTitle(title);
 | 
			
		||||
			} else {
 | 
			
		||||
				LOGGER.warn("Movie not found! Not adding cache!");
 | 
			
		||||
				return;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// add the response to the responseString[]
 | 
			
		||||
		responseString[0] = object.getString("Title", "");
 | 
			
		||||
		responseString[1] = object.getString("Year", "");
 | 
			
		||||
		responseString[2] = object.getString("Rated", "");
 | 
			
		||||
		responseString[3] = object.getString("Released", "");
 | 
			
		||||
		responseString[4] = object.getString("Runtime", "");
 | 
			
		||||
		responseString[5] = object.getString("Genre", "");
 | 
			
		||||
		responseString[6] = object.getString("Director", "");
 | 
			
		||||
		responseString[7] = object.getString("Writer", "");
 | 
			
		||||
		responseString[8] = object.getString("Actors", "");
 | 
			
		||||
		responseString[9] = object.getString("Plot", "");
 | 
			
		||||
		responseString[10] = object.getString("Language", "");
 | 
			
		||||
		responseString[11] = object.getString("Country", "");
 | 
			
		||||
		responseString[12] = object.getString("Awards", "");
 | 
			
		||||
		responseString[13] = object.getString("Metascore", "");
 | 
			
		||||
		responseString[14] = object.getString("imdbRating", "");
 | 
			
		||||
		responseString[15] = object.getString("Type", "");
 | 
			
		||||
		responseString[16] = object.getString("imdbVotes", "");
 | 
			
		||||
		responseString[17] = object.getString("imdbID", "");
 | 
			
		||||
		responseString[18] = object.getString("Poster", "");
 | 
			
		||||
		responseString[19] = object.getString("Response", "");
 | 
			
		||||
		OMDbAPIResponseDataType omdbResponse = new OMDbAPIResponseDataType();
 | 
			
		||||
		omdbResponse.setTitle(object.getString("Title", ""));
 | 
			
		||||
		omdbResponse.setYear(object.getString("Year", ""));
 | 
			
		||||
		omdbResponse.setRated(object.getString("Rated", ""));
 | 
			
		||||
		omdbResponse.setReleased(object.getString("Release", ""));
 | 
			
		||||
		omdbResponse.setSeason(object.getString("Season", ""));
 | 
			
		||||
		omdbResponse.setEpisode(object.getString("Episode", ""));
 | 
			
		||||
		omdbResponse.setRuntime(object.getString("Runtime", ""));
 | 
			
		||||
		omdbResponse.setGenre(object.getString("Genre", ""));
 | 
			
		||||
		omdbResponse.setDirector(object.getString("Director", ""));
 | 
			
		||||
		omdbResponse.setWriter(object.getString("Writer", ""));
 | 
			
		||||
		omdbResponse.setActors(object.getString("Actors", ""));
 | 
			
		||||
		omdbResponse.setPlot(object.getString("Plot", ""));
 | 
			
		||||
		omdbResponse.setLanguage(object.getString("Language", ""));
 | 
			
		||||
		omdbResponse.setCountry(object.getString("Country", ""));
 | 
			
		||||
		omdbResponse.setAwards(object.getString("Awards", ""));
 | 
			
		||||
		omdbResponse.setMetascore(object.getString("Metascore", ""));
 | 
			
		||||
		omdbResponse.setImdbRating(object.getString("imdbRating", ""));
 | 
			
		||||
		omdbResponse.setImdbVotes(object.getString("imdbVotes", ""));
 | 
			
		||||
		omdbResponse.setImdbID(object.getString("imdbID", ""));
 | 
			
		||||
		omdbResponse.setType(object.getString("Type", ""));
 | 
			
		||||
		omdbResponse.setDvd(object.getString("DVD", ""));
 | 
			
		||||
		omdbResponse.setBoxOffice(object.getString("BoxOffice", ""));
 | 
			
		||||
		omdbResponse.setProduction(object.getString("Production", ""));
 | 
			
		||||
		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(responseString[18])); //change path to where file is located
 | 
			
		||||
		    posterPath = main.getPosterCache() + "/" + mainWindowController.getCurrentTitle() + ".png";
 | 
			
		||||
			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) {
 | 
			
		||||
			LOGGER.error(e);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// adding strings to the cache
 | 
			
		||||
		dbController.addCache(mainWindowController.getCurrentStreamUrl(), responseString[0], responseString[1],
 | 
			
		||||
				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]);
 | 
			
		||||
		// adding to cache
 | 
			
		||||
		dbController.addCache(mainWindowController.getCurrentStreamUrl(), omdbResponse);
 | 
			
		||||
		dbController.setCached(mainWindowController.getCurrentStreamUrl());
 | 
			
		||||
		
 | 
			
		||||
		// load data to the MainWindowController
 | 
			
		||||
		Platform.runLater(() -> {
 | 
			
		||||
			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
 | 
			
		||||
title = Titel
 | 
			
		||||
year = Jahr
 | 
			
		||||
rating = Einstufung
 | 
			
		||||
publishedOn = Ver\u00F6ffentlicht am
 | 
			
		||||
duration = Laufzeit
 | 
			
		||||
rated = Einstufung
 | 
			
		||||
released = Ver\u00F6ffentlicht am
 | 
			
		||||
season = Staffel
 | 
			
		||||
episode = Episode
 | 
			
		||||
runtime = Laufzeit
 | 
			
		||||
genre = Gener
 | 
			
		||||
director = Regisseur
 | 
			
		||||
writer = Autor
 | 
			
		||||
@ -51,6 +53,8 @@ awards = Auszeichnungen
 | 
			
		||||
metascore = Metascore
 | 
			
		||||
imdbRating = IMDB-Bewertung
 | 
			
		||||
type = Type
 | 
			
		||||
boxOffice = BoxOffice
 | 
			
		||||
website = Webseite
 | 
			
		||||
 | 
			
		||||
#first start
 | 
			
		||||
addSourceHeader = Neue Quelle hinzuf\u00FCgen
 | 
			
		||||
 | 
			
		||||
@ -37,9 +37,11 @@ infoText = \nMaintainers: \n \u2022 seil0@kellerkinder.xyz \n \u2022 hendrik.sch
 | 
			
		||||
#textFlow translations
 | 
			
		||||
title = Title
 | 
			
		||||
year = Year
 | 
			
		||||
rating = Rating
 | 
			
		||||
publishedOn = published on
 | 
			
		||||
duration = Duration
 | 
			
		||||
rated = Rating
 | 
			
		||||
released = published on
 | 
			
		||||
season = Season
 | 
			
		||||
episode = Episode
 | 
			
		||||
runtime = Duration
 | 
			
		||||
genre = Gener
 | 
			
		||||
director = Director
 | 
			
		||||
writer = Writer
 | 
			
		||||
@ -51,6 +53,8 @@ awards = Awards
 | 
			
		||||
metascore = Metascore
 | 
			
		||||
imdbRating = IMDB-Rating
 | 
			
		||||
type = Type
 | 
			
		||||
boxOffice = BoxOffice
 | 
			
		||||
website = Website
 | 
			
		||||
 | 
			
		||||
#first start
 | 
			
		||||
addSourceHeader = add a new source
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user