package com.newvideo.letv; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.newvideo.letv.entity.LeTVAlbum; import com.newvideo.letv.entity.LeTVVideo; import com.newvideo.util.HttpUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class LeAPI { public static final String URL = "http://api.open.lecloud.com/vrp/vod/execute"; public static final String ALBUM_URL = "http://api.open.lecloud.com/vrp/album/execute"; public static List videoList(int page) { Map map = new HashMap(); map.put("method", "le.vrp.vod.pageList"); map.put("uId", LeTVUtil.UID); map.put("ver", "1.0"); map.put("sign", LeTVUtil.getSign()); map.put("timestamp", System.currentTimeMillis() + ""); map.put("curPage", page + ""); map.put("pageSize", "20"); map.put("sort", "desc"); String result = HttpUtil.get(URL, map); JSONObject root = JSONObject.fromObject(result); if (root.optInt("code") == 0) { Gson gson = new GsonBuilder().create(); JSONArray data = root.optJSONArray("data"); List list = new ArrayList(); for (int i = 0; i < data.size(); i++) { LeTVVideo tv = gson.fromJson(data.optJSONObject(i).toString(), LeTVVideo.class); list.add(getVideoDetail(tv.getVideoId())); } return list; } return null; } // �����ӿ� public static List videoNewList() { Map map = new HashMap(); map.put("method", "le.vrp.vod.incrementList"); map.put("uId", LeTVUtil.UID); map.put("ver", "1.0"); map.put("sign", LeTVUtil.getSign()); map.put("timestamp", System.currentTimeMillis() + ""); String result = HttpUtil.get(URL, map); JSONObject root = JSONObject.fromObject(result); if (root.optInt("code") == 0) { Gson gson = new GsonBuilder().create(); JSONArray data = root.optJSONArray("data"); List list = new ArrayList(); for (int i = 0; i < data.size(); i++) { LeTVVideo tv = gson.fromJson(data.optJSONObject(i).toString(), LeTVVideo.class); list.add(tv); } return list; } return null; } public static LeTVVideo getVideoDetail(String vid) { Map map = new HashMap(); map.put("method", "le.vrp.vod.get"); map.put("uId", LeTVUtil.UID); map.put("ver", "1.0"); map.put("sign", LeTVUtil.getSign()); map.put("timestamp", System.currentTimeMillis() + ""); map.put("videoId", vid); String result = HttpUtil.get(URL, map); JSONObject root = JSONObject.fromObject(result); if (root.optInt("code") == 0) { Gson gson = new GsonBuilder().create(); LeTVVideo tv = gson.fromJson(root.optJSONObject("data").toString(), LeTVVideo.class); tv.setExtendPropertiesStr(tv.getExtendProperties().toString()); return tv; } return null; } // ר���б� public static List albumList(int page) { List list = new ArrayList(); Map map = new HashMap(); map.put("method", "le.vrp.album.pageList"); map.put("uId", LeTVUtil.UID); map.put("ver", "1.0"); map.put("sign", LeTVUtil.getSign()); map.put("timestamp", System.currentTimeMillis() + ""); map.put("curPage", page + ""); map.put("pageSize", "20"); map.put("sort", "desc"); // map.put("category", "100002"); // category String result = HttpUtil.get(ALBUM_URL, map); JSONObject obj = JSONObject.fromObject(result); if (obj.optInt("code") == 0) { JSONArray array = obj.optJSONArray("data"); Gson gson = new GsonBuilder().setVersion(1.0).create(); for (int i = 0; i < array.size(); i++) { LeTVAlbum album = gson.fromJson(array.optJSONObject(i).toString(), LeTVAlbum.class); list.add(albumDetail(album.getAlbumId())); } } return list; } public static List albumNewList() { List list = new ArrayList(); Map map = new HashMap(); map.put("method", "le.vrp.album.incrementList"); map.put("uId", LeTVUtil.UID); map.put("ver", "1.0"); map.put("sign", LeTVUtil.getSign()); map.put("timestamp", System.currentTimeMillis() + ""); // map.put("category", "100002"); // category String result = HttpUtil.get(ALBUM_URL, map); JSONObject obj = JSONObject.fromObject(result); if (obj.optInt("code") == 0) { JSONArray array = obj.optJSONArray("data"); Gson gson = new GsonBuilder().setVersion(1.0).create(); for (int i = 0; i < array.size(); i++) { LeTVAlbum album = gson.fromJson(array.optJSONObject(i).toString(), LeTVAlbum.class); list.add(albumDetail(album.getAlbumId())); } } return list; } // ר������ public static LeTVAlbum albumDetail(String albumId) { Map map = new HashMap(); map.put("method", "le.vrp.album.get"); map.put("uId", LeTVUtil.UID); map.put("ver", "1.0"); map.put("sign", LeTVUtil.getSign()); map.put("timestamp", System.currentTimeMillis() + ""); map.put("albumId", albumId); // category String result = HttpUtil.get(ALBUM_URL, map); JSONObject obj = JSONObject.fromObject(result); Gson gson = new GsonBuilder().create(); if (obj.optInt("code") == 0) { LeTVAlbum album = gson.fromJson(obj.optJSONObject("data").toString(), LeTVAlbum.class); album.setExtendPropertiesStr(album.getExtendProperties().toString()); return album; } return null; } // ר������Ƶ�б� public static Map albumVideoList(String albumId, int page) { Map resultMap = new HashMap(); Map map = new HashMap(); map.put("method", "le.vrp.album.getVideoList"); map.put("uId", LeTVUtil.UID); map.put("ver", "1.0"); map.put("sign", LeTVUtil.getSign()); map.put("timestamp", System.currentTimeMillis() + ""); map.put("curPage", page + ""); map.put("pageSize", "20"); map.put("sort", "desc"); map.put("category", "100002"); map.put("albumId", albumId); String result = HttpUtil.get(ALBUM_URL, map); JSONObject obj = JSONObject.fromObject(result); List videoList = new ArrayList(); if (obj.optInt("code") == 0) { Gson gson = new GsonBuilder().create(); JSONArray array = obj.optJSONArray("data"); for (int i = 0; i < array.size(); i++) { LeTVVideo tv = gson.fromJson(array.optString(i), LeTVVideo.class); videoList.add(getVideoDetail(tv.getVideoId())); } } resultMap.put("data", videoList); resultMap.put("count", obj.optInt("totalCount")); return resultMap; } }