added poster cache
This commit is contained in:
parent
726a788876
commit
cccbca06bd
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -23,7 +23,6 @@ import com.eclipsesource.json.Json;
|
||||||
import com.eclipsesource.json.JsonArray;
|
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.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;
|
||||||
|
@ -518,7 +517,7 @@ public class DBController {
|
||||||
String Type, String imdbVotes, String imdbID, String Poster, String Response) throws SQLException{
|
String Type, String imdbVotes, String imdbID, String Poster, String Response) throws SQLException{
|
||||||
PreparedStatement ps = connection.prepareStatement("insert into cache values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
PreparedStatement ps = connection.prepareStatement("insert into cache values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
|
||||||
|
|
||||||
System.out.println("adding to cache...");
|
System.out.println("adding to cache: " + Title);
|
||||||
ps.setString(1,streamUrl);
|
ps.setString(1,streamUrl);
|
||||||
ps.setString(2,Title);
|
ps.setString(2,Title);
|
||||||
ps.setString(3,Year);
|
ps.setString(3,Year);
|
||||||
|
@ -579,8 +578,8 @@ public class DBController {
|
||||||
responseText.add(new Text(rs.getString(j)+"\n"));
|
responseText.add(new Text(rs.getString(j)+"\n"));
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
responseText.add(new Text(rs.getString(19)+"\n"));
|
responseText.add(new Text(rs.getString(19)+"\n"));
|
||||||
im = new Image(rs.getString(20));
|
im = new Image(new File(rs.getString(20)).toURI().toString());
|
||||||
|
|
||||||
stmt.close();
|
stmt.close();
|
||||||
rs.close();
|
rs.close();
|
||||||
|
@ -596,7 +595,6 @@ public class DBController {
|
||||||
mainWindowController.textFlow.getChildren().addAll(nameText.get(i),responseText.get(i));
|
mainWindowController.textFlow.getChildren().addAll(nameText.get(i),responseText.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO separate cache for posters
|
|
||||||
try{
|
try{
|
||||||
mainWindowController.image1.setImage(im);
|
mainWindowController.image1.setImage(im);
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class Main extends Application {
|
||||||
private MainWindowController mainWindowController;
|
private MainWindowController mainWindowController;
|
||||||
private File directory;
|
private File directory;
|
||||||
private File settingsFile;
|
private File settingsFile;
|
||||||
|
private File posterCache;
|
||||||
private String dirWin = System.getProperty("user.home") + "/Documents/HomeFlix"; //Windows: C:/Users/"User"/Documents/HomeFlix
|
private String dirWin = System.getProperty("user.home") + "/Documents/HomeFlix"; //Windows: C:/Users/"User"/Documents/HomeFlix
|
||||||
private String dirLinux = System.getProperty("user.home") + "/HomeFlix"; //Linux: /home/"User"/HomeFlix
|
private String dirLinux = System.getProperty("user.home") + "/HomeFlix"; //Linux: /home/"User"/HomeFlix
|
||||||
|
|
||||||
|
@ -92,7 +93,9 @@ public class Main extends Application {
|
||||||
settingsFile = new File(dirWin + "/config.xml");
|
settingsFile = new File(dirWin + "/config.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(settingsFile.exists() != true){
|
posterCache = new File(directory+"/posterCache");
|
||||||
|
|
||||||
|
if(!settingsFile.exists()){
|
||||||
directory.mkdir();
|
directory.mkdir();
|
||||||
mainWindowController.setPath(firstStart());
|
mainWindowController.setPath(firstStart());
|
||||||
mainWindowController.setStreamingPath(directory.getAbsolutePath());
|
mainWindowController.setStreamingPath(directory.getAbsolutePath());
|
||||||
|
@ -106,6 +109,9 @@ public class Main extends Application {
|
||||||
System.exit(0); //finishes itse
|
System.exit(0); //finishes itse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!posterCache.exists()) {
|
||||||
|
posterCache.mkdir();
|
||||||
|
}
|
||||||
//TODO remove when tested under Linux
|
//TODO remove when tested under Linux
|
||||||
// if(System.getProperty("os.name").equals("Linux")){
|
// if(System.getProperty("os.name").equals("Linux")){
|
||||||
// if(dirLinux.exists() != true){
|
// if(dirLinux.exists() != true){
|
||||||
|
@ -203,4 +209,12 @@ public class Main extends Application {
|
||||||
public void setFONT_FAMILY(String FONT_FAMILY) {
|
public void setFONT_FAMILY(String FONT_FAMILY) {
|
||||||
this.FONT_FAMILY = FONT_FAMILY;
|
this.FONT_FAMILY = FONT_FAMILY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getPosterCache() {
|
||||||
|
return posterCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosterCache(File posterCache) {
|
||||||
|
this.posterCache = posterCache;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -4,13 +4,18 @@
|
||||||
*/
|
*/
|
||||||
package application;
|
package application;
|
||||||
|
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
import com.eclipsesource.json.Json;
|
import com.eclipsesource.json.Json;
|
||||||
import com.eclipsesource.json.JsonObject;
|
import com.eclipsesource.json.JsonObject;
|
||||||
|
|
||||||
|
@ -32,6 +37,7 @@ public class apiQuery{
|
||||||
private Main main;
|
private Main main;
|
||||||
private Image im;
|
private Image im;
|
||||||
private String[] responseString = new String[20];
|
private String[] responseString = new String[20];
|
||||||
|
private String posterCache;
|
||||||
ArrayList<Text> responseText = new ArrayList<Text>();
|
ArrayList<Text> responseText = new ArrayList<Text>();
|
||||||
ArrayList<Text> nameText = new ArrayList<Text>();
|
ArrayList<Text> nameText = new ArrayList<Text>();
|
||||||
|
|
||||||
|
@ -42,9 +48,11 @@ public class apiQuery{
|
||||||
String moviename = null;
|
String moviename = null;
|
||||||
String dataurl = null;
|
String dataurl = null;
|
||||||
String retdata = null;
|
String retdata = null;
|
||||||
|
String posterPath = null;
|
||||||
InputStream is = null;
|
InputStream is = null;
|
||||||
BufferedReader br = null;
|
BufferedReader br = null;
|
||||||
String fontFamily = main.getFONT_FAMILY();
|
String fontFamily = main.getFONT_FAMILY();
|
||||||
|
posterCache = main.getPosterCache().toString();
|
||||||
int fontSize = (int) Math.round(mainWindowController.size);
|
int fontSize = (int) Math.round(mainWindowController.size);
|
||||||
|
|
||||||
responseText.removeAll(responseText);
|
responseText.removeAll(responseText);
|
||||||
|
@ -101,10 +109,23 @@ public class apiQuery{
|
||||||
responseString[18] = object.getString("Poster", "");
|
responseString[18] = object.getString("Poster", "");
|
||||||
responseString[19] = object.getString("Response", "");
|
responseString[19] = object.getString("Response", "");
|
||||||
|
|
||||||
|
//adding poster to cache
|
||||||
|
BufferedImage originalImage = ImageIO.read(new URL(responseString[18]));//change path to where file is located
|
||||||
|
int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
|
||||||
|
BufferedImage resizeImagePNG = resizeImage(originalImage, type, 198, 297);
|
||||||
|
if(System.getProperty("os.name").equals("Linux")) {
|
||||||
|
posterPath = posterCache+"/"+titel+".png";
|
||||||
|
ImageIO.write(resizeImagePNG, "png", new File(posterCache+"/"+titel+".png")); //change path where you want it saved
|
||||||
|
} else {
|
||||||
|
ImageIO.write(resizeImagePNG, "png", new File(posterCache+"\\"+titel+".png")); //change path where you want it saved
|
||||||
|
posterPath = posterCache+"\\"+titel+".png";
|
||||||
|
}
|
||||||
|
System.out.println("adding poster to cache: "+posterPath);
|
||||||
|
|
||||||
//adding strings to the cache
|
//adding strings to the cache
|
||||||
dbController.addCache( streamUrl, responseString[0], responseString[1],responseString[2], responseString[3], responseString[4], responseString[5],
|
dbController.addCache( streamUrl, 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[6], responseString[7], responseString[8], responseString[9], responseString[10],responseString[11], responseString[12],
|
||||||
responseString[13], responseString[14], responseString[15], responseString[16], responseString[17], responseString[18],
|
responseString[13], responseString[14], responseString[15], responseString[16], responseString[17], posterPath,
|
||||||
responseString[19]);
|
responseString[19]);
|
||||||
dbController.setCached(streamUrl);
|
dbController.setCached(streamUrl);
|
||||||
|
|
||||||
|
@ -181,4 +202,13 @@ public class apiQuery{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static BufferedImage resizeImage(BufferedImage originalImage, int type, int IMG_WIDTH, int IMG_HEIGHT) {
|
||||||
|
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
|
||||||
|
Graphics2D g = resizedImage.createGraphics();
|
||||||
|
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
|
||||||
|
g.dispose();
|
||||||
|
|
||||||
|
return resizedImage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue