admin
2020-10-15 1eac0e8d2e70dd5a6271793616748209c7dfa916
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
package com.hxh.spring.test;
 
import com.yeshi.buwan.dao.juhe.funtv.FunTVAlbum2Dao;
import com.yeshi.buwan.dao.juhe.funtv.FunTVVideo2Dao;
import com.yeshi.buwan.funtv.FunTVNewApi;
import com.yeshi.buwan.funtv.entity.FunTVAlbum2;
import com.yeshi.buwan.funtv.entity.FunTVShortVideo2;
import com.yeshi.buwan.funtv.entity.FunTVVideo2;
import com.yeshi.buwan.job.video.FunTV2VideoUpdate;
import com.yeshi.buwan.service.inter.juhe.FunTV2Service;
import com.yeshi.buwan.vo.video.funtv.Funtv2ResultVO;
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.ArrayList;
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 FunTV2VideoUpdate funTV2VideoUpdate;
 
    @Test
    public void test1() {
        long now = System.currentTimeMillis();
        for (int d = 200; d >= 100; d--) {
            Funtv2ResultVO result = FunTVNewApi.getVideos(1, 20, now - 1000 * 60 * 60L * 24 * d, now - 1000 * 60 * 60L * 24 * (d - 1), 1013, 1);
            if (result != null && result.getList() != null && result.getList().size() > 0)
                System.out.println(result);
        }
    }
 
    @Test
    public void syncAlbum() {
        Funtv2ResultVO vo = FunTVNewApi.getAlbums(1, 20, null, null, 5, 1);
        int totalCount = vo.getCount();
        int pageSize = 20;
        int totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
        for (int p = 0; p < totalPage; p++) {
            Funtv2ResultVO result = FunTVNewApi.getAlbums(p + 1, pageSize, null, null, 5, 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 syncShortVideo() {
        long now = System.currentTimeMillis();
        for (int d = 30; d >= 0; d--) {
            List<FunTVShortVideo2> shortVideo2List = new ArrayList<>();
            int pageSize = 100;
            Funtv2ResultVO result = FunTVNewApi.getVideos(1, pageSize, now - 1000 * 60 * 60L * 24 * d, now - 1000 * 60 * 60L * 24 * (d - 1), null, 1);
            if (result != null) {
                for (Serializable a : result.getList()) {
                    FunTVShortVideo2 video2 = (FunTVShortVideo2) a;
                    shortVideo2List.add(video2);
                }
            }
            int count = result.getCount();
            int totalPage = count % pageSize == 0 ? count / pageSize : count / pageSize + 1;
            if (totalPage > 1)
                for (int p = 1; p < totalPage; p++) {
                    result = FunTVNewApi.getVideos(p + 1, pageSize, now - 1000 * 60 * 60L * 24 * d, now - 1000 * 60 * 60L * 24 * (d - 1), null, 1);
                    if (result != null) {
                        for (Serializable a : result.getList()) {
                            FunTVShortVideo2 video2 = (FunTVShortVideo2) a;
                            shortVideo2List.add(video2);
                        }
                    }
                }
            for (FunTVShortVideo2 video2 : shortVideo2List) {
                funTV2Service.saveShortVideo(video2);
            }
        }
    }
 
    @Test
    public void getAlbumDetail() {
        FunTVAlbum2 album2 = FunTVNewApi.getAlbumsDetail("99989");
        System.out.println(album2);
    }
 
 
    @Test
    public void addToVideoInfo() {
        List<FunTVAlbum2> album2List = funTVAlbum2Dao.listByChannelId(1, 300, 500);
        for (FunTVAlbum2 album2 : album2List) {
            List<FunTVVideo2> list = funTVVideo2Dao.listByMediaId(album2.getId());
            album2.setEpisodes(list);
            funTV2Service.addToVideoInfo(album2);
        }
    }
 
 
    @Test
    public void getAccessToken(){
        System.out.println(FunTVNewApi.getAccessToken());
    }
 
}