The HMOClient package is designed to encapsulize interaction from Java with an
HMO server such as a Tivo (containing Video items) or another computer serving
images and music.
Video items are not documented in the HMO specification but have been implemented
by observation of results.
Example of processing against a TiVo:
try {
// Do a whole bunch of junk to make an https connection to the
// TiVo with a specific login/password, an invalid/unknown
// hostname (just IP), and an untrusted certificate signer.
Authenticator.setDefault( new MyAuthenticator("tivo",mediaKey) );
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; }
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
{ }
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
{ }
} };
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
SSLSocketFactory socketFactory = sc.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);
if(HttpsURLConnection.getDefaultSSLSocketFactory() !=socketFactory) {
throw new Exception("UNABLE TO SET SSLSocketFactory!");
}
MyHostVerifier mhv = new MyHostVerifier();
HttpsURLConnection.setDefaultHostnameVerifier( mhv );
if(HttpsURLConnection.getDefaultHostnameVerifier() != mhv) {
throw new Exception("UNABLE TO SET HostnameVerifier!");
}
// authenticator takes care of user/pass
URL url = new URL("https://"+host);
// Set up the HMO session and get the root.
HMOSession hmo = new HMOSession(url);
ContainerRequest req1 = hmo.newRootRequest();
Container root = req1.execute( 0, 1 );
Item rootsChild = (Item)root.getItems().get( 0 );
// make a real request from the root (now playing).
// get the 5 most recently created items check which are in progress
if(rootsChild.isContainer()) {
ContainerRequest req = rootsChild.newContainerRequest();
req.addReverseOrder( ContainerRequest.ORDER_CREATION_DATE );
req.setRecursive( true );
Container first5 = req.execute( 0, 5 );
Throwable loadError = first5.getLoadError();
if(loadError != null) {
if(loadError instanceof Exception) {
throw (Exception)loadError;
} else {
throw new Exception(loadError.getMessage(),loadError);
}
}
List items = first5.getItems();
if(items != null) {
for( Iterator iter = items.iterator() ; iter.hasNext() ; ) {
Object obj = iter.next();
if(obj instanceof VideoItem) {
VideoItem item = (VideoItem)obj;
if(item.isInProgress()) {
...
}
}
}
}
}
} catch(Exception e) {
app.getFactory().log( ILogger.LOG_WARNING, e.toString() );
}