Browse Source

small omdbAPI query fixes

pull/12/head
Jannik 2 years ago
parent
commit
29c6b30168
3 changed files with 24 additions and 13 deletions
  1. +0
    -2
      src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java
  2. +3
    -1
      src/main/java/kellerkinder/HomeFlix/controller/DBController.java
  3. +21
    -10
      src/main/java/kellerkinder/HomeFlix/controller/OMDbAPIController.java

+ 0
- 2
src/main/java/kellerkinder/HomeFlix/application/MainWindowController.java View File

@ -826,8 +826,6 @@ public class MainWindowController {
Runnable OMDbAPIWorker = new OMDbAPIController(main, dbController, entry, omdbAPIKey, false);
executor.execute(OMDbAPIWorker);
// TODO for entries not available show homeflix logo and set cached
}
executor.shutdown();


+ 3
- 1
src/main/java/kellerkinder/HomeFlix/controller/DBController.java View File

@ -389,7 +389,7 @@ public class DBController {
try {
PreparedStatement ps = connection.prepareStatement("insert into cache values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
LOGGER.info("adding to cache: " + omdbResponse.getTitle());
LOGGER.info("adding cache for: " + streamUrl);
ps.setString(1,streamUrl);
ps.setString(2,omdbResponse.getTitle());
ps.setString(3,omdbResponse.getYear());
@ -550,6 +550,8 @@ public class DBController {
} catch (SQLException e) {
LOGGER.error("An error occured, while getting all NOT cached entries", e);
}
LOGGER.info("There are {} entries not Chached!", notCachedEntries.size());
return notCachedEntries;
}


+ 21
- 10
src/main/java/kellerkinder/HomeFlix/controller/OMDbAPIController.java View File

@ -73,13 +73,19 @@ public class OMDbAPIController implements Runnable {
LOGGER.info("Querying omdbAPI ...");
JsonObject object;
object = getByTitle(currentTableFilm.getTitle());
if (object == null) return;
if (object == null) {
LOGGER.error("Fatal error while querying omdbAPI!");
return;
}
// if the answer contains "not found!" try to search by title
if (object.getString("Error", "").contains("not found!")) {
String title = searchByTitle(currentTableFilm.getTitle());
if (title.length() > 0) {
// we have at least on answer, get info by title now
object = getByTitle(title);
// if we still have nothing found, get info by title without episode
if(object.getString("Error", "").contains("Series or episode not found!")) {
useEpisode = false;
object = getByTitle(title);
@ -127,15 +133,18 @@ public class OMDbAPIController implements Runnable {
LOGGER.error(e);
}
// adding to cache
dbController.addCache(currentTableFilm.getStreamUrl(), omdbResponse);
dbController.setCached(currentTableFilm.getStreamUrl());
// load data to the MainWindowController
if (refresh) {
Platform.runLater(() -> {
dbController.readCache(currentTableFilm.getStreamUrl());
});
synchronized (this) {
// adding to cache
dbController.addCache(currentTableFilm.getStreamUrl(), omdbResponse);
dbController.setCached(currentTableFilm.getStreamUrl());
// load data to the MainWindowController
if (refresh) {
Platform.runLater(() -> {
dbController.readCache(currentTableFilm.getStreamUrl());
});
}
}
return;
@ -206,7 +215,9 @@ public class OMDbAPIController implements Runnable {
return movie.asObject().getString("Title", "");
}
} else {
LOGGER.warn("Movie not found! Not adding cache!");
// TODO set cached 1 and set the HomeFlix logo as picture
// System.out.println("Object is: " + searchObject);
LOGGER.warn("Movie \"{}\" not found! Not adding cache!", title);
}
return "";
}


Loading…
Cancel
Save