package com.newvideo.util.zhibo;
|
|
import java.io.IOException;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.HttpException;
|
import org.apache.commons.httpclient.methods.GetMethod;
|
import org.springframework.stereotype.Component;
|
|
import com.newvideo.domain.HomeVideo;
|
import com.newvideo.domain.VideoInfo;
|
import com.newvideo.service.imp.ConfigService;
|
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
@Component
|
public class MeiNvZhiBoUtil {
|
public final static String MEINV_KK = "meinv_kk";// KK
|
public final static String MEINV_MM = "meinv_mm";// 么么直播
|
public final static String MEINV_FX = "meinv_fx";// 酷狗繁星
|
|
@Resource
|
private ConfigService configService;
|
|
public List<HomeVideo> getMeiNvZhiBo(String type) {
|
Map<String, String> map = configService.getConfigAsMap();
|
List<HomeVideo> list = new ArrayList<HomeVideo>();
|
if (type.equalsIgnoreCase(MEINV_FX)) {
|
|
} else if (type.equalsIgnoreCase(MEINV_KK)) {
|
try {
|
list = getKKList(Integer.parseInt(map.get("meinv_kk_count")));
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
} else if (type.equalsIgnoreCase(MEINV_MM)) {
|
try {
|
list = getMMList(Integer.parseInt(map.get("meinv_mm_count")));
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
return list;
|
}
|
|
private static List<HomeVideo> getKKList(int count) throws Exception {
|
List<HomeVideo> list = new ArrayList<HomeVideo>();
|
String result = get(
|
"http://www.kktv1.com/CDN/output/M/3/I/10002002/P/start-0_offset-" + count + "_platform-2/json.js");
|
JSONObject object = JSONObject.fromObject(result);
|
JSONArray array = object.optJSONArray("roomList");
|
for (int i = 0; i < array.size(); i++) {
|
VideoInfo info = new VideoInfo();
|
JSONObject obj = array.optJSONObject(i);
|
info.setId(obj.optString("roomId"));
|
info.setName(obj.optString("nickname"));
|
info.setTag("在线:" + obj.optString("onlineCount"));
|
info.setPicture(obj.optString("poster_path_272"));
|
HomeVideo hv = new HomeVideo();
|
hv.setPicture(info.getPicture());
|
hv.setVideo(info);
|
list.add(hv);
|
}
|
return list;
|
}
|
|
private static List<HomeVideo> getMMList(int count) throws Exception {
|
List<HomeVideo> list = new ArrayList<HomeVideo>();
|
String result = get("http://api.memeyule.com/union/star_json?from=mugua&page=1&size=" + count + "&sort=1");
|
JSONObject object = JSONObject.fromObject(result);
|
JSONArray array = object.optJSONArray("data");
|
for (int i = 0; i < array.size(); i++) {
|
VideoInfo info = new VideoInfo();
|
JSONObject obj = array.optJSONObject(i);
|
info.setId(obj.optString("star_id"));
|
info.setName(obj.optString("star_name"));
|
info.setTag("在线:" + obj.optString("audience_num"));
|
info.setPicture(obj.optString("image_url"));
|
HomeVideo hv = new HomeVideo();
|
hv.setPicture(info.getPicture());
|
hv.setVideo(info);
|
list.add(hv);
|
}
|
return list;
|
}
|
|
private static String get(String url) {
|
HttpClient client = new HttpClient();
|
GetMethod method = new GetMethod(url);
|
method.getParams().setContentCharset("UTF-8");
|
try {
|
client.executeMethod(method);
|
String responseBodyAsString = method.getResponseBodyAsString();
|
// LogUtil.i(responseBodyAsString);
|
return responseBodyAsString;
|
} catch (HttpException e) {
|
e.printStackTrace();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
return "";
|
}
|
|
}
|