KSController.java
4.13 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package cn.fw.freya.controller;
import cn.fw.freya.model.data.pool.LivePool;
import cn.fw.freya.model.data.pool.VideoPool;
import cn.fw.freya.model.dto.rpc.ReportAccountDto;
import cn.fw.freya.service.crawl.impl.KuaiShouCrawl;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author unknown
* @version 1.0
* @date 2021/12/10 14:56
* @Description
*/
@Validated
@RequestMapping("/kuaishou")
@RestController
@RequiredArgsConstructor
public class KSController {
private final KuaiShouCrawl kuaishouCrawl;
/**
* 获取所有'作品'信息, 并存库
*
* @param accountNo 账户号
*/
@GetMapping("/getVideoInfo")
public List<VideoPool> getVideoInfo(String accountNo, HttpServletRequest request) throws IOException {
request.getHeader("host");
return kuaishouCrawl.getAllVideoMsg(accountNo);
}
/**
* 获取所有'直播'信息, 并存库
*
* @param accountNo 账户号
*/
@GetMapping("/getLiveInfo")
public List<LivePool> getLiveInfo(String accountNo) throws IOException {
return kuaishouCrawl.getYesterdayLiveMsg(accountNo);
}
/**
* 更新用户粉丝数
*
* @param accountNo 账户号
*/
@GetMapping("/updateAccountFans")
public ReportAccountDto updateAccountFans(String accountNo) throws IOException {
return kuaishouCrawl.updateAccountMsg(accountNo);
}
/**
* 进入指定账户号的创作者平台首页
*
* @param accountNo 账户号
*/
@GetMapping("/loginIndex")
public void loginIndex(String accountNo) {
kuaishouCrawl.loginIndex(accountNo);
}
/**
* 获取指定用户指定类型的sig3签名
*
* @param accountNo 账户号
*/
@GetMapping("/getNS_sig3")
public String getNS_sig3(String accountNo, Integer type, boolean retryGet) {
return kuaishouCrawl.getNS_sig3(accountNo, type, 1, retryGet);
}
/**
* 设置setSig3Map
*/
@GetMapping("/setSig3Map")
public boolean setSig3Map() {
return kuaishouCrawl.setSig3Map();
}
/**
* 设置setSig3Map
*/
@PostMapping("/setMapFromString")
public boolean setMapFromString(@RequestBody String jsonStr) {
return kuaishouCrawl.setMapFromString(jsonStr, false);
}
/**
* 停止设置setSig3Map
*/
@GetMapping("/stopSetSig3Map")
public boolean stopSetSig3Map() {
return kuaishouCrawl.stopSetSig3Map();
}
/**
* 清空Sig3Map
*/
@GetMapping("/cleanSig3Map")
public boolean cleanSig3Map() {
return kuaishouCrawl.cleanSig3Map();
}
/**
* 获取getSig3Map
*/
@GetMapping("/getSig3Map")
public String getSig3Map() {
return kuaishouCrawl.getSig3Map();
}
/**
* 将现有的签名信息map写入到配置文件中
*/
@GetMapping("/writeMapToProperties")
public boolean writeMapToProperties() {
return kuaishouCrawl.writeMapToProperties();
}
/**
* 获取账户直播回放地址
*
* @param accountNo 账户号
*/
@GetMapping("/getPlayback")
public List<JSONObject> getPlayback(String accountNo) {
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return kuaishouCrawl.getUserLivePlayback(accountNo).stream()
.map(item -> {
JSONObject obj = (JSONObject) item;
obj.put("duration", BigDecimal.valueOf(obj.getLong("duration")).divide(BigDecimal.valueOf(60), 2, RoundingMode.HALF_UP));
Arrays.asList("createTime").forEach(item1 -> obj.put(item1, sdf.format(new Date(obj.getLong(item1)))));
return obj;
}).collect(Collectors.toList());
}
}