Browse Source

removed the usage of mwc in omdbAPIQuery

pull/12/head
Jannik 4 years ago
parent
commit
a1319382ff
  1. 17
      src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java
  2. 40
      src/main/java/kellerkinder/HomeFlix/controller/OMDbAPIController.java

17
src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java

@ -155,7 +155,6 @@ public class MainWindowController {
private Main main;
private MainWindowController mainWindowController;
private UpdateController updateController;
private OMDbAPIController omdbAPIController;
private DBController dbController;
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
@ -166,7 +165,7 @@ public class MainWindowController {
private boolean autoplay = false;
private final String version = "0.7.0";
private final String buildNumber = "157";
private final String buildNumber = "159";
private final String versionName = "toothless dragon";
private String btnStyle;
private String color;
@ -198,8 +197,7 @@ public class MainWindowController {
public MainWindowController(Main main) {
this.main = main;
mainWindowController = this;
dbController = new DBController(this.main, this);
omdbAPIController = new OMDbAPIController(this, dbController, this.main);
dbController = new DBController(this.main, this);
}
@FXML
@ -440,11 +438,10 @@ public class MainWindowController {
if (currentTableFilm.getCached() || dbController.searchCacheByURL(getCurrentStreamUrl())) {
LOGGER.info("loading from cache: " + getCurrentTitle());
dbController.readCache(getCurrentStreamUrl());
} else {
omdbAPIController = new OMDbAPIController(mainWindowController, dbController, main);
Thread omdbAPIThread = new Thread(omdbAPIController);
} else {
Thread omdbAPIThread = new Thread(new OMDbAPIController(main, dbController, currentTableFilm, omdbAPIKey));
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 for entries not available show homeflix logo
}
// Thread omdbAPIThread = new Thread(new OMDbAPIController(main, dbController, currentTableFilm, omdbAPIKey));
// omdbAPIThread.setName("OMDbAPI");
// omdbAPIThread.start();
}

40
src/main/java/kellerkinder/HomeFlix/controller/OMDbAPIController.java

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

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close