admin
2021-01-25 d182390205a9828bd1091b06fa712e028004c687
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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<LeTVVideo> videoList(int page) {
        Map<String, String> map = new HashMap<String, String>();
        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<LeTVVideo> list = new ArrayList<LeTVVideo>();
            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<LeTVVideo> videoNewList() {
        Map<String, String> map = new HashMap<String, String>();
        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<LeTVVideo> list = new ArrayList<LeTVVideo>();
            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<String, String> map = new HashMap<String, String>();
        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<LeTVAlbum> albumList(int page) {
        List<LeTVAlbum> list = new ArrayList<LeTVAlbum>();
        Map<String, String> map = new HashMap<String, String>();
        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<LeTVAlbum> albumNewList() {
        List<LeTVAlbum> list = new ArrayList<LeTVAlbum>();
        Map<String, String> map = new HashMap<String, String>();
        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<String, String> map = new HashMap<String, String>();
        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<String, Object> albumVideoList(String albumId, int page) {
        Map<String, Object> resultMap = new HashMap<String, Object>();
        Map<String, String> map = new HashMap<String, String>();
        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<LeTVVideo> videoList = new ArrayList<LeTVVideo>();
        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;
    }
 
}