@ -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 . getCurren tTitle ( ) ) ;
object = getByTitle ( currentTableFilm . getTitle ( ) ) ;
if ( object = = null ) return ;
if ( object . getString ( "Error" , "" ) . contains ( "not found!" ) ) {
String title = searchByTitle ( mainWindowController . getCurren tTitle ( ) ) ;
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 . getCurren tStreamUrl ( ) , omdbResponse ) ;
dbController . setCached ( mainWindowController . getCurren tStreamUrl ( ) ) ;
dbController . addCache ( currentTableFilm . getStreamUrl ( ) , omdbResponse ) ;
dbController . setCached ( currentTableFilm . getStreamUrl ( ) ) ;
// load data to the MainWindowController
Platform . runLater ( ( ) - > {
dbController . readCache ( mainWindowController . getCurren tStreamUrl ( ) ) ;
dbController . readCache ( currentTableFilm . getStreamUrl ( ) ) ;
} ) ;
return ;
@ -142,13 +146,13 @@ public class OMDbAPIController implements Runnable {
String output = null ;
URL apiUrl ;
try {
if ( mainWindowController . getC urrentTableFilm( ) . getSeason ( ) . length ( ) > 0 & & useEpisode ) {
apiUrl = new URL ( URL + mainWind owController . getO mdbAPIKey( ) + "&t="
if ( c urrentTableFilm. getSeason ( ) . length ( ) > 0 & & useEpisode ) {
apiUrl = new URL ( URL + omdbAPIKey + "&t="
+ title . replace ( " " , "%20" )
+ "&Season=" + mainWindowController . getC urrentTableFilm( ) . getSeason ( )
+ "&Episode=" + mainWindowController . getC urrentTableFilm( ) . getEpisode ( ) ) ;
+ "&Season=" + c urrentTableFilm. getSeason ( )
+ "&Episode=" + c urrentTableFilm. getEpisode ( ) ) ;
} else {
apiUrl = new URL ( URL + mainWind owController . getO mdbAPIKey( ) + "&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 + mainWind owController . getO mdbAPIKey( ) + "&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 ( ) ;