admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
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
package com.yeshi.buwan.util.zhibo;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import com.yeshi.buwan.domain.system.DetailSystem;
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.yeshi.buwan.domain.HomeVideo;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.service.imp.DetailSystemConfigService;
 
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 DetailSystemConfigService configService;
 
    public List<HomeVideo> getMeiNvZhiBo(String type, DetailSystem system,int version) {
        Map<String, String> map = configService.getConfigAsMap(system,version);
        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 "";
    }
 
}