admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
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
package com.hxh.spring.test.live;
 
import com.yeshi.buwan.dao.live.TVLiveChannelDao;
import com.yeshi.buwan.domain.live.TVLiveChannel;
import com.yeshi.buwan.domain.live.TVLiveProgramResource;
import com.yeshi.buwan.exception.ParamsException;
import com.yeshi.buwan.job.LiveJob;
import com.yeshi.buwan.service.inter.live.TVLiveProgramResourceService;
import com.yeshi.buwan.util.StringUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
 
import javax.annotation.Resource;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
 
@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试
@ContextConfiguration(locations = {"classpath:spring.xml"})
@WebAppConfiguration
public class TVLiveTest {
 
    @Resource
    private LiveJob liveJob;
 
    @Resource
    private TVLiveChannelDao tvLiveChannelDao;
    @Resource
    private TVLiveProgramResourceService tvLiveProgramResourceService;
 
    @Test
    public void syncMiGu() throws Exception {
        liveJob.updateMiGu("");
    }
 
    /**
     * 更新节目单
     */
    @Test
    public void updatePrigrams() throws Exception {
        liveJob.updatePrograms(null);
    }
 
    @Test
    public void getDianShiMaoChannels() throws IOException {
        Document doc = Jsoup.connect("https://www.tvmao.com/program_satellite/AHTV1-w4.html").userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36").get();
        Elements els = doc.getElementsByClass("chlsnav").get(0).getElementsByTag("ul").get(0).getElementsByTag("a");
        for (int i = 0; i < els.size(); i++) {
            System.out.println(els.get(i).text() + "#https://www.tvmao.com" +
                    els.get(i).attr("href"));
        }
    }
 
    @Test
    public void getTVSOUChannels() throws IOException {
        Document doc = Jsoup.connect("https://www.tvsou.com/epg/yangshi/").userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36").get();
        Elements els = doc.getElementsByClass("c_list_main").get(0).getElementsByTag("a");
        for (int i = 0; i < els.size(); i++) {
            System.out.println(els.get(i).text() + "#https://www.tvsou.com/" +
                    els.get(i).attr("href"));
        }
    }
 
    @Test
    public void addProgramResource() throws FileNotFoundException {
        Scanner scanner = new Scanner(new File("C:\\Users\\Administrator\\Desktop\\新建文本文档 (2).txt"));
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            String[] sts = line.split("#");
            if (sts.length > 1) {
                String name = sts[0];
                String link = sts[1].trim();
                String id = StringUtil.Md5(name);
                TVLiveChannel channel = tvLiveChannelDao.get(id);
                if (channel != null) {
                    TVLiveProgramResource resource = new TVLiveProgramResource();
                    resource.setChannelId(channel.getId());
                    resource.setType(TVLiveProgramResource.TVLiveProgramResourceType.dianshimao);
                    resource.setUrl(link);
                    try {
                        tvLiveProgramResourceService.add(resource);
                    } catch (ParamsException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
 
        scanner.close();
    }
 
 
    /**
     * 搜视网
     * @throws FileNotFoundException
     */
    @Test
    public void addProgramResourceTVSOU() throws FileNotFoundException {
        Scanner scanner = new Scanner(new File("C:\\Users\\Administrator\\Desktop\\搜视网.txt"));
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            String[] sts = line.split("#");
            if (sts.length > 1) {
                String name = sts[0];
                String link = sts[1].trim();
                String id = StringUtil.Md5(name);
                TVLiveChannel channel = tvLiveChannelDao.get(id);
                if (channel != null) {
                    TVLiveProgramResource resource = new TVLiveProgramResource();
                    resource.setChannelId(channel.getId());
                    resource.setType(TVLiveProgramResource.TVLiveProgramResourceType.tvsou);
                    resource.setUrl(link);
                    try {
                        tvLiveProgramResourceService.add(resource);
                    } catch (ParamsException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
 
        scanner.close();
    }
 
 
}