Skip to content

Commit

Permalink
Code revised to work against the Java2 Kaltura client lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Jess portnoy committed Apr 6, 2020
1 parent 6d7982e commit a3627a3
Show file tree
Hide file tree
Showing 25 changed files with 150 additions and 367 deletions.
Binary file added KalturaApiClient-15.14.0-SNAPSHOT.jar
Binary file not shown.
Binary file removed KalturaClient-3.3.1.jar
Binary file not shown.
Binary file added UploadTest.class
Binary file not shown.
124 changes: 88 additions & 36 deletions UploadTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@

import com.kaltura.client.enums.*;
import com.kaltura.client.types.*;
import com.kaltura.client.utils.response.base.Response;
import com.kaltura.client.services.*;
import com.kaltura.client.KalturaApiException;
import com.kaltura.client.KalturaClient;
import com.kaltura.client.KalturaConfiguration;
import com.kaltura.client.services.MediaService.AddContentMediaBuilder;
import com.kaltura.client.services.MediaService.AddMediaBuilder;
import com.kaltura.client.services.MediaService.GetMediaBuilder;
import com.kaltura.client.services.MediaService.UpdateContentMediaBuilder;
import com.kaltura.client.APIOkRequestsExecutor;
import com.kaltura.client.Client;
import com.kaltura.client.Configuration;
import java.util.ArrayList;
import java.util.List;
import com.kaltura.client.utils.response.OnCompletion;
import com.kaltura.client.utils.response.base.Response;

import chunkedupload.ParallelUpload;

public class UploadTest {
Expand All @@ -15,52 +25,94 @@ public static void main(String[] argv){
System.exit (1);
}
try{
KalturaConfiguration config = new KalturaConfiguration();
Configuration config = new Configuration();
config.setEndpoint(argv[0]);
KalturaClient client = new KalturaClient(config);

Client client = new Client(config);

String secret = argv[2];
String userId = null;
int partnerId = Integer.parseInt(argv[1]);
String privileges = null;
KalturaSessionService sessionService = client.getSessionService();
String ks = client.generateSessionV2(secret, null, KalturaSessionType.ADMIN, partnerId, 86400, "");
String ks = client.generateSessionV2(secret, null, SessionType.ADMIN, partnerId, 86400, "");

client.setSessionId(ks);
System.out.println(ks);

KalturaMediaEntry newEntry = null;
MediaEntry newEntry = null;
boolean update = false;
if(argv.length > 4 && argv[4] != "") {
newEntry = client.getMediaService().get(argv[4]);
update = true;
String filePath = argv[3];
String entryId = null;
if(argv.length > 4 && argv[4] != ""){
entryId=argv[4];
GetMediaBuilder getBuilder = MediaService.get(entryId);
Response<MediaEntry> response = (Response<MediaEntry>)APIOkRequestsExecutor.getExecutor().execute(getBuilder.build(client));
if (response != null && response.results.getId() != null){
doUpload(client, filePath, entryId, true);
}else{
System.out.println("No such entry" + entryId + "\n");
}

} else {
KalturaMediaEntry entry = new KalturaMediaEntry();
entry.name = "Chunked Upload Test";
entry.type = KalturaEntryType.MEDIA_CLIP;
entry.mediaType = KalturaMediaType.VIDEO;
newEntry = client.getMediaService().add(entry);
}
newEntry = new MediaEntry();
newEntry.setName("Chunked Upload Test");
newEntry.setType(EntryType.MEDIA_CLIP);
newEntry.setMediaType(MediaType.VIDEO);
AddMediaBuilder requestBuilder = MediaService.add(newEntry)
.setCompletion(new OnCompletion<Response<MediaEntry>>() {
public void onComplete(Response<MediaEntry> result) {
System.out.println("her nnow\n");
String fentryId = result.results.getId();;
if (fentryId !=null){
System.out.println("\nCreated a new entry: " + fentryId);
doUpload(client, filePath, fentryId, false);
}else{
return;
}

System.out.println("\nCreated a new entry: " + newEntry.id);

ParallelUpload pu = new ParallelUpload(client, argv[3]);
String tokenId = pu.upload();
if (tokenId != null) {
KalturaUploadedFileTokenResource fileTokenResource = new KalturaUploadedFileTokenResource();
fileTokenResource.token = tokenId;
if(update == true) {
newEntry = client.getMediaService().updateContent(newEntry.id, fileTokenResource);
} else {
newEntry = client.getMediaService().addContent(newEntry.id, fileTokenResource);
}
System.out.println("\nUploaded a new Video file to entry: " + newEntry.id);
}
});
APIOkRequestsExecutor.getExecutor().queue(requestBuilder.build(client));
}
} catch (KalturaApiException e) {
e.printStackTrace();


}
catch (APIException e)
{
e.printStackTrace();
}
} catch (Exception exc) {
exc.printStackTrace();
}
exc.printStackTrace();
}
}
public static boolean doUpload(Client client, String filePath, String entryId,boolean update)
{
ParallelUpload pu = new ParallelUpload(client, filePath);
String tokenId = null;
try{
tokenId = pu.upload();

}catch (Exception e){
e.printStackTrace();
}

if (tokenId != null) {
UploadedFileTokenResource fileTokenResource = new UploadedFileTokenResource();
fileTokenResource.setToken(tokenId);
Response<MediaEntry> response =null;
if(update == true){
UpdateContentMediaBuilder requestBuilder = MediaService.updateContent(entryId, fileTokenResource);
response = (Response<MediaEntry>)APIOkRequestsExecutor.getExecutor().execute(requestBuilder.build(client));
} else {
AddContentMediaBuilder requestBuilder = MediaService.addContent(entryId, fileTokenResource);
response = (Response<MediaEntry>)APIOkRequestsExecutor.getExecutor().execute(requestBuilder.build(client));
}
if (response != null && response.error != null){
System.out.println(response.error);
return (false);
}

System.out.println("\nUploaded Video file to entry: " + entryId);
}
return (true);

}
}
Loading

0 comments on commit a3627a3

Please sign in to comment.