Skip to content

Commit

Permalink
issue #235
Browse files Browse the repository at this point in the history
issue #242

upgraded mythtv services api to v1.0.13
  • Loading branch information
Daniel Frey committed Dec 5, 2013
1 parent 0381f2a commit 6244ff0
Show file tree
Hide file tree
Showing 31 changed files with 512 additions and 480 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<org.joda.joda-convert-version>1.2</org.joda.joda-convert-version>
<universal-image-loader-version>1.8.6</universal-image-loader-version>
<commons-io-version>1.3.2</commons-io-version>
<mythtv.service.api-version>1.0.12</mythtv.service.api-version>
<mythtv.service.api-version>1.0.13</mythtv.service.api-version>
</properties>

<url>https://github.com/MythTV-Clients/mythtv-for-android</url>
Expand Down
4 changes: 2 additions & 2 deletions src/org/mythtv/db/dvr/RemoveStreamTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private void removeLiveStreamV25( Integer id ) {
}

org.mythtv.services.api.v026.MythServicesTemplate template = (org.mythtv.services.api.v026.MythServicesTemplate) MythAccessFactory.getServiceTemplateApiByVersion( ApiVersion.v025, mLocationProfile.getUrl() );
template.contentOperations().removeLiveStream( id );
template.contentOperations().removeLiveStream( id, ETagInfo.createEmptyETag() );
}

private void removeLiveStreamV26( Integer id ) {
Expand All @@ -110,7 +110,7 @@ private void removeLiveStreamV26( Integer id ) {
}

org.mythtv.services.api.v026.MythServicesTemplate template = (org.mythtv.services.api.v026.MythServicesTemplate) MythAccessFactory.getServiceTemplateApiByVersion( ApiVersion.v026, mLocationProfile.getUrl() );
template.contentOperations().removeLiveStream( id );
template.contentOperations().removeLiveStream( id, ETagInfo.createEmptyETag() );
}

private void removeLiveStreamV27( Integer id ) {
Expand Down
6 changes: 3 additions & 3 deletions src/org/mythtv/service/channel/v25/ChannelHelperV25.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public boolean process( final Context context, final LocationProfile locationPro
}

// wait a second before downloading the next one (if there are more than one video source)
if( count < videoSourceList.getVideoSources().length - 1 ) {
if( count < videoSourceList.getVideoSources().length - 1 ) {
Log.i( TAG, "process : sleeping " + nap + " ms" );
Thread.sleep( nap );
}
Expand All @@ -158,11 +158,11 @@ public boolean process( final Context context, final LocationProfile locationPro

} catch( Exception e ) {
Log.e( TAG, "process : error", e );

passed = false;
}

Log.v( TAG, "downloadVideoSources : exit" );
Log.v( TAG, "process : exit" );
return passed;
}

Expand Down
193 changes: 73 additions & 120 deletions src/org/mythtv/service/channel/v26/ChannelHelperV26.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ private int load( final Context context, final LocationProfile locationProfile,

Cursor cursor = context.getContentResolver().query( LiveStreamConstants.CONTENT_URI, projection, selection, selectionArgs, null );
if( cursor.moveToFirst() ) {
Log.v( TAG, "save : updating existing liveStream info" );
Log.v( TAG, "load : updating existing liveStream info" );
long id = cursor.getLong( cursor.getColumnIndexOrThrow( LiveStreamConstants.TABLE_NAME + "_" + LiveStreamConstants._ID ) );

context.getContentResolver().update( ContentUris.withAppendedId( LiveStreamConstants.CONTENT_URI, id ), values, null, null );
Expand Down
19 changes: 12 additions & 7 deletions src/org/mythtv/service/content/v26/FileListHelperV26.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,19 @@ private List<String> downloadFiles( final String storageGroupName ) {

List<String> files = null;

ResponseEntity<org.mythtv.services.api.v026.StringList> responseEntity = mMythServicesTemplate.contentOperations().getFileList( storageGroupName, ETagInfo.createEmptyETag() );
ResponseEntity<org.mythtv.services.api.ArrayOfString> responseEntity = mMythServicesTemplate.contentOperations().getFileList( storageGroupName, ETagInfo.createEmptyETag() );

if( responseEntity.getStatusCode().equals( HttpStatus.OK ) ) {

org.mythtv.services.api.v026.StringList fileList = responseEntity.getBody();
org.mythtv.services.api.ArrayOfString fileList = responseEntity.getBody();

if( null != fileList.getStringList() && fileList.getStringList().length > 0 ) {
files = load( fileList );
if( null != fileList ) {

if( null != fileList.getValue() && fileList.getValue().length > 0 ) {

files = load( fileList.getValue() );
}

}

}
Expand All @@ -132,14 +137,14 @@ private List<String> downloadFiles( final String storageGroupName ) {
return files;
}

private List<String> load( org.mythtv.services.api.v026.StringList versionFiles ) {
private List<String> load( String[] versionFiles ) {
Log.v( TAG, "load : enter" );

List<String> files = new ArrayList<String>();

if( null != versionFiles ) {
if( null != versionFiles && versionFiles.length > 0 ) {

for( String versionFile : versionFiles.getStringList() ) {
for( String versionFile : versionFiles ) {

files.add( versionFile );

Expand Down
92 changes: 45 additions & 47 deletions src/org/mythtv/service/content/v26/LiveStreamHelperV26.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@
import org.mythtv.client.ui.preferences.PlaybackProfile;
import org.mythtv.db.AbstractBaseHelper;
import org.mythtv.db.content.LiveStreamConstants;
import org.mythtv.db.content.model.LiveStreamInfoWrapper;
import org.mythtv.db.http.model.EtagInfoDelegate;
import org.mythtv.db.preferences.PlaybackProfileDaoHelper;
import org.mythtv.service.content.LiveStreamService;
import org.mythtv.service.dvr.v26.RecordedHelperV26;
import org.mythtv.service.util.NetworkHelper;
import org.mythtv.services.api.ApiVersion;
import org.mythtv.services.api.Bool;
import org.mythtv.services.api.ETagInfo;
import org.mythtv.services.api.connect.MythAccessFactory;
import org.mythtv.services.api.v026.Bool;
import org.mythtv.services.api.v026.MythServicesTemplate;
import org.mythtv.services.api.v026.beans.LiveStreamInfo;
import org.mythtv.services.api.v026.beans.LiveStreamInfoList;
import org.mythtv.services.api.v026.beans.LiveStreamInfoWrapper;
import org.mythtv.services.api.v026.beans.Program;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -129,13 +130,14 @@ public boolean create( final Context context, final LocationProfile locationProf
Program program = RecordedHelperV26.getInstance().findRecorded( context, locationProfile, channelId, startTime );

if( null != program ) {
ResponseEntity<LiveStreamInfoWrapper> wrapper = mMythServicesTemplate.contentOperations().
addLiveStream( program.getRecording().getStorageGroup(), program.getFilename(), program.getHostname(), -1, -1,
ResponseEntity<LiveStreamInfo> wrapper = mMythServicesTemplate.contentOperations().
addLiveStream( program.getRecording().getStorageGroup(), program.getFileName(), program.getHostName(), null, null,
selectedPlaybackProfile.getHeight(), selectedPlaybackProfile.getVideoBitrate(),
selectedPlaybackProfile.getAudioBitrate(), selectedPlaybackProfile.getAudioSampleRate() );
selectedPlaybackProfile.getAudioBitrate(), selectedPlaybackProfile.getAudioSampleRate(),
ETagInfo.createEmptyETag() );

if( wrapper.getStatusCode().equals( HttpStatus.OK ) ) {
LiveStreamInfo liveStreamInfo = wrapper.getBody().getLiveStreamInfo();
LiveStreamInfo liveStreamInfo = wrapper.getBody();

save( context, locationProfile, liveStreamInfo, channelId, startTime );

Expand Down Expand Up @@ -177,27 +179,16 @@ public Integer load( final Context context, final LocationProfile locationProfil

ResponseEntity<LiveStreamInfoList> wrapper = mMythServicesTemplate.contentOperations().getLiveStreamList( EtagInfoDelegate.createEmptyETag() );
if( wrapper.getStatusCode().equals( HttpStatus.OK ) ) {

if( null != wrapper.getBody() ) {

if( null != wrapper.getBody().getLiveStreamInfos() ) {

if( null != wrapper.getBody().getLiveStreamInfos().getLiveStreamInfos() && !wrapper.getBody().getLiveStreamInfos().getLiveStreamInfos().isEmpty() ) {

List<LiveStreamInfo> liveStreams = wrapper.getBody().getLiveStreamInfos().getLiveStreamInfos();
loaded = load( context, locationProfile, liveStreams );

}

}

LiveStreamInfo[] liveStreams = wrapper.getBody().getLiveStreamInfos();

if( null != liveStreams && liveStreams.length > 0 ) {
loaded = load( context, locationProfile, liveStreams );
}

Log.v( TAG, "update : exit" );
return loaded;
}

Log.v( TAG, "update : exit" );
return loaded;

} catch( Exception e ) {
Log.e( TAG, "update : error", e );
}
Expand All @@ -206,7 +197,7 @@ public Integer load( final Context context, final LocationProfile locationProfil
return loaded;
}

public boolean update( final Context context, final LocationProfile locationProfile, final long liveStreamId, final int channelId, DateTime startTime ) {
public boolean update( final Context context, final LocationProfile locationProfile, final long liveStreamId, final Integer channelId, final DateTime startTime ) {
Log.v( TAG, "update : enter" );

if( !NetworkHelper.getInstance().isMasterBackendConnected( context, locationProfile ) ) {
Expand All @@ -221,16 +212,16 @@ public boolean update( final Context context, final LocationProfile locationProf

return false;
}

try {

LiveStreamInfo liveStream = findLiveStream( context, locationProfile, liveStreamId );
if( null != liveStream ) {
Log.v( TAG, "update : liveStream=" + liveStream.toString() );

ResponseEntity<LiveStreamInfoWrapper> wrapper = mMythServicesTemplate.contentOperations().getLiveStream( liveStream.getId(), EtagInfoDelegate.createEmptyETag() );
ResponseEntity<LiveStreamInfo> wrapper = mMythServicesTemplate.contentOperations().getLiveStream( liveStream.getId(), EtagInfoDelegate.createEmptyETag() );
if( wrapper.getStatusCode().equals( HttpStatus.OK ) ) {
LiveStreamInfo updated = wrapper.getBody().getLiveStreamInfo();
LiveStreamInfo updated = wrapper.getBody();

if( !"Unknown status value".equalsIgnoreCase( updated.getStatusStr() ) ) {
save( context, locationProfile, updated, channelId, startTime );
Expand Down Expand Up @@ -263,7 +254,7 @@ public boolean remove( final Context context, final LocationProfile locationProf

MythServicesTemplate mMythServicesTemplate = (MythServicesTemplate) MythAccessFactory.getServiceTemplateApiByVersion( mApiVersion, locationProfile.getUrl() );
if( null == mMythServicesTemplate ) {
Log.w( TAG, "rempve : Master Backend '" + locationProfile.getHostname() + "' is unreachable" );
Log.w( TAG, "remove : Master Backend '" + locationProfile.getHostname() + "' is unreachable" );

return false;
}
Expand All @@ -272,25 +263,32 @@ public boolean remove( final Context context, final LocationProfile locationProf
Program program = RecordedHelperV26.getInstance().findRecorded( context, locationProfile, channelId, startTime );

if( null != program ) {
Log.v( TAG, "remove : program found" );

LiveStreamInfo liveStream = findLiveStream( context, locationProfile, channelId, startTime );
if( null != liveStream ) {
Log.v( TAG, "remove : program has live stream" );

ResponseEntity<Bool> wrapper = mMythServicesTemplate.contentOperations().removeLiveStream( liveStream.getId() );
if( wrapper.getStatusCode().equals( HttpStatus.OK ) ) {

Bool bool = wrapper.getBody();
if( bool.getBool() == Boolean.TRUE ) {

boolean removed = deleteLiveStreamByLiveStreamId( context, locationProfile, liveStream.getId() );
if( removed ) {
Log.v( TAG, "remove : exit" );
ResponseEntity<Bool> wrapper = mMythServicesTemplate.contentOperations().removeLiveStream( liveStream.getId(), ETagInfo.createEmptyETag() );
if( wrapper.getStatusCode().equals( HttpStatus.OK ) ) {

Bool bool = wrapper.getBody();
if( bool.getValue() ) {
Log.v( TAG, "remove : live stream removed on backend" );

boolean removed = deleteLiveStreamByLiveStreamId( context, locationProfile, liveStream.getId() );
if( removed ) {
Log.v( TAG, "remove : exit" );

return true;
}

return true;
}

}

}

}

} catch( Exception e ) {
Expand Down Expand Up @@ -352,7 +350,7 @@ public boolean deleteLiveStream( final Context context, final Long id ) {
Log.d( TAG, "deleteLiveStream : enter" );

if( null == context )
throw new RuntimeException( "LiveStreamHelperV27 is not initialized" );
throw new RuntimeException( "LiveStreamHelperV26 is not initialized" );

int deleted = context.getContentResolver().delete( ContentUris.withAppendedId( LiveStreamConstants.CONTENT_URI, id ), null, null );
if( deleted == 1 ) {
Expand Down Expand Up @@ -416,7 +414,7 @@ private Integer countLiveStreamsNotComplete( final Context context, final Locati
return null != count ? count : 0;
}

private int load( final Context context, final LocationProfile locationProfile, List<LiveStreamInfo> liveStreams ) throws RemoteException, OperationApplicationException {
private int load( final Context context, final LocationProfile locationProfile, LiveStreamInfo[] liveStreams ) throws RemoteException, OperationApplicationException {
Log.d( TAG, "load : enter" );

if( null == context ) {
Expand Down Expand Up @@ -662,8 +660,8 @@ private LiveStreamInfo convertCursorToLiveStreamInfo( Cursor cursor ) {
liveStreamInfo.setPercentComplete( percentComplete );
liveStreamInfo.setCreated( created );
liveStreamInfo.setLastModified( lastModified );
liveStreamInfo.setRelativeUrl( relativeUrl );
liveStreamInfo.setFullUrl( fullUrl );
liveStreamInfo.setRelativeURL( relativeUrl );
liveStreamInfo.setFullURL( fullUrl );
liveStreamInfo.setStatusStr( statusStr );
liveStreamInfo.setStatusInt( statusInt );
liveStreamInfo.setStatusMessage( statusMessage );
Expand Down Expand Up @@ -694,8 +692,8 @@ private ContentValues convertLiveStreamInfoToContentValues( final LocationProfil
values.put( LiveStreamConstants.FIELD_PERCENT_COMPLETE, liveStreamInfo.getPercentComplete() );
values.put( LiveStreamConstants.FIELD_CREATED, null != liveStreamInfo.getCreated() ? liveStreamInfo.getCreated().getMillis() : -1 );
values.put( LiveStreamConstants.FIELD_LAST_MODIFIED, null != liveStreamInfo.getLastModified() ? liveStreamInfo.getLastModified().getMillis() : -1 );
values.put( LiveStreamConstants.FIELD_RELATIVE_URL, liveStreamInfo.getRelativeUrl() );
values.put( LiveStreamConstants.FIELD_FULL_URL, liveStreamInfo.getFullUrl() );
values.put( LiveStreamConstants.FIELD_RELATIVE_URL, liveStreamInfo.getRelativeURL() );
values.put( LiveStreamConstants.FIELD_FULL_URL, liveStreamInfo.getFullURL() );
values.put( LiveStreamConstants.FIELD_STATUS_STR, liveStreamInfo.getStatusStr() );
values.put( LiveStreamConstants.FIELD_STATUS_INT, liveStreamInfo.getStatusInt() );
values.put( LiveStreamConstants.FIELD_STATUS_MESSAGE, liveStreamInfo.getStatusMessage() );
Expand Down
2 changes: 1 addition & 1 deletion src/org/mythtv/service/dvr/v25/ProgramHelperV25.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void processProgram( final Context context, final LocationProfile locatio

String programSelection = table + "." + ProgramConstants.FIELD_CHANNEL_ID + " = ? AND " + table + "." + ProgramConstants.FIELD_START_TIME + " = ?";
String[] programSelectionArgs = new String[] { String.valueOf( program.getChannel().getChanId() ), String.valueOf( program.getStartTime().getMillis() ) };

programSelection = appendLocationHostname( context, locationProfile, programSelection, table );

Cursor programCursor = context.getContentResolver().query( uri, programProjection, programSelection, programSelectionArgs, null );
Expand Down
10 changes: 5 additions & 5 deletions src/org/mythtv/service/dvr/v25/RecordedHelperV25.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public boolean deleteRecorded( final Context context, final LocationProfile loca
removed = programHelper.deleteProgram( context, locationProfile, ProgramConstants.CONTENT_URI_RECORDED, ProgramConstants.TABLE_NAME_RECORDED, program.getChannel().getChanId(), program.getStartTime(), program.getRecording().getStartTs(), recordId );
if( removed ) {
// Log.v( TAG, "deleteRecorded : program removed from backend" );

Integer programCount = countRecordedByTitle( context, locationProfile, title );
if( null == programCount ) {
// Log.v( TAG, "deleteRecorded : programCount=" + programCount );
Expand Down Expand Up @@ -261,9 +261,9 @@ private int load( final Context context, final LocationProfile locationProfile,
if( null != program.getChannel() ) {

if( !channelsChecked.contains( program.getChannel().getChanId() ) ) {

if( null == mChannelDaoHelper.findByChannelId( context, locationProfile, Long.parseLong( String.valueOf( program.getChannel().getChanId() ) ) ) ) {

ChannelHelperV25.getInstance().processChannel( context, locationProfile, ops, program.getChannel() );
count++;

Expand Down Expand Up @@ -318,7 +318,7 @@ private int load( final Context context, final LocationProfile locationProfile,

long channelId = deletedCursor.getLong( deletedCursor.getColumnIndex( ProgramConstants.FIELD_CHANNEL_ID ) );
long startTime = deletedCursor.getLong( deletedCursor.getColumnIndex( ProgramConstants.FIELD_START_TIME ) );

// Delete any live stream details
String liveStreamSelection = LiveStreamConstants.FIELD_CHAN_ID + " = ? AND " + LiveStreamConstants.FIELD_START_TIME + " = ?";
String[] liveStreamSelectionArgs = new String[] { String.valueOf( channelId ), String.valueOf( startTime ) };
Expand Down Expand Up @@ -386,7 +386,7 @@ private void processProgramGroups( final Context context, final LocationProfile

int processed = -1;
int count = 0;

ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

Log.v( TAG, "processProgramGroups : adding 'All' program group in programGroups" );
Expand Down
2 changes: 1 addition & 1 deletion src/org/mythtv/service/dvr/v25/RecordingHelperV25.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public RecordingInfo convertCursorToRecording( final Cursor cursor, final String
return recording;
}

// internal helpers
// internal helpers

private ContentValues convertRecordingToContentValues( final LocationProfile locationProfile, final DateTime startTime, final RecordingInfo recording, final String tag ) {
// Log.v( TAG, "convertRecordingToContentValues : enter" );
Expand Down
14 changes: 7 additions & 7 deletions src/org/mythtv/service/dvr/v25/RecordingRuleHelperV25.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ private int addRecordingRule( final Context context, final LocationProfile locat
versionRecRule.getRecGroup(), versionRecRule.getStorageGroup(), versionRecRule.getPlayGroup(), versionRecRule.isAutoExpire(),
versionRecRule.getMaxEpisodes(), versionRecRule.isMaxNewest(), versionRecRule.isAutoCommflag(), versionRecRule.isAutoTranscode(),
versionRecRule.isAutoMetaLookup(), versionRecRule.isAutoUserJob1(), versionRecRule.isAutoUserJob2(), versionRecRule.isAutoUserJob3(),
versionRecRule.isAutoUserJob4(), versionRecRule.getTranscoder() );
versionRecRule.isAutoUserJob4(), versionRecRule.getTranscoder() );

if( add.getStatusCode().equals( HttpStatus.OK ) ) {

Expand Down Expand Up @@ -399,13 +399,13 @@ private boolean updateRecordingRule( final Context context, final LocationProfil
if( added > 0 ) {

ret = true;

downloadRecordinRules( context, locationProfile );

}

}

}

Log.d( TAG, "updateRecordingRule : exit" );
Expand Down Expand Up @@ -502,13 +502,13 @@ private ContentValues convertRecRuleToContentValues( final LocationProfile locat
values.put( RecordingRuleConstants.FIELD_MASTER_HOSTNAME, locationProfile.getHostname() );
values.put( RecordingRuleConstants.FIELD_LAST_MODIFIED_DATE, new DateTime().getMillis() );
// Log.v( TAG, "convertRecRuleToContentValues : values=" + values.toString() );

// Log.v( TAG, "convertRecRuleToContentValues : exit" );
return values;
}

private org.mythtv.services.api.v025.beans.RecRule convertRecRuleToRecRuleV25( final RecRule recordingRule ) {

org.mythtv.services.api.v025.beans.RecRule versionRecRule = new org.mythtv.services.api.v025.beans.RecRule();
versionRecRule.setId( recordingRule.getId() );
versionRecRule.setParentId( recordingRule.getParentId() );
Expand Down
Loading

0 comments on commit 6244ff0

Please sign in to comment.