admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
src/test/java/com/hxh/spring/test/live/TVLiveTest.java
@@ -1,6 +1,15 @@
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;
@@ -8,6 +17,10 @@
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"})
@@ -17,10 +30,104 @@
    @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();
    }
}