small omdbAPI query fixes

This commit is contained in:
Jannik 2018-12-20 13:47:32 +01:00
parent 1d06aaeaa2
commit 29c6b30168
3 changed files with 24 additions and 13 deletions

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();

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;
}

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,6 +133,8 @@ public class OMDbAPIController implements Runnable {
LOGGER.error(e);
}
synchronized (this) {
// adding to cache
dbController.addCache(currentTableFilm.getStreamUrl(), omdbResponse);
dbController.setCached(currentTableFilm.getStreamUrl());
@ -137,6 +145,7 @@ public class OMDbAPIController implements Runnable {
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 "";
}