removed the usage of mwc in omdbAPIQuery

This commit is contained in:
Jannik 2018-10-01 21:12:53 +02:00
parent a491937b30
commit a1319382ff
2 changed files with 31 additions and 26 deletions

View File

@ -155,7 +155,6 @@ public class MainWindowController {
private Main main; private Main main;
private MainWindowController mainWindowController; private MainWindowController mainWindowController;
private UpdateController updateController; private UpdateController updateController;
private OMDbAPIController omdbAPIController;
private DBController dbController; private DBController dbController;
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName()); private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
@ -166,7 +165,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 = "157"; private final String buildNumber = "159";
private final String versionName = "toothless dragon"; private final String versionName = "toothless dragon";
private String btnStyle; private String btnStyle;
private String color; private String color;
@ -198,8 +197,7 @@ public class MainWindowController {
public MainWindowController(Main main) { public MainWindowController(Main main) {
this.main = main; this.main = main;
mainWindowController = this; mainWindowController = this;
dbController = new DBController(this.main, this); dbController = new DBController(this.main, this);
omdbAPIController = new OMDbAPIController(this, dbController, this.main);
} }
@FXML @FXML
@ -440,11 +438,10 @@ public class MainWindowController {
if (currentTableFilm.getCached() || dbController.searchCacheByURL(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 {
omdbAPIController = new OMDbAPIController(mainWindowController, dbController, main); Thread omdbAPIThread = new Thread(new OMDbAPIController(main, dbController, currentTableFilm, omdbAPIKey));
Thread omdbAPIThread = new Thread(omdbAPIController);
omdbAPIThread.setName("OMDbAPI"); omdbAPIThread.setName("OMDbAPI");
omdbAPIThread.start(); omdbAPIThread.start();
} }
} }
}); });
@ -818,6 +815,10 @@ public class MainWindowController {
// TODO get all needed posters eg cache all not cached entries // TODO get all needed posters eg cache all not cached entries
// TODO for entries not available show homeflix logo // TODO for entries not available show homeflix logo
} }
// Thread omdbAPIThread = new Thread(new OMDbAPIController(main, dbController, currentTableFilm, omdbAPIKey));
// omdbAPIThread.setName("OMDbAPI");
// omdbAPIThread.start();
} }

View File

@ -39,38 +39,42 @@ 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.FilmTabelDataType;
import kellerkinder.HomeFlix.datatypes.OMDbAPIResponseDataType; import kellerkinder.HomeFlix.datatypes.OMDbAPIResponseDataType;
public class OMDbAPIController implements Runnable { public class OMDbAPIController implements Runnable {
private MainWindowController mainWindowController;
private DBController dbController;
private Main main; private Main main;
private DBController dbController;
private FilmTabelDataType currentTableFilm;
private String omdbAPIKey;
private String URL = "https://www.omdbapi.com/?apikey="; private String URL = "https://www.omdbapi.com/?apikey=";
private boolean useEpisode = true; private boolean useEpisode = true;
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName()); private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
/** /**
* constructor for the OMDbAPIController * constructor for the OMDbAPIController
* @param mainWindowController the MainWindowController object
* @param dbController the DBController object
* @param main the Main object * @param main the Main object
* @param dbController the DBController object
* @param currentTableFilm the current film object
* @param omdbAPIKey the omdbAPI key
*/ */
public OMDbAPIController(MainWindowController mainWindowController, DBController dbController, Main main){ public OMDbAPIController(Main main, DBController dbController, FilmTabelDataType currentTableFilm, String omdbAPIKey) {
this.mainWindowController = mainWindowController;
this.dbController = dbController;
this.main = main; this.main = main;
this.dbController = dbController;
this.currentTableFilm = currentTableFilm;
this.omdbAPIKey = omdbAPIKey;
} }
@Override @Override
public void run() { public void run() {
LOGGER.info("Querying omdbAPI ..."); LOGGER.info("Querying omdbAPI ...");
JsonObject object; JsonObject object;
object = getByTitle(mainWindowController.getCurrentTitle()); object = getByTitle(currentTableFilm.getTitle());
if (object == null) return; if (object == null) return;
if (object.getString("Error", "").contains("not found!")) { if (object.getString("Error", "").contains("not found!")) {
String title = searchByTitle(mainWindowController.getCurrentTitle()); String title = searchByTitle(currentTableFilm.getTitle());
if (title.length() > 0) { if (title.length() > 0) {
object = getByTitle(title); object = getByTitle(title);
@ -122,12 +126,12 @@ public class OMDbAPIController implements Runnable {
} }
// adding to cache // adding to cache
dbController.addCache(mainWindowController.getCurrentStreamUrl(), omdbResponse); dbController.addCache(currentTableFilm.getStreamUrl(), omdbResponse);
dbController.setCached(mainWindowController.getCurrentStreamUrl()); dbController.setCached(currentTableFilm.getStreamUrl());
// load data to the MainWindowController // load data to the MainWindowController
Platform.runLater(() -> { Platform.runLater(() -> {
dbController.readCache(mainWindowController.getCurrentStreamUrl()); dbController.readCache(currentTableFilm.getStreamUrl());
}); });
return; return;
@ -142,13 +146,13 @@ public class OMDbAPIController implements Runnable {
String output = null; String output = null;
URL apiUrl; URL apiUrl;
try { try {
if (mainWindowController.getCurrentTableFilm().getSeason().length() > 0 && useEpisode) { if (currentTableFilm.getSeason().length() > 0 && useEpisode) {
apiUrl = new URL(URL + mainWindowController.getOmdbAPIKey() + "&t=" apiUrl = new URL(URL + omdbAPIKey + "&t="
+ title.replace(" ", "%20") + title.replace(" ", "%20")
+ "&Season=" + mainWindowController.getCurrentTableFilm().getSeason() + "&Season=" + currentTableFilm.getSeason()
+ "&Episode=" + mainWindowController.getCurrentTableFilm().getEpisode()); + "&Episode=" + currentTableFilm.getEpisode());
} else { } else {
apiUrl = new URL(URL + mainWindowController.getOmdbAPIKey() + "&t=" apiUrl = new URL(URL + omdbAPIKey + "&t="
+ title.replace(" ", "%20")); + title.replace(" ", "%20"));
} }
@ -179,7 +183,7 @@ public class OMDbAPIController implements Runnable {
* English name use tmdb * English name use tmdb
*/ */
try { try {
URL apiUrl = new URL(URL + mainWindowController.getOmdbAPIKey() + "&s=" + title.replace(" ", "%20")); URL apiUrl = new URL(URL + omdbAPIKey + "&s=" + title.replace(" ", "%20"));
BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream())); BufferedReader ina = new BufferedReader(new InputStreamReader(apiUrl.openStream()));
output = ina.readLine(); output = ina.readLine();
ina.close(); ina.close();