Skip to content

Commit 447e867

Browse files
committed
cloudkey-java sources + jar
0 parents  commit 447e867

File tree

12 files changed

+787
-0
lines changed

12 files changed

+787
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.*
2+
!.gitignore
3+
bin/

cloudkey-java.jar

1.63 MB
Binary file not shown.

examples/Cloud.jsp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<h1>My videos on DM Cloud</h1>
2+
3+
<% String user_id = "YOUR USER ID"; %></p>
4+
<% String api_key = "YOUR API KEY"; %></p>
5+
6+
<%@ page import="com.dmcloud.*"%>
7+
<%@ page import="java.util.Map"%>
8+
<%@ page import="java.util.ArrayList"%>
9+
<%
10+
try
11+
{
12+
CloudKey cloud = new CloudKey(user_id, api_key);
13+
14+
DCObject result = cloud.call
15+
(
16+
"media.list",
17+
DCObject.create()
18+
.push("fields", DCArray.create()
19+
.push("id")
20+
.push("meta.title")
21+
.push("assets.jpeg_thumbnail_auto.stream_url")
22+
.push("assets.mp4_h264_aac.video_width")
23+
.push("assets.mp4_h264_aac.video_height")
24+
.push("assets.source.download_url")
25+
)
26+
);
27+
DCArray list = DCArray.create((ArrayList)result.get("list"));
28+
for(int i=0; i<list.size(); i++)
29+
{
30+
DCObject item = DCObject.create((Map)list.get(i));
31+
out.write("<p>Title : " + item.pull("meta.title") + "</p>");
32+
out.write("<p><img src=\"" + item.pull("assets.jpeg_thumbnail_auto.stream_url") + "\" /></p>");
33+
String[] referers = {"http://www.dmcloud.net"};
34+
String embed_url = cloud.get_embed_url(CloudKey.CLOUDKEY_API_URL, item.get("id").toString(), CloudKey.CLOUDKEY_SECLEVEL_REFERER, "", "", "", null, referers, 0);
35+
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>");
36+
String stream_url = cloud.get_stream_url(CloudKey.CLOUDKEY_API_URL, item.get("id").toString(), "mp4_h264_aac", CloudKey.CLOUDKEY_SECLEVEL_REFERER, "", "", "", null, referers, 0, "", false);
37+
String dl_url = item.pull("assets.source.download_url");
38+
out.write("<p><a href=\"" + dl_url + "\">Download source</a></p>");
39+
out.write("<p><a href=\"" + stream_url + "\">Stream url</a></p>");
40+
}
41+
}
42+
catch(Exception e)
43+
{
44+
out.write("<p>Error : " + e.getMessage() + "</p>");
45+
}
46+
%>

src/com/dmcloud/CloudKey.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.dmcloud;
2+
3+
import java.util.ArrayList;
4+
import java.util.Map;
5+
6+
public class CloudKey extends CloudKey_LL {
7+
8+
public CloudKey(String _user_id, String _api_key) throws Exception
9+
{
10+
super(_user_id, _api_key, CLOUDKEY_API_URL, CLOUDKEY_CDN_URL, "");
11+
}
12+
13+
public CloudKey(String _user_id, String _api_key, String _base_url, String _cdn_url, String _proxy) throws Exception
14+
{
15+
super(_user_id, _api_key, _base_url, _cdn_url, _proxy);
16+
}
17+
18+
public String mediaCreate() throws Exception
19+
{
20+
return mediaCreate("", null, null);
21+
}
22+
23+
public String mediaCreate(String url, ArrayList<String> assets_names, Map meta) throws Exception
24+
{
25+
DCObject args = DCObject.create()
26+
.push("url", url)
27+
.push("meta", meta)
28+
.push("assets_names", assets_names);
29+
Map result = this.call("media.create", args);
30+
return result.get("id").toString();
31+
}
32+
33+
public void mediaDelete(String id) throws Exception
34+
{
35+
this.call("media.delete", DCObject.create().push("id", id));
36+
}
37+
38+
public String upload() throws Exception
39+
{
40+
Map result = this.call("file.upload", null);
41+
return result.get("url").toString();
42+
}
43+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.dmcloud;
2+
3+
public class CloudKey_Exception extends Exception
4+
{
5+
int code = 0;
6+
7+
public CloudKey_Exception(String message)
8+
{
9+
super(message);
10+
}
11+
12+
public CloudKey_Exception(String message, int _code)
13+
{
14+
this(message);
15+
this.code = _code;
16+
}
17+
18+
public int getCode()
19+
{
20+
return this.code;
21+
}
22+
}

0 commit comments

Comments
 (0)