This commit is contained in:
userA
2023-10-13 01:53:53 +08:00
26 changed files with 468 additions and 98 deletions

2
.idea/compiler.xml generated
View File

@@ -38,7 +38,7 @@
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="ChopperBot" options="" />
<module name="ChopperBot" options="-parameters" />
<module name="chopperbot-account" options="-parameters" />
<module name="chopperbot-barrage" options="-parameters" />
<module name="chopperbot-common" options="-parameters" />

View File

@@ -71,6 +71,8 @@
![9f9a0e3127245ae70e5375c1bf90509](https://github.com/969025903/ChopperBot/assets/77137063/6d8c0f1e-a02f-4d04-a047-f03888358790)
## Heat Recommend
![431e8b1880825e528b07f9c11360577](https://github.com/969025903/ChopperBot/assets/77137063/adeab4ae-25fe-4752-a6ce-2a79a6f5703e)
## Hot Live
![T4)XK652SFQ1FH7BF53~1 J](https://github.com/969025903/ChopperBot/assets/77137063/6fe79608-6724-4768-8b39-3f4b9b2483c2)
**More pages in development....**
# 🕹 ChopperBot Module

View File

@@ -67,7 +67,8 @@
![9f9a0e3127245ae70e5375c1bf90509](https://github.com/969025903/ChopperBot/assets/77137063/6d8c0f1e-a02f-4d04-a047-f03888358790)
## 热门直播推荐
![431e8b1880825e528b07f9c11360577](https://github.com/969025903/ChopperBot/assets/77137063/adeab4ae-25fe-4752-a6ce-2a79a6f5703e)
## 多平台热门直播
![T4)XK652SFQ1FH7BF53~1 J](https://github.com/969025903/ChopperBot/assets/77137063/6fe79608-6724-4768-8b39-3f4b9b2483c2)
**更多页面正在开发中....**
# 🕹 ChopperBot模块介绍

View File

@@ -67,6 +67,17 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>

View File

@@ -1,8 +1,10 @@
package org.example.api;
import org.example.core.account.Impl.AccountOperator;
import org.example.pojo.Account;
import org.springframework.web.bind.annotation.*;
import org.example.core.pojo.Account;
import org.example.core.pojo.AccountVO;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import javax.annotation.Resource;
import java.util.List;
@@ -12,25 +14,42 @@ import java.util.List;
* @Author welsir
* @Date 2023/9/22 14:11
*/
@RestController
@RequestMapping("account")
@Component
public class AccountApi {
@Resource
private AccountOperator accountOperator;
@PostMapping("/addUser/{uid}")
public void addAccount(@PathVariable int uid){
accountOperator.insertAccount(uid);
/*
* 第一次登陆调用此方法将账号对应cookie存入数据库中
* 目前仅支持两个平台的账号保管(抖音、b站)
* 目前只支持以下方式登录
* 抖音登录默认为验证码登录
* b站登录默认为账号密码登录
*/
public void addAccountSaveCookie(int platformId, @RequestBody String username, @RequestBody String password){
accountOperator.insertAccount(platformId,username,password);
}
@GetMapping("/getUser/{platformId}")
public List<Account> getAllUsers(@PathVariable int platformId){
/*
* 根据平台id获取用户集合
*/
public List<AccountVO> getAllUsers(int platformId){
return accountOperator.getAllUsers(platformId);
}
@PostMapping("/editUser")
public void editUser(@RequestBody Account account){
public List<AccountVO> getAllUsers(){
return accountOperator.getAllUsers();
}
/*
* 修改用户属性
*/
public void editUser(Account account){
accountOperator.editUser(account);
}
public void deleteUser(int uid){
accountOperator.deleteAccount(uid);
}
}

View File

@@ -1,19 +0,0 @@
package org.example.core.account;
import org.example.pojo.Account;
import java.util.List;
/**
* @Description
* @Author welsir
* @Date 2023/9/23 14:02
*/
public interface AccountCenter {
void insertAccount(int platformId);
List<Account> getAllUsers(int id);
void editUser(Account account);
}

View File

@@ -0,0 +1,25 @@
package org.example.core.account;
import org.example.core.pojo.Account;
import org.example.core.pojo.AccountVO;
import java.util.List;
/**
* @Description
* @Author welsir
* @Date 2023/9/23 14:02
*/
public interface AccountOperateCenter {
void insertAccount(int platformId,String username,String password);
List<AccountVO> getAllUsers();
List<AccountVO> getAllUsers(int id);
void deleteAccount(int uid);
void editUser(Account account);
}

View File

@@ -1,33 +1,55 @@
package org.example.core.account.Impl;
import org.example.core.account.AccountCenter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.core.account.AccountOperateCenter;
import org.example.core.constpool.ConstPool;
import org.example.core.factory.PlatformFactory;
import org.example.mapper.AccountMapper;
import org.example.pojo.Account;
import org.springframework.stereotype.Component;
import org.example.core.factory.PlatformOperation;
import org.example.core.mapper.AccountMapper;
import org.example.core.mapper.AccountTypeMapper;
import org.example.core.pojo.Account;
import org.example.core.pojo.AccountType;
import org.example.core.pojo.AccountVO;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Description
* @Author welsir
* @Date 2023/9/23 14:04
*/
@Component
public class AccountOperator implements AccountCenter {
@Service
public class AccountOperator implements AccountOperateCenter {
@Resource
private AccountMapper accountMapper;
@Resource
AccountTypeMapper accountTypeMapper;
@Override
public void insertAccount(int platformId) {
PlatformFactory.createPlatformOperation(platformId);
public void insertAccount(int platformId,String username,String password) {
PlatformOperation platformOperation = PlatformFactory.createPlatformOperation(platformId);
platformOperation.login(platformId,username,password);
}
@Override
public List<Account> getAllUsers(int id) {
return accountMapper.selectUserByPlatform(id);
public List<AccountVO> getAllUsers() {
List<Account> accountList = accountMapper.selectList(null);
List<AccountType> accountTypes = accountTypeMapper.selectList(null);
return addTypeToAccount(accountTypes,accountList);
}
@Override
public List<AccountVO> getAllUsers(int id) {
List<Account> accountList = accountMapper.selectUserByPlatform(id);
List<AccountType> accountTypes = accountTypeMapper.selectList(null);
return addTypeToAccount(accountTypes,accountList);
}
@Override
@@ -35,4 +57,31 @@ public class AccountOperator implements AccountCenter {
int i = accountMapper.updateById(account);
Assert.isTrue(i==1,"Update user fail!Please try again or check the wrong!");
}
public List<AccountVO> addTypeToAccount(List<AccountType> accountTypes,List<Account> accountList){
Map<Long, List<AccountType>> typeMap = accountTypes.stream()
.collect(Collectors.groupingBy(AccountType::getUid));
List<AccountVO> accountVOList = new ArrayList<>();
for (Account account : accountList) {
AccountVO accountVO = new AccountVO();
List<AccountType> types = typeMap.get(account.getId());
if (types != null) {
accountVO.setTypeList(types);
accountVO.setUid(account.getId());
accountVO.setUsername(account.getUsername());
accountVO.setPassword(account.getPassword());
accountVO.setPlatform(ConstPool.AccountPlatForm.fromId(account.getPlatformId()));
accountVOList.add(accountVO);
}
}
return accountVOList;
}
@Override
public void deleteAccount(int uid){
accountMapper.deleteById(uid);
QueryWrapper<AccountType> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("uid",uid);
accountTypeMapper.delete(queryWrapper);
}
}

View File

@@ -0,0 +1,35 @@
package org.example.core.constpool;
/**
* @Description
* @Author welsir
* @Date 2023/10/12 20:47
*/
public class ConstPool {
//账号平台
public enum AccountPlatForm{
BILIBILI(1),
DOUYIN(2);
private int id;
AccountPlatForm(int id){
this.id = id;
}
public static int getPlatFormId (int id){
return id;
}
public static String fromId(int id) {
for (AccountPlatForm platform : values()) {
if (platform.id == id) {
return platform.toString();
}
}
throw new IllegalArgumentException("Invalid id: " + id);
}
}
}

View File

@@ -1,7 +1,9 @@
package org.example.core.factory;
import org.example.core.platform.Bilibili;
import org.example.pojo.PlatformType;
import org.example.core.platform.Douyin;
import org.example.core.pojo.PlatformType;
/**
* @Description
@@ -10,14 +12,13 @@ import org.example.pojo.PlatformType;
*/
public class PlatformFactory {
public static void createPlatformOperation(int platformId) {
public static PlatformOperation createPlatformOperation(int platformId) {
switch (PlatformType.getPlatform(platformId)){
case BILIBILI:
new Bilibili();
return;
return new Bilibili();
case DOUYU:
case DOUYIN:
return;
return new Douyin();
default:
throw new RuntimeException();
}

View File

@@ -8,6 +8,6 @@ package org.example.core.factory;
public interface PlatformOperation {
void operation(int id);
void login(int id,String account,String password);
}

View File

@@ -1,9 +1,10 @@
package org.example.mapper;
package org.example.core.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.example.pojo.Account;
import org.example.pojo.AccountType;
import org.example.core.pojo.Account;
import org.example.core.pojo.AccountType;
import org.springframework.stereotype.Component;
import java.util.List;
@@ -12,6 +13,7 @@ import java.util.List;
* @Author welsir
* @Date 2023/9/23 14:15
*/
@Component
public interface AccountMapper extends BaseMapper<Account> {
@Select("select * from account a join platform pf on a.platformId=pf.id where pf.id = #{id}")
@@ -20,4 +22,5 @@ public interface AccountMapper extends BaseMapper<Account> {
@Select("select * from account_type where uid=#{id}")
List<AccountType> selectTypeByUid(Long id);
}

View File

@@ -1,7 +1,8 @@
package org.example.mapper;
package org.example.core.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.example.pojo.AccountType;
import org.example.core.pojo.AccountType;
/**
* @Description

View File

@@ -1,16 +1,24 @@
package org.example.core.platform;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.example.core.factory.PlatformOperation;
import org.example.mapper.AccountMapper;
import org.example.pojo.Account;
import org.example.core.mapper.AccountMapper;
import org.example.core.pojo.Account;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import javax.annotation.Resource;
import java.util.Scanner;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
/**
* @Description
@@ -18,36 +26,45 @@ import java.util.concurrent.TimeUnit;
* @Date 2023/9/24 21:18
*/
public class Bilibili implements PlatformOperation {
//cookie本地读取路径
private static final String FILE_PATH = "D:\\Douyincookies.txt";
private static final String URL = "https://www.bilibili.com/";
@Resource
private AccountMapper accountMapper;
Set<Cookie> cookies;
@Override
public void operation(int id) {
public void login(int id,String username,String password) {
try {
//设置driver驱动<-记得更改为自己的本地路径!!->
System.setProperty("webdriver.chrome.driver", "D:\\downLoad\\chromedriver_win32\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
//同理
options.setBinary("C:\\Program Files (x86)\\Chromebrowser\\Chrome.exe");
ChromeDriver webDriver = new ChromeDriver(options);
//b站网址
String url = "https://www.bilibili.com/";
webDriver.get(url);
//与浏览器同步非常重要,必须等待浏览器加载完毕
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//中间完成登录操作
Scanner scanner = new Scanner(System.in);
scanner.next();
//获取cookie
cookies = webDriver.manage().getCookies();
Account account = new Account();
account.setCookie(cookies);
account.setPlatformId(id);
accountMapper.insert(account);
} catch (Exception e) {
ChromeDriver loginwebDriver = new ChromeDriver(options);
loginwebDriver.get(URL); //
loginwebDriver.manage().deleteAllCookies();
Thread.sleep(30000L);
Set<Cookie> cookies = loginwebDriver.manage().getCookies();
loginwebDriver.quit();
ChromeDriver confirmLogin = new ChromeDriver(options);
confirmLogin.get(URL);
confirmLogin.manage().deleteAllCookies();
for (Cookie cookie : cookies) {
loginwebDriver.manage().addCookie(cookie);
}
confirmLogin.navigate().refresh();
Thread.sleep(3000L);
WebElement avator = confirmLogin.findElement(By.xpath("/html/body/div[2]/div[2]/div[1]/div[1]/ul[2]/li[1]"));
if(avator!=null){
Account user = new Account();
user.setCookies(cookies.toString());
user.setPlatformId(1);
user.setUsername(username);
user.setPassword(password);
accountMapper.insert(user);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -0,0 +1,89 @@
package org.example.core.platform;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONReader;
import org.example.core.factory.PlatformOperation;
import org.example.core.mapper.AccountMapper;
import org.example.core.pojo.Account;
import org.openqa.selenium.Cookie;
import javax.annotation.Resource;
import java.io.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
/**
* @Description
* @Author welsir
* @Date 2023/10/9 17:09
*/
public class Douyin implements PlatformOperation {
final String FILE_PATH = "D:\\Douyincookies.txt";
@Resource
AccountMapper accountMapper;
@Override
public void login(int id,String username,String password) {
try {
List<String> command = new ArrayList<>();
command.add("python"); // Python 解释器
command.add("D:\\code\\gitHubProject\\Text_select_captcha\\DouyinLogin.py"); // 要运行的 Python 脚本文件名
ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = processBuilder.start();
List<String> command1 = new ArrayList<>();
command1.add("python"); // Python 解释器
command1.add("D:\\code\\gitHubProject\\Text_select_captcha\\Douyin.py");
ProcessBuilder processBuilder1 = new ProcessBuilder(command1);
Process process1 = processBuilder1.start();
// 获取Python脚本的标准输出流
InputStream inputStream1 = process1.getInputStream();
BufferedReader reader1 = new BufferedReader(new InputStreamReader(inputStream1));
String line1;
StringBuilder callBack = new StringBuilder();
// 读取Python脚本的输出
while ((line1 = reader1.readLine()) != null) {
callBack.append(line1).append("\n");
}
System.out.println("验证flag:" + callBack);
// 等待Python脚本执行完成
int exitCode = process1.waitFor();
if (exitCode == 0) {
System.out.println("抖音登录成功!");
Account account = new Account();
account.setUsername(username);
account.setCookies(loadCookiesFromFile(FILE_PATH).toString());
account.setPlatformId(2);
accountMapper.insert(account);
}
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
public HashSet<Cookie> loadCookiesFromFile (String filePath) throws IOException {
HashSet<Cookie> cookies = new HashSet<>();
try (FileReader fileReader = new FileReader(filePath)) {
JSONReader reader = new JSONReader(fileReader);
JSONArray jsonArray = reader.readObject(JSONArray.class);
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String name = jsonObject.getString("name");
String value = jsonObject.getString("value");
String domain = jsonObject.getString("domain");
String path = jsonObject.getString("path");
String sameSite = jsonObject.getString("sameSite");
Date expiry = jsonObject.getDate("expiry");
boolean secure = jsonObject.getBoolean("secure");
boolean httpOnly = jsonObject.getBoolean("httpOnly");
Cookie cookie = new Cookie(name, value, domain, path, expiry, secure, httpOnly, sameSite);
cookies.add(cookie);
}
}
return cookies;
}
}

View File

@@ -1,4 +1,4 @@
package org.example.pojo;
package org.example.core.pojo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
@@ -6,9 +6,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.openqa.selenium.Cookie;
import java.util.Set;
import java.io.Serializable;
/**
* @Description
@@ -19,11 +18,13 @@ import java.util.Set;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Account {
public class Account implements Serializable {
@TableId(value = "id", type = IdType.ASSIGN_ID)
private Long uid;
private Set<Cookie> cookie;
@TableId(value = "uid", type = IdType.ASSIGN_UUID)
private Long id;
private String username;
private String password;
private String cookies;
private boolean isCompleteMatch;
private int platformId;

View File

@@ -1,12 +1,10 @@
package org.example.pojo;
package org.example.core.pojo;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @Description
* @Author welsir

View File

@@ -0,0 +1,24 @@
package org.example.core.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.pojo.AccountType;
import java.util.List;
/**
* @Description
* @Author welsir
* @Date 2023/10/12 21:03
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AccountVO {
private Long uid;
private String username;
private String password;
private String platform;
List<AccountType> typeList;
}

View File

@@ -1,4 +1,4 @@
package org.example.pojo;
package org.example.core.pojo;
/**
* @Description

View File

@@ -1,4 +1,6 @@
package org.example.pojo;
package org.example.core.pojo;
import org.example.pojo.VideoType;
import java.util.List;

View File

@@ -1,12 +1,9 @@
package org.example.pojo;
package org.example.core.pojo;
import lombok.Data;
import org.openqa.selenium.Cookie;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @Description
@@ -18,9 +15,9 @@ public class VideoQueue {
private String name;
private List<Object> messages;
private boolean isStrongMatch;
private Set<Cookie> cookies;
private String cookies;
public VideoQueue(String name, boolean isStrongMatch,Set<Cookie> cookies) {
public VideoQueue(String name, boolean isStrongMatch,String cookies) {
this.name = name;
this.messages = new ArrayList<>();
this.isStrongMatch = isStrongMatch;

View File

@@ -1,4 +1,4 @@
package org.example.pojo;
package org.example.core.pojo;
/**
* @Description

View File

@@ -0,0 +1,47 @@
package org.example.controller;
import org.example.core.pojo.Account;
import org.example.core.pojo.AccountVO;
import org.example.service.AccountService;
import org.example.util.Result;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @Description
* @Author welsir
* @Date 2023/10/12 22:26
*/
@RestController
@RequestMapping("/account")
public class AccountController {
@Resource
AccountService accountService;
@GetMapping(value = "/getUser/{platformId}")
public Result getAllUser(@PathVariable int platformId){
List<AccountVO> list = accountService.getAllUser(platformId);
return Result.success(list);
}
@GetMapping(value = "/getUser")
public Result getAllUser(){
return Result.success(accountService.getAllUser());
}
@PostMapping(value = "/login/{platformId}")
public Result login(@RequestBody String username, @RequestBody String password, @PathVariable int platformId){
accountService.login(platformId,username,password);
return Result.success();
}
@PostMapping(value = "/edit")
public Result edit(@RequestBody Account account){
accountService.edit(account);
return Result.success();
}
}

View File

@@ -0,0 +1,25 @@
package org.example.service;
import org.example.core.pojo.Account;
import org.example.core.pojo.AccountVO;
import java.util.List;
/**
* @Description
* @Author welsir
* @Date 2023/10/12 22:26
*/
public interface AccountService {
List<AccountVO> getAllUser(int id);
List<AccountVO> getAllUser();
void login(int platformId,String username,String password);
void edit(Account account);
}

View File

@@ -0,0 +1,42 @@
package org.example.service.impl;
import org.example.api.AccountApi;
import org.example.core.pojo.Account;
import org.example.core.pojo.AccountVO;
import org.example.service.AccountService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @Description
* @Author welsir
* @Date 2023/10/12 22:39
*/
@Service
public class AccountServiceImpl implements AccountService {
@Resource
AccountApi accountApi;
@Override
public List<AccountVO> getAllUser(int id) {
return accountApi.getAllUsers(id);
}
@Override
public List<AccountVO> getAllUser() {
return accountApi.getAllUsers();
}
@Override
public void login(int platformId,String username, String password) {
accountApi.addAccountSaveCookie(platformId,username,password);
}
@Override
public void edit(Account account) {
accountApi.editUser(account);
}
}

Binary file not shown.