JAVA SDK

General information

The JAVA library exposes all API methods described in Cloud API section.

You can download cloudkey.jar and sources on GitHub.

A master class named CloudKey exposes all objects (eg: Media API) through object attributes.

Some jsp examples are available on cloudkey-java/examples.

Remote methods

Example of json object

{"fields":["id","media.title","assets.jpeg_thumbnail_auto.stream_url","assets.mp4_h264_aac.video_width","assets.mp4_h264_aac.video_height","assets.source.download_url"]}

For instance, to call the list method from the CloudKey object

First, you need to create a DCArray, which contains fields

DCArray fields = DCArray.create().push("id")
                                 .push("media.title")
                                 .push("assets.jpeg_thumbnail_auto.stream_url")
                                 .push("assets.mp4_h264_aac.video_width")
                                 .push("assets.mp4_h264_aac.video_height")
                                 .push("assets.source.download_url");

Then, you create a DCObject for mapping fields with array

DCObject args = DCObject.create().push("fields", fields);

Finally, you have

<%@ page import="net.dmcloud.cloudkey.*"%>
<%@ page import="net.dmcloud.util.*"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.ArrayList"%>
<%
CloudKey cloud = new CloudKey(user_id, api_key);
DCObject result = cloud.call
(
    "media.list",
    DCObject.create()
            .push
            (
                "fields",
                DCArray.create()
                       .push("id")
                       .push("meta.title")
                       .push("assets.jpeg_thumbnail_auto.stream_url")
                       .push("assets.mp4_h264_aac.video_width")
                       .push("assets.mp4_h264_aac.video_height")
                       .push("assets.source.download_url")
            )
);

Use result object mapping => DCObject (similar as HashMap)

DCArray list = DCArray.create((ArrayList)result.get("list"));
for(int i=0; i<list.size(); i++)
{
    DCObject item = DCObject.create((Map)list.get(i));
    out.write("<p>Title : " + item.pull("meta.title") + "</p>");
    out.write("<p><img src=\"" + item.pull("assets.jpeg_thumbnail_auto.stream_url") + "\" /></p>");
    String[] referers = {'http://SERVER_URL'};
    String embed_url = cloud.getEmbedUrl(CloudKey.API_URL, item.get("id").toString(), CloudKey.SECLEVEL_REFERER, "", "", "", null, referers, 0);
    out.write("<iframe width=\"" + item.pull("assets.mp4_h264_aac.video_width") + "\" height=\"" + item.pull("assets.mp4_h264_aac.video_height") + "\" src=\"" + embed_url  + "\"></iframe>");
    String stream_url = cloud.getStreamUrl(CloudKey.API_URL, item.get("id").toString(), "mp4_h264_aac", CloudKey.SECLEVEL_REFERER, "", "", "", null, referers, 0, "", false);
    String dl_url = item.pull("assets.source.download_url");
    out.write("<p><a href=\"" + dl_url + "\">Download source</a></p>");
    out.write("<p><a href=\"" + stream_url + "\">Stream url</a></p>");
}

Local methods

File object

fileUpload()

File API

String url_upload = cloud.fileUpload();
// OR
DCObject result = cloud.fileUpload(true, "?", "http://SERVER_URL/redirect_url.jsp");
String status_url = result.pull("status");
String upload_url = result.pull("url");

Media object

mediaGetEmbedUrl()

This method returns a signed URL to a Dailymotion Cloud player embed (see the API reference for details).

The generated URL is perishable, and access is granted based on the provided security level bitmask.

Parameters:
  • id (media ID) - the id of the new media object.
  • seclevel (int) - the security level bitmask (default is CloudKey.SECLEVEL_NONE, see below for details).
  • expires (int) - the UNIX epoch expiration time (default is new Date().getTime() + 7200 (2 hours from now)).

The following arguments may be required if the CloudKey.SECLEVEL_DELEGATE option is not specified in the seclevel parameter, depending on the other options. This is not recommended as it would probably lead to spurious access denials, mainly due to GeoIP databases discrepancies.

Parameters:
  • asnum (str) - the client’s autonomous system number (default is null).
  • ip (str) - the client’s IP adress (default is null).
  • useragent (str) - the client’s HTTP User-Agent header (default is null).
  • countries (DCArray) - the list of country codes you want to allow or block, if the first country is ‘-‘ it means block otherwise it means allow (default is null).
  • referers (DCArray) - the list of referers you want to allow (default is null)

Example:

// Create an embed URL limited only to the AS of the end-user and valid for 1 hour
String embed_url = cloud.mediaGetEmbedUrl(media_id, (CloudKey.SECLEVEL_DELEGATE|CloudKey.SECLEVEL_ASNUM), '', '', null, null, (int)(new Date().getTime() + 3600));
mediaGetStreamUrl()

This method returns a signed URL to a Dailymotion Cloud video stream (see the API reference for details).

The generated URL is perishable, and access is granted based on the provided security level bitmask.

Parameters:
  • id (media ID) - the id of the new media object.
  • asset_name (str) - the desired media ASSET_NAME (default is mp4_h264_aac).
  • seclevel (int) - the security level bitmask (default is CloudKey.SECLEVEL_NONE, see below for details).
  • expires (int) - the UNIX epoch expiration time (default is new Date().getTime() + 7200 (2 hours from now)).

The following arguments may be required if the CloudKey.SECLEVEL_DELEGATE option is not specified in the seclevel parameter, depending on the other options. This is not recommended as it would probably lead to spurious access denials, mainly due to GeoIP databases discrepancies.

Parameters:
  • asnum (str) - the client’s autonomous system number (default is null).
  • ip (str) - the client’s IP address (default is null).
  • useragent (str) - the client’s HTTP User-Agent header (default is null).
  • countries (DCArray) - the list of country codes you want to allow or block, if the first country is ‘-‘ it means block otherwise it means allow (default is null).
  • referers (DCArray) - the list of referers you want to allow (default is null)
mediaCreate()
Parameters:
  • url (str) - the url of the media object (optional)
  • assets_names (DCArray) - ASSET_NAME (see the API media) (optional)
  • meta (DCObject) - an hashmap containing meta as keys and values (optional)
mediaCreate()
Parameters:
  • f (java.io.File) - File object
  • assets_names (DCArray) - ASSET_NAME (see the API media) (optional)
  • meta (DCObject) - an hashmap containing meta as keys and values (optional)
mediaDelete()
Parameters:
  • id (media ID) - the id of the media object.

Quick Tour

Security level options

The security level defines the mechanism used by the Dailymotion Cloud architecture to ensure a mediastream URL access will be limited to a single user or a group of users. The different (combinable) options are:

  • CloudKey.SECLEVEL_NONE: the URL access is granted to everyone.
  • CloudKey.SECLEVEL_ASNUM: the URL access is granted to the specified AS number only. AS numbers stands for ‘Autonomous System number’ and roughly map groups of IP to telcos and large organizations on the Internet (each ISP has its own AS number for instance, Dailyotion’s AS number is AS41690).
  • CloudKey.SECLEVEL_IP: the URL access is granted to the specified IP address only. This option may lead to spurious access denials as some users are load-balanced behind multiple proxies when accessing the Internet (this is mostly the case with ISPs and large organizations).
  • CloudKey.SECLEVEL_USERAGENT: the URL access is granted to users sending the specified User-Agent HTTP header only.
  • CloudKey.SECLEVEL_DELEGATE: the ASNUM, IP and User-Agent values are to be gathered at the server side during the first URL access and don’t need to be specified at the client side beforehand (this is the recommanded approach as it will ensure a 100%-accurate ASNUM recognition).
  • CloudKey.SECLEVEL_USEONCE: the URL access is granted once only (using this option will probably prevent seeking from working correctly).
  • CloudKey.SECLEVEL_COUNTRY: the URL can only be queried from specified countrie(s). The rule can be reversed to allow all countries except some.
  • CloudKey.SECLEVEL_REFERER: the URL can only be queried if the Referer HTTP header contains a specified value. If the URL contains a Referer header with a different value, the request is refused. If the Referer header is missing, the request is accepted in order to prevent from false positives as some browsers, anti-virus or enterprise proxies may remove this header.

For more information, please refer to: Which security level to choose for which usage

Exceptions

  • CloudKey_Exception: This is the base of all exceptions
    • RPCException: Default exception
    • TransportException: When an error occured with the HTTP transport
    • SerializerErrorException: When the Request or the Response is not valid JSON
    • InvalidRequestException: When the Request is not wellformed
    • InvalidCallException: When the value of the call argument is invalid
    • InvalidObjectException: When you access an object that doesn’t exist
    • InvalidMethodException: When you access a method that doesn’t exist
    • InvalidParameterException: When a method is called with a invalid or missing parameter
    • AuthenticationErrorException: When authentication information is invalid
      • RateLimitExceededException: When you exceed the number of API calls on a specific timeframe
    • ApplicationException: The base class of the following exceptions
      • NotFoundException: When action is requested on an item that doesn’t exist
      • ExistsException: When action is requested on an item that already exists
      • LimitExceededException: When you reach the maximum number of allowed objects.

Table Of Contents

Previous topic

Python SDK

Next topic

API Tutorial

This Page