@ -22,16 +22,12 @@
package kellerkinder.HomeFlix.application ;
import java.awt.Desktop ;
import java.io.BufferedReader ;
import java.io.File ;
import java.io.FileReader ;
import java.io.FileWriter ;
import java.io.IOException ;
import java.io.InputStreamReader ;
import java.io.Writer ;
import java.math.BigInteger ;
import java.net.URLConnection ;
import java.time.LocalDate ;
import java.util.Locale ;
import java.util.ResourceBundle ;
@ -73,7 +69,6 @@ import kellerkinder.HomeFlix.controller.UpdateController;
import kellerkinder.HomeFlix.controller.XMLController ;
import kellerkinder.HomeFlix.datatypes.FilmTabelDataType ;
import kellerkinder.HomeFlix.datatypes.PosterModeElement ;
import kellerkinder.HomeFlix.player.Player ;
public class MainWindowController {
@ -109,8 +104,6 @@ public class MainWindowController {
private String btnStyle ;
private FilmTabelDataType currentTableFilm = new FilmTabelDataType ( "" , "" , "" , "" , false , null ) ;
private ObservableList < PosterModeElement > posterEmenents = FXCollections . observableArrayList ( ) ;
private LocalDate lastValidCache = LocalDate . now ( ) . minusDays ( 30 ) ; // current date - 30 days is the last valid cache date
@ -184,59 +177,6 @@ public class MainWindowController {
primaryStage . setMinWidth ( 1130 . 00 ) ;
}
// Table-Mode fxml actions
@FXML
private void playbtnclicked ( ) {
if ( currentTableFilm . getStreamUrl ( ) . length ( ) > 0 ) {
if ( currentTableFilm . getStreamUrl ( ) . contains ( "_rootNode" ) ) {
LOGGER . info ( "rootNode found, getting last watched episode" ) ;
currentTableFilm = dbController . getLastWatchedEpisode ( currentTableFilm . getTitle ( ) ) ;
}
if ( isSupportedFormat ( currentTableFilm ) ) {
new Player ( currentTableFilm . getStreamUrl ( ) ) ;
} else {
LOGGER . error ( "using fallback player!" ) ;
if ( System . getProperty ( "os.name" ) . contains ( "Linux" ) ) {
String line ;
String output = "" ;
Process p ;
try {
p = Runtime . getRuntime ( ) . exec ( "which vlc" ) ;
BufferedReader input = new BufferedReader ( new InputStreamReader ( p . getInputStream ( ) ) ) ;
while ( ( line = input . readLine ( ) ) ! = null ) {
output = line ;
}
LOGGER . info ( "which vlc: " + output ) ;
input . close ( ) ;
} catch ( IOException e1 ) {
e1 . printStackTrace ( ) ;
}
if ( output . contains ( "which: no vlc" ) | | output = = "" ) {
JFXInfoAlert vlcInfoAlert = new JFXInfoAlert ( "Info" ,
XMLController . getLocalBundle ( ) . getString ( "vlcNotInstalled" ) , btnStyle , primaryStage ) ;
vlcInfoAlert . showAndWait ( ) ;
} else {
try {
new ProcessBuilder ( "vlc" , currentTableFilm . getStreamUrl ( ) ) . start ( ) ;
} catch ( IOException e ) {
LOGGER . warn ( "An error has occurred while opening the file!" , e ) ;
}
}
} else if ( System . getProperty ( "os.name" ) . contains ( "Windows" ) | | System . getProperty ( "os.name" ) . contains ( "Mac OS X" ) ) {
try {
Desktop . getDesktop ( ) . open ( new File ( currentTableFilm . getStreamUrl ( ) ) ) ;
} catch ( IOException e ) {
LOGGER . warn ( "An error has occurred while opening the file!" , e ) ;
}
} else {
LOGGER . error ( System . getProperty ( "os.name" ) + ", OS is not supported, please contact a developer! " ) ;
}
}
}
}
// general fxml actions
@FXML
private void aboutBtnAction ( ) {
@ -272,6 +212,7 @@ public class MainWindowController {
if ( selectedFolder ! = null & & selectedFolder . exists ( ) ) {
selectFirstSource . getAlert ( ) . close ( ) ;
writeSource ( selectedFolder . getPath ( ) , "local" ) ;
settingsViewController . loadInitSources ( ) ;
} else {
LOGGER . error ( "The selected folder dosen't exist!" ) ;
System . exit ( 1 ) ;
@ -286,6 +227,7 @@ public class MainWindowController {
if ( selectedFile ! = null & & selectedFile . exists ( ) ) {
selectFirstSource . getAlert ( ) . close ( ) ;
writeSource ( selectedFile . getPath ( ) , "stream" ) ;
settingsViewController . loadInitSources ( ) ;
} else {
LOGGER . error ( "The selected file dosen't exist!" ) ;
System . exit ( 1 ) ;
@ -411,20 +353,9 @@ public class MainWindowController {
}
}
/ * *
* check if a film is supported by the HomeFlixPlayer or not this is the case if
* the mime type is mp4
*
* @param entry the film you want to check
* @return true if so , false if not
* /
private boolean isSupportedFormat ( FilmTabelDataType film ) {
String mimeType = URLConnection . guessContentTypeFromName ( film . getStreamUrl ( ) ) ;
return mimeType ! = null & & ( mimeType . contains ( "mp4" ) | | mimeType . contains ( "vp6" ) ) ;
}
/ * *
* Poser Mode WIP
* Poser Mode
* /
private void posterModeStartup ( ) {
@ -437,13 +368,15 @@ public class MainWindowController {
* check if all posters are cached , if not cache the missing ones
* /
void checkAllPosters ( ) {
dbController . refreshDataBase ( ) ; // refreshes the database after a source path was added
// get all not cached entries, none of them should have a cached poster
ExecutorService executor = Executors . newFixedThreadPool ( 5 ) ;
for ( FilmTabelDataType entry : dbController . getAllNotCachedEntries ( ) ) {
System . out . println ( entry . getStreamUrl ( ) + " is NOT cached!" ) ;
Runnable OMDbAPIWorker = new OMDbAPIController ( entry , XMLController . getOmdbAPIKey ( ) ) ;
Runnable OMDbAPIWorker = new OMDbAPIController ( entry ) ;
executor . execute ( OMDbAPIWorker ) ;
}
executor . shutdown ( ) ;
@ -456,9 +389,7 @@ public class MainWindowController {
} catch ( InterruptedException e ) {
LOGGER . error ( e ) ;
}
// update all elements from the database
dbController . refreshDataBase ( ) ; // refreshes the database after a source path was added
System . out . println ( "finished refresh" ) ;
}
@ -502,7 +433,7 @@ public class MainWindowController {
for ( FilmTabelDataType entry : dbController . getStreamsList ( ) ) {
if ( dbController . getCacheDate ( entry . getStreamUrl ( ) ) . isBefore ( lastValidCache ) ) {
System . out . println ( entry . getTitle ( ) + " chached on: " + dbController . getCacheDate ( entry . getStreamUrl ( ) ) ) ;
Runnable OMDbAPIWorker = new OMDbAPIController ( entry , XMLController . getOmdbAPIKey ( ) ) ;
Runnable OMDbAPIWorker = new OMDbAPIController ( entry ) ;
executor . execute ( OMDbAPIWorker ) ;
}
}