admin
2025-02-20 f537abe9f3646c739beaf15076246a2f71a347e9
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.hxh.spring.test.video;
 
import com.google.gson.Gson;
import com.yeshi.buwan.dao.video.AlbumVideoMapDao;
import com.yeshi.buwan.domain.VideoInfo;
import com.yeshi.buwan.domain.video.AlbumVideoMap;
import com.yeshi.buwan.domain.video.InternetSearchVideo;
import com.yeshi.buwan.service.imp.VideoInfoService;
import com.yeshi.buwan.service.inter.juhe.InternetSearchVideoService;
import com.yeshi.buwan.util.DouBanUtil;
import com.yeshi.buwan.util.FileUtil;
import com.yeshi.buwan.util.factory.VideoInfoFactory;
import org.junit.Test;
 
import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
 
/**
 * @author hxh
 * @title: DouBanTest
 * @description: TODO
 * @date 2022/3/16 14:59
 */
//@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(locations = {"classpath:spring.xml"})
//@WebAppConfiguration
public class DouBanTest {
 
    @Resource
    private AlbumVideoMapDao albumVideoMapDao;
    @Resource
    private VideoInfoService videoInfoService;
    @Resource
    private InternetSearchVideoService internetSearchVideoService;
 
 
    @Test
    public void saveSearchResult() throws Exception {
        //读取视频名称
        Scanner scanner = new Scanner(new FileInputStream(new File("F:\\影视信息\\片名.txt")));
        int sleepTime = 1;
        List<String> nameList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            String st = scanner.nextLine();
            VideoInfo videoInfo = new Gson().fromJson(st, VideoInfo.class);
            String name = videoInfo.getName();
            nameList.add(name);
        }
        scanner.close();
 
        Collections.shuffle(nameList);
        for (String name : nameList) {
            File f = new File("F:\\影视信息\\豆瓣影视搜索信息\\" + name + ".html");
            if (!f.exists()) {
                try {
                    DouBanUtil.saveSearch(name, f.getAbsolutePath());
                    if (sleepTime > 1) {
                        sleepTime--;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    sleepTime++;
                }
                Thread.sleep(sleepTime * 1000);
            }
        }
 
 
    }
 
    @Test
    public void saveVideoInfo() throws IOException {
        List<AlbumVideoMap> mapList = albumVideoMapDao.listAll(6690, 40000);
        int page = mapList.size() % 20 == 0 ? mapList.size() / 20 : mapList.size() / 20 + 1;
        for (int i = 0; i < page; i++) {
            int start = i * 20;
            int end = mapList.size() > i * 20 + 20 ? i * 20 + 20 : mapList.size();
            List<AlbumVideoMap> subList = mapList.subList(start, end);
            List<String> localIdList = new ArrayList<>();
            List<String> internetIdList = new ArrayList<>();
            for (AlbumVideoMap map : subList) {
                String videoId = map.getVideoId();
                if (org.yeshi.utils.NumberUtil.isNumeric(videoId)) {
                    localIdList.add(videoId);
                } else {
                    internetIdList.add(videoId);
                }
            }
            List<VideoInfo> videoInfoList = new ArrayList<>();
            if (localIdList.size() > 0) {
                videoInfoList.addAll(videoInfoService.listByVideoIds(localIdList));
            }
 
            if (internetIdList.size() > 0) {
                List<InternetSearchVideo> ivideoList = internetSearchVideoService.listByIds(internetIdList);
                if (ivideoList.size() > 0) {
                    for (InternetSearchVideo searchVideo : ivideoList) {
                        videoInfoList.add(VideoInfoFactory.create(searchVideo));
                    }
                }
            }
 
            for (VideoInfo videoInfo : videoInfoList) {
                videoInfo.setIntroduction("");
                FileUtil.appendSave(new Gson().toJson(videoInfo) + "\n", "F:\\影视信息\\片名.txt");
            }
 
        }
    }
 
 
}