admin
2021-02-06 e2c6372f29ae0a93d9f672ffad4613581ba3e201
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
package com.hxh.spring.test;
 
import com.newvideo.dao.juhe.funtv.FunTVAlbum2Dao;
import com.newvideo.dao.juhe.funtv.FunTVVideo2Dao;
import com.newvideo.dao.juhe.funtv.VideoFunTV2Dao;
import com.newvideo.funtv.FunTVNewApi;
import com.newvideo.funtv.Funtv2ResultVO;
import com.newvideo.funtv.entity.FunTVAlbum2;
import com.newvideo.funtv.entity.FunTVVideo2;
import com.newvideo.funtv.entity.VideoFunTV2;
import com.newvideo.service.imp.ResourceVideoService;
import com.newvideo.service.imp.VideoInfoService;
import com.newvideo.service.inter.FunTV2Service;
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.Serializable;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试
@ContextConfiguration(locations = {"classpath:spring.xml"})
@WebAppConfiguration
public class FunTV2 {
 
    @Resource
    private FunTV2Service funTV2Service;
 
    @Resource
    private FunTVAlbum2Dao funTVAlbum2Dao;
 
    @Resource
    private FunTVVideo2Dao funTVVideo2Dao;
 
    @Resource
    private VideoInfoService videoInfoService;
 
    @Resource
    private VideoFunTV2Dao videoFunTV2Dao;
 
    @Resource
    private ResourceVideoService resourceVideoService;
 
 
 
    @Test
    public void syncAlbum() {
        //1-电影 2-电视剧 3-动漫 4-综艺 5-少儿
        int channelId = 2;
        Funtv2ResultVO vo = FunTVNewApi.getAlbums(1, 20, null, null, 1);
        int totalCount = vo.getCount();
        int pageSize = 20;
        int totalPage =10; //totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        for (int p = 0; p < totalPage; p++) {
            Funtv2ResultVO result = FunTVNewApi.getAlbums(p + 1, pageSize, null, null, 1);
            if (result != null)
                for (Serializable a : result.getList()) {
                    FunTVAlbum2 album2 = (FunTVAlbum2) a;
                    funTV2Service.saveAlbum(album2);
                    if (album2.getEpisodes() != null)
                        for (FunTVVideo2 video2 : album2.getEpisodes())
                            funTV2Service.saveVideo(video2);
                }
        }
    }
 
    @Test
    public void addToVideoInfo() {
        List<FunTVAlbum2> album2List = funTVAlbum2Dao.listByChannelId(1, 0, 100);
        for (FunTVAlbum2 album2 : album2List) {
            //只加入免费的
            if (!album2.getFeeMode().equalsIgnoreCase("0")) {
                continue;
            }
            System.out.println(album2.getName());
            List<FunTVVideo2> list = funTVVideo2Dao.listByMediaId(album2.getId(), 0, 2000);
            album2.setEpisodes(list);
            try {
                funTV2Service.processAlbum(album2);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
 
    @Test
    public void getAccessToken() {
        System.out.println(FunTVNewApi.getAccessToken());
    }
 
 
    @Test
    public void offLine() {
        funTV2Service.offLineAlbum("565");
    }
 
 
 
    @Test
    public void removeAlbum() {
        for (int i = 0; i < 100; i++) {
            List<VideoFunTV2> list = videoFunTV2Dao.listAll(0, 100);
            for (VideoFunTV2 tv2 : list) {
                try {
                    funTV2Service.offLineAlbum(tv2.getMediaId());
                } catch (Exception e) {
 
                }
            }
        }
    }
 
 
    public static void main(String[] args) {
        String authCode = FunTVNewApi.getAuthCode();
        System.out.println(authCode);
    }
 
}