Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

账号模块完善账号通道搭建,缺少自动发布流程 #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.example.pojo.Channel;
import org.example.pojo.vo.AccountVO;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
Expand All @@ -15,7 +18,8 @@
* @Author welsir
* @Date 2023/9/22 14:11
*/
@Component
@RestController
@RequestMapping("/account")
public class AccountApi {

@Resource
Expand All @@ -30,6 +34,7 @@ public class AccountApi {
* 抖音登录默认为验证码登录
* b站登录默认为账号密码登录
*/
@PostMapping("/login")
public void addAccountSaveCookie(int platformId, String username){
accountOperator.insertAccount(platformId,username);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void insertAccount(int platformId,String username) {
}
String realCookies = list.toString();
Account account = new Account();
account.setPlatform_id(platformId);
account.setPlatformId(platformId);
account.setCookies(realCookies);
account.setUsername(username);
System.out.println(account);
Expand Down Expand Up @@ -91,7 +91,7 @@ public List<AccountVO> addTypeToAccount(List<AccountType> accountTypes,List<Acco
accountVO.setTypeList(types);
accountVO.setUid(account.getId());
accountVO.setUsername(account.getUsername());
accountVO.setPlatform(ConstPool.AccountPlatForm.fromId(account.getPlatform_id()));
accountVO.setPlatform(ConstPool.AccountPlatForm.fromId(account.getPlatformId()));
accountVOList.add(accountVO);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.example.core.channel;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.extern.slf4j.Slf4j;
import org.example.mapper.AccountChannelMapper;
import org.example.mapper.AccountMapper;
import org.example.mapper.ChannelMapper;
import org.example.plugin.SpringBootPlugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class Exchange {

//切片推送
public void work(){
log.info("执行视频发布推送工作..........");
Map<String, List<Account>> channelAccount = channel.getChannelAccount();
channels.forEach((k,v)->{
if(channels.get(k)==null||channelAccount.get(k)==null){
Expand All @@ -64,7 +63,7 @@ public void work(){
video.setCoverPath(packageSection.getCoverPath());
video.setDescription(packageSection.getDescription());
video.setLabels(packageSection.getLabels());
video.setPlatform(packageSection.getPlatform());
video.setPlatform(String.valueOf(account.getPlatformId()));
pushVideo.publishVideo(video);
}
}
Expand Down Expand Up @@ -92,5 +91,4 @@ private String getDevicePath(String filePath){
String directory = (directoryPath != null) ? directoryPath.toString() : "No Directory";
return directory+"\\"+fileName+"\\";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,10 @@ public void run() {
video.setFinish(true);
videoStorehouse.decrementCount();
}
//如何保证数据一定会被消费且不会重复消费
exchange.work();
saveToLocal();
}
//如何保证数据一定会被消费且不会重复消费

exchange.work();
saveToLocal();
}
};
timer.scheduleAtFixedRate(task,0,2000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.extern.slf4j.Slf4j;
import org.example.bean.section.PackageSection;
import org.example.bean.section.VideoSection;
import org.example.core.factory.videoPushFactory.StrategyFactory;
import org.example.plugin.SpringGuardPlugin;
import org.example.pojo.PacketSectionVideo;
Expand Down Expand Up @@ -46,14 +47,15 @@ public void start() {
if(p==null){
return;
}
System.out.println(p);
//数据库持久化保存
PacketSectionVideo packedVideo = factory.wrapperSectionVideo(p);
videosCollection.put(packedVideo.getId(),packedVideo);
count.incrementAndGet();
}

public void sendVideo(PackageSection p) {
queue.add(p);
public void sendVideo(VideoSection p) {
queue.add((PackageSection) p);
}

public boolean pushNotify(){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.example.init;

import org.example.constpool.ModuleName;
import org.example.constpool.PluginName;
import org.example.core.exchange.PostWorkerManager;
import org.example.core.guard.VideoPushChannelGuard;
import org.example.plugin.annotation.Plugin;
import org.springframework.stereotype.Component;

/**
* @Description
* @Author welsir
* @Date 2024/5/31 17:15
*/
@Plugin(moduleName = ModuleName.ACCOUNT,
pluginName = PluginName.POST_WORKER,
pluginName_CN = "快递员插件",
pluginDescription = "用于将切片仓库中包装好的切片推送至用户管道",
pluginClass= PostWorkerManager.class,
springBootPlugin = true,
ignore = true
)
@Component
public class PostWorkerPluginInitMachine extends SpringPlugInitMachine{
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Account implements Serializable {
private Long id;
private String username;
private String cookies;
private boolean is_complete_match;
private int platform_id;
private Boolean isCompleteMatch;
private Integer platformId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class PluginName {

public static final String CHANNEL = "channel";

public static final String POST_WORKER = "postWorker";


public static final String LIVE_CONFIG_PLUGIN= "LiveConfig";
public static final String LIVE_MANAGER_PLUGIN= "LiveDownLoadManager";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.Map;

/**
Expand All @@ -16,6 +17,8 @@
@Component
public class VideoPublishApi {

@Resource
platformSelectionFactory platformSelectionFactory;
public void publishVideo(VideoToPublish video){
PlatformVideoPublisher publisher = platformSelectionFactory.creatPlatformPublisher(video.getPlatform());
publisher.publishVideo(video);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
import org.example.core.publisher.PlatformVideoPublisher;
import org.example.core.publisher.impl.BilibiliVideoPublisher;
import org.example.core.publisher.impl.DouyinVideoPublisher;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

/**
* @Description
* @Author welsir
* @Date 2023/10/13 21:09
*/
@Component
public class platformSelectionFactory {
public static PlatformVideoPublisher creatPlatformPublisher(String platform) {
if("BILIBILI".equals(platform)){
public PlatformVideoPublisher creatPlatformPublisher(String platform) {
if("1".equals(platform)){
return new BilibiliVideoPublisher();
}else if(platform.equals("DOUYIN")){
}else if(("2").equals(platform)){
return new DouyinVideoPublisher();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.example.utils.HttpClientUtil;
import org.example.utils.VideoDeviceUtil;
import org.openqa.selenium.Cookie;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -35,6 +36,7 @@
* @author dhx
* @date 2023/9/18 20:49
*/
@Component
public class BilibiliVideoPublisher implements PlatformVideoPublisher {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.sql.Time;
import java.util.*;
import java.util.concurrent.TimeUnit;

Expand All @@ -21,6 +23,7 @@
* @Author welsir
* @Date 2023/10/13 20:11
*/
@Component
public class DouyinVideoPublisher implements PlatformVideoPublisher {

final String DOUYIN_PUBLISH_VIDEO = "org/example/core/script/douyin/DouyinVideoPublish.py";
Expand All @@ -34,8 +37,6 @@ public void publishVideo(VideoToPublish video) {
ChromeDriver webDriver = new ChromeDriver(options);
String url = "https://www.douyin.com/";
webDriver.get(url);
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
webDriver.manage().deleteAllCookies();
String cookies = video.getCookies().substring(1, video.getCookies().length() - 1);
String[] split = cookies.split(", ");
Set<Cookie> cookies1 = new HashSet<>();
Expand All @@ -49,8 +50,9 @@ public void publishVideo(VideoToPublish video) {
Cookie cookie = new Cookie(map.get("name"), map.get("value"), map.get("path"), null);
cookies1.add(cookie);
}
webDriver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
webDriver.manage().deleteAllCookies();
Thread.sleep(5000L);
for (Cookie cookie : cookies1) {
webDriver.manage().addCookie(cookie);
}
Expand Down
4 changes: 4 additions & 0 deletions chopperbot-section/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>chopperbot-account</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.example.constpool.ConstPool;
import org.example.constpool.FileNameBuilder;
import org.example.constpool.GlobalFileCache;
import org.example.core.guard.VideoPushChannelGuard;
import org.example.plugin.SpringGuardPlugin;
import org.example.sql.annotation.SQLInit;
import org.example.util.ExceptionUtil;
Expand Down Expand Up @@ -34,6 +35,8 @@ public class VideoSectionWorkShop extends SpringGuardPlugin {

@Resource
SectionParking sectionParking;
@Resource
VideoPushChannelGuard videoGuard;

@Override
public boolean init() {
Expand All @@ -50,6 +53,7 @@ public void start() {
return;
VideoSection videoSection = generateSection(request);
sectionParking.parking(videoSection);
videoGuard.sendVideo(videoSection);
}catch (InterruptedException e){
return;
}catch (Exception e){
Expand Down
Binary file modified database.db
Binary file not shown.