admin
2022-04-16 04f09e52ffd4681bdfd85e51acd3da0d1280c3d3
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
package com.yeshi.buwan.controller.api;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.buwan.domain.live.*;
import com.yeshi.buwan.live.migu.MiGuLiveListInfo;
import com.yeshi.buwan.live.migu.MiguLiveApiUtil;
import com.yeshi.buwan.service.inter.live.MiGuLiveService;
import com.yeshi.buwan.service.inter.live.TVLiveCategoryChannelService;
import com.yeshi.buwan.service.inter.live.TVLiveCategoryService;
import com.yeshi.buwan.service.inter.live.TVLiveChannelResourceService;
import com.yeshi.buwan.util.Constant;
import com.yeshi.buwan.util.JsonUtilV2;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.vo.AcceptData;
import com.yeshi.buwan.vo.tvlive.TVLiveChannelVO;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
 
/**
 * 电视直播
 */
@Controller
@RequestMapping("api/v2/tvlive")
public class TVLiveController {
 
    Logger logger = LoggerFactory.getLogger(TVLiveController.class);
 
 
    @Resource
    private TVLiveCategoryService tvLiveCategoryService;
 
    @Resource
    private TVLiveCategoryChannelService tvLiveCategoryChannelService;
 
    @Resource
    private TVLiveChannelResourceService tvLiveChannelResourceService;
 
    @Resource
    private MiGuLiveService miGuLiveService;
 
 
    @RequestMapping("getCategory")
    @ResponseBody
    public String getCategory(AcceptData acceptData) {
        Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
        List<SuperTVLiveCategory> superList = tvLiveCategoryService.listSuper(acceptData.getDetailSystem().getId(), 1, 20);
        List<String> channelIds = new ArrayList<>();
        for (SuperTVLiveCategory category : superList) {
            channelIds.add(category.getCid());
        }
        List<TVLiveCategory> categoryList = tvLiveCategoryService.listByIds(channelIds);
        JSONObject data = new JSONObject();
        data.put("count", categoryList.size());
        data.put("data", gson.toJson(categoryList));
        return JsonUtilV2.loadTrueJson(data.toString());
    }
 
 
    @RequestMapping("getChannelList")
    @ResponseBody
    public String getChannelList(AcceptData acceptData, String cid, int page) {
 
        if (StringUtil.isNullOrEmpty(cid)) {
            return JsonUtilV2.loadFalseJson("cid为空");
        }
 
        List<TVLiveChannel> channelList = tvLiveCategoryChannelService.listChannelByCid(cid, null, page, Constant.pageCount);
        long count = tvLiveCategoryChannelService.countChannelByCid(cid, null);
 
        List<TVLiveChannelVO> voList = new ArrayList<>();
        for (TVLiveChannel channel : channelList) {
            voList.add(TVLiveChannelVO.create(channel));
        }
        JSONObject root = new JSONObject();
        root.put("list", new Gson().toJson(voList));
        root.put("count", count);
        return JsonUtilV2.loadTrueJson(root.toString());
    }
 
    @RequestMapping("getPlayUrl")
    @ResponseBody
    public String getPlayUrl(AcceptData acceptData, String id) {
 
        if (StringUtil.isNullOrEmpty(id)) {
            return JsonUtilV2.loadFalseJson("id为空");
        }
 
        //获取播放链接
 
        List<TVLiveChannelResourceMap> mapList = tvLiveChannelResourceService.listByChannelId(id);
        if (mapList == null || mapList.size() == 0) {
            return JsonUtilV2.loadFalseJson("暂无播放源");
        }
 
        TVLiveChannelResourceMap map = mapList.get(0);
        String playUrl = null;
        if (map.getResource() == TVLiveResource.migu) {
            MiGuLiveListInfo info = miGuLiveService.selectByPrimaryKey(map.getRid());
            playUrl = MiguLiveApiUtil.getPlayUrl(info.getPID());
        } else if (map.getResource() == TVLiveResource.other) {
            playUrl = map.getPlayUrl();
        }
        JSONObject root = new JSONObject();
        root.put("playUrl", playUrl);
        return JsonUtilV2.loadTrueJson(root.toString());
    }
 
 
}