Skip to content

Instantly share code, notes, and snippets.

@fjenett
Last active August 29, 2015 11:29
Show Gist options
  • Save fjenett/b8e288c00123b511f25e to your computer and use it in GitHub Desktop.
Save fjenett/b8e288c00123b511f25e to your computer and use it in GitHub Desktop.
Find "3D Positions" event for a video
/**
* fjenett - 2015
*/
import org.piecemaker2.api.*;
import org.piecemaker2.models.*;
import java.util.Properties;
import java.util.Date;
/* INSERT YOUR API KEY HERE */
String apiKey = "";
/* INSERT GROUP ID HERE */
int groupId = 29;
String apiHost = "http://piecemaker2-api-public.herokuapp.com";
PieceMakerApi api;
void setup ()
{
size( 400, 200 );
// initialize the client with host and API-Key
api = new PieceMakerApi( this, apiHost, apiKey );
// trigger loading of group
api.listEventsOfType( groupId, "video", api.createCallback( "groupLoaded" ) );
fill( 255 );
textSize( 24 );
textAlign( CENTER );
}
void draw ()
{
if ( apiKey != null )
{
background( #669933 );
} else {
background( #994433 );
}
}
// group loaded callback
void groupLoaded ( org.piecemaker2.models.Event[] videos )
{
for ( org.piecemaker2.models.Event v : videos )
{
if ( v.fields.get("title").equals("D06T02_Janine_sync_AJA_1") )
{
api.listEventsForTimespan( groupId,
v.utc_timestamp,
new Date( v.utc_timestamp.getTime() + (long)(v.duration * 1000) ),
api.INTERSECTING,
api.createCallback("eventsLoaded") );
break;
}
}
}
// context events loaded callback
void eventsLoaded ( org.piecemaker2.models.Event[] events )
{
for ( org.piecemaker2.models.Event e : events )
{
if ( e.type.equals("data") )
{
println( "ID: " + e.id + " / Title: " + e.fields.get("title") );
String host = (String)e.fields.get("pma-server"),
uuid = (String)e.fields.get("pma-channel-uuid");
loadChannelAndStreams( host,uuid );
break;
}
}
}
// loading the actual data from Piecemeta
void loadChannelAndStreams ( String host, String channelUUID )
{
JSONObject channel = loadJSONObject( "http://"+host+"/channels/"+channelUUID+".json" );
JSONArray streams = loadJSONArray( "http://"+host+"/channels/"+channelUUID+"/streams.json" );
println( "channel \"" + channel.getString("title") + "\" / streams: " + streams.size() );
for ( int i = 0, k = streams.size(); i < k; i++ )
{
JSONObject streamInfo = streams.getJSONObject(i);
String streamUUID = streamInfo.getString( "uuid" );
JSONObject stream = loadJSONObject( "http://"+host+"/streams/"+streamUUID+".json" + "?skip=2" );
println( "stream \"" + stream.getString("title") + "\" / frames: " + stream.getJSONArray("frames").size() );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment